diff --git a/src/options/fragments/developer.tsx b/src/options/fragments/developer.tsx index 3360bf7f..ee2f5640 100644 --- a/src/options/fragments/developer.tsx +++ b/src/options/fragments/developer.tsx @@ -4,7 +4,7 @@ import { toast } from 'sonner/dist'; import type { ExposeHandler, StateProxy } from "~hooks/binding"; import type { Leaves } from "~types/common"; import { sendMessager } from '~utils/messaging'; -import { setSettingStorage } from '~utils/storage'; +import { removeSettingStorage, setSettingStorage } from '~utils/storage'; export type SettingSchema = { elements: { @@ -233,22 +233,41 @@ function DeveloperSettings({ state, useHandler }: StateProxy): JS success: '已成功获取最新版本,请重新加载网页。', error: (err) => '获取最新版本失败: ' + err.message }) - await fetching + } + + const resetDefault = async () => { + if (!window.confirm('这将覆盖开发者相关至插件默认设定。')) return + const removing = removeSettingStorage('settings.developer') + toast.promise(removing, { + loading: '正在重置开发者相关设定...', + success: '已成功重置至默认设定,请重新加载网页。', + error: (err) => '重置设定失败: ' + err.message + }) } return (
- 获取最新版本 - } +
+ + +
+ } > 若你本身并不熟悉网页开发,请尽量别碰这里的设定
diff --git a/src/utils/storage.ts b/src/utils/storage.ts index 323a67f5..b11df0ab 100644 --- a/src/utils/storage.ts +++ b/src/utils/storage.ts @@ -47,6 +47,16 @@ export async function getFullSettingStroage(): Promise { return Object.assign({}, ...settings) } +/** + * Removes a setting from the storage. + * + * @param key - The key of the setting to be removed. It should be one of the keys of `SettingFragments`. + * @returns A promise that resolves when the setting is removed. + */ +export async function removeSettingStorage(key: keyof SettingFragments): Promise { + return storage.remove(key) +} + /** * Executes a callback function while setting a processing flag in the session storage. * @param callback - The callback function to be executed. diff --git a/tests/pages/options.spec.ts b/tests/pages/options.spec.ts index 5dea01c2..13c1b136 100644 --- a/tests/pages/options.spec.ts +++ b/tests/pages/options.spec.ts @@ -248,15 +248,12 @@ test('測試從遠端獲取開發者設定', async ({ page }) => { await page.getByText('开发者相关').click() const inputUpperButtonArea = page.getByTestId('elements.upperButtonArea') - await expect(inputUpperButtonArea).toHaveValue('.lower-row .left-ctnr') await inputUpperButtonArea.fill('inputUpperButtonArea changed') const liveTitle = page.getByTestId('elements.liveTitle') - await expect(liveTitle).toHaveValue('.live-skin-main-text.small-title') await liveTitle.fill('liveTitle changed') const liveFullScreenClass = page.getByTestId('classes.screenFull') - await expect(liveFullScreenClass).toHaveValue('fullscreen-fix') await liveFullScreenClass.fill('liveFullScreenClass changed') await page.getByText('保存设定').click() @@ -289,6 +286,47 @@ test('測試從遠端獲取開發者設定', async ({ page }) => { expect(storageStr).toBe(JSON.stringify(remote)) }) +test('測試恢復開發者設定至默認值', async ({ page }) => { + + logger.info('正在修改开发者相关....') + + await page.getByText('开发者相关').click() + + const inputUpperButtonArea = page.getByTestId('elements.upperButtonArea') + await expect(inputUpperButtonArea).toHaveValue('.lower-row .left-ctnr') + await inputUpperButtonArea.fill('inputUpperButtonArea changed') + + const liveTitle = page.getByTestId('elements.liveTitle') + await expect(liveTitle).toHaveValue('.live-skin-main-text.small-title') + await liveTitle.fill('liveTitle changed') + + const liveFullScreenClass = page.getByTestId('classes.screenFull') + await expect(liveFullScreenClass).toHaveValue('fullscreen-fix') + await liveFullScreenClass.fill('liveFullScreenClass changed') + + await page.getByText('保存设定').click() + await page.reload({ waitUntil: 'domcontentloaded' }) + + logger.info('正在验证开发者相关....') + await page.getByText('开发者相关').click() + await expect(inputUpperButtonArea).toHaveValue('inputUpperButtonArea changed') + await expect(liveTitle).toHaveValue('liveTitle changed') + await expect(liveFullScreenClass).toHaveValue('liveFullScreenClass changed') + + logger.info('正在恢复开发者相关至默认值....') + page.once('dialog', dialog => dialog.accept()) + await page.getByText('重置设定').click() + + await page.getByText('已成功重置至默认设定').waitFor({ state: 'visible' }) + await page.reload({ waitUntil: 'domcontentloaded' }) + + logger.info('正在验证开发者相关有否被重置....') + await page.getByText('开发者相关').click() + await expect(inputUpperButtonArea).not.toHaveValue('inputUpperButtonArea changed') + await expect(liveTitle).not.toHaveValue('liveTitle changed') + await expect(liveFullScreenClass).not.toHaveValue('liveFullScreenClass changed') +}) + test('測試設定數據從MV2遷移', async ({ serviceWorker, page }) => { logger.info('正在測試寫入 MV2 設定....')