Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions e2e/media-theme-switch.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import { test, expect, type Page } from "@playwright/test";

/**
* 音视频固定暗色开关(media-player-theme-switch / #1973 / 票 1.2)。
*
* 断言用户可观察面:播放器计算背景色随开关在暗/浅之间切换,配置经重启保持。
* 覆盖:默认勾选、取消后立即变浅、重新勾选恢复暗色、深色应用主题下两档一致、
* 刷新后开关状态与表面档位保持。
*/

const DARK_PLAYER_BG = "rgb(19, 19, 22)";
const LIGHT_PLAYER_BG = "rgb(247, 247, 246)";

const EVIDENCE_DIR = process.env.EVIDENCE_DIR;
async function shot(page: Page, name: string): Promise<void> {
if (EVIDENCE_DIR) {
const path = await import("node:path");
await page.screenshot({ path: path.join(EVIDENCE_DIR, `${name}.png`) });
}
}

async function boot(page: Page): Promise<void> {
await page.addInitScript({ path: "./e2e/mocks/tauri-mock.js" });
await page.addInitScript(() => {
const w = window as unknown as Record<string, unknown>;
w.__biaoyue_media__ = [
{
path: "/tmp/movies/ep1.mp4",
name: "ep1.mp4",
kind: "video",
target: "ep1",
},
];
});
await page.goto("/", { waitUntil: "networkidle" });
await page.waitForSelector('[data-testid="pane-header"]', { timeout: 15000 });
}

async function openVideo(page: Page): Promise<void> {
await page.evaluate(() => {
const win = window as unknown as Record<string, any>;
win.__biaoyue_openFile__("/tmp/movies/ep1.mp4", "", "ep1.mp4");
});
await page.locator(".art-video-player").first().waitFor({ timeout: 10000 });
}

async function playerBg(page: Page): Promise<string> {
return page.evaluate(() => {
const el = document.querySelector(".art-video-player");
return el ? getComputedStyle(el).backgroundColor : "";
});
}

async function openSettings(page: Page): Promise<void> {
await page.keyboard.press("Meta+,");
await expect(page.getByTestId("media-theme-dark")).toBeVisible({
timeout: 5000,
});
}

async function closeSettings(page: Page): Promise<void> {
await page.keyboard.press("Escape");
await expect(page.getByTestId("media-theme-dark")).toHaveCount(0, {
timeout: 5000,
});
}

test("默认勾选;取消后播放器立即变浅,重新勾选恢复暗色", async ({ page }) => {
await boot(page);
await openVideo(page);
await expect.poll(() => playerBg(page)).toBe(DARK_PLAYER_BG);

await openSettings(page);
const toggle = page.getByTestId("media-theme-dark");
await expect(toggle).toBeChecked();
await shot(page, "settings-switch-default");

// 设置是覆盖层,工作区常驻 → 取消勾选即热应用
await toggle.uncheck();
await expect.poll(() => playerBg(page)).toBe(LIGHT_PLAYER_BG);
await closeSettings(page);
await expect.poll(() => playerBg(page)).toBe(LIGHT_PLAYER_BG);
await shot(page, "switch-off-player-light");

await openSettings(page);
await expect(page.getByTestId("media-theme-dark")).not.toBeChecked();
await page.getByTestId("media-theme-dark").check();
await expect.poll(() => playerBg(page)).toBe(DARK_PLAYER_BG);
await closeSettings(page);
await expect.poll(() => playerBg(page)).toBe(DARK_PLAYER_BG);
await shot(page, "switch-on-player-dark");
});

test("深色应用主题下:固定暗色与跟随档的表面一致", async ({ page }) => {
await boot(page);
await openVideo(page);
await expect.poll(() => playerBg(page)).toBe(DARK_PLAYER_BG);

await openSettings(page);
await page.getByTestId("theme-option-dark").click();
await page.getByTestId("media-theme-dark").uncheck();
await closeSettings(page);
await expect.poll(() => playerBg(page)).toBe(DARK_PLAYER_BG);
});

test("刷新后开关状态与播放器表面档位保持", async ({ page }) => {
await boot(page);
await openVideo(page);
await openSettings(page);
await page.getByTestId("media-theme-dark").uncheck();
await closeSettings(page);
await expect.poll(() => playerBg(page)).toBe(LIGHT_PLAYER_BG);

await page.reload({ waitUntil: "networkidle" });
await page.waitForSelector('[data-testid="pane-header"]', { timeout: 15000 });
await openVideo(page);
await expect.poll(() => playerBg(page)).toBe(LIGHT_PLAYER_BG);
await shot(page, "restart-persisted-light");

await openSettings(page);
await expect(page.getByTestId("media-theme-dark")).not.toBeChecked();
});
2 changes: 1 addition & 1 deletion openspec/changes/media-player-theme-switch/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

- [x] 1.1 配置项 `mediaTheme` + 播放器默认暗色作用域(容器与 `body` 浮层同源),并改写既有的播放器主题默认态用例
- **数据面**: 规格,存储,校验,桥接,消费,回滚(六栏见 design.md「## 数据面」)
- [ ] 1.2 设置 → 外观 新增「音视频固定暗色背景」开关,接跟随档热应用与持久化,补开关与重启保持用例(Blocked by 1.1)
- [x] 1.2 设置 → 外观 新增「音视频固定暗色背景」开关,接跟随档热应用与持久化,补开关与重启保持用例(Blocked by 1.1)
- **数据面**: 消费
25 changes: 25 additions & 0 deletions src/components/SettingsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,9 @@ export default function SettingsView({ onClose }: SettingsViewProps) {
const shortcuts = useShortcuts();

const theme = useEditorStore((s) => s.config.theme ?? "system");
const mediaThemeDark = useEditorStore(
(s) => (s.config.mediaTheme ?? "dark") !== "follow",
);
const readerFontSize = useEditorStore((s) => s.config.readerFontSize ?? 17);
const readerWidth = useEditorStore((s) => s.config.readerWidth ?? 1080);
const selectionToolbar = useEditorStore(
Expand Down Expand Up @@ -966,6 +969,11 @@ export default function SettingsView({ onClose }: SettingsViewProps) {
}
};

const toggleMediaTheme = (next: boolean) => {
setConfig({ mediaTheme: next ? "dark" : "follow" });
void saveAppConfig();
};

const chooseFontSize = (size: number) => {
setConfig({ readerFontSize: size });
setFontSize(size);
Expand Down Expand Up @@ -1587,6 +1595,23 @@ export default function SettingsView({ onClose }: SettingsViewProps) {
</span>
</span>
</label>
<label className="mt-2 flex cursor-pointer items-start gap-2">
<input
type="checkbox"
data-testid="media-theme-dark"
checked={mediaThemeDark}
onChange={(e) => toggleMediaTheme(e.target.checked)}
className="mt-0.5"
/>
<span>
<span className="block text-sm text-[var(--app-text)]">
音视频固定暗色背景
</span>
<span className="block text-xs text-[var(--app-text-3)]">
默认开启:播放器始终使用暗色表面;关闭后跟随应用主题
</span>
</span>
</label>
</section>

<section>
Expand Down
Loading