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
132 changes: 132 additions & 0 deletions e2e/music.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import { test, expect } from "@playwright/test";
function wave() {
const buffer = Buffer.alloc(44 + 160000);
buffer.write("RIFF", 0);
buffer.writeUInt32LE(buffer.length - 8, 4);
buffer.write("WAVEfmt ", 8);
buffer.writeUInt32LE(16, 16);
buffer.writeUInt16LE(1, 20);
buffer.writeUInt16LE(1, 22);
buffer.writeUInt32LE(8000, 24);
buffer.writeUInt32LE(16000, 28);
buffer.writeUInt16LE(2, 32);
buffer.writeUInt16LE(16, 34);
buffer.write("data", 36);
buffer.writeUInt32LE(160000, 40);
return buffer;
}
test("Music imports audio, plays it and persists playlists", async ({
page,
}) => {
await page.goto("/");
await expect(page.locator(".boot")).toHaveCount(0);
async function launch() {
await page.getByRole("button", { name: "Apps", exact: true }).click();
await page
.locator(".startmenu")
.getByRole("button", { name: "Music", exact: true })
.click();
}
await launch();
await page.getByLabel("Import audio", { exact: true }).setInputFiles({
name: "sample.wav",
mimeType: "audio/wav",
buffer: wave(),
});
await expect(page.getByRole("status")).toHaveText("Imported 1 track(s).");
await page.getByRole("button", { name: "sample.wav", exact: true }).click();
await expect(
page.getByRole("button", { name: "Pause", exact: true }),
).toBeVisible();
await page.getByRole("button", { name: "Home", exact: true }).click();
expect(
await page
.locator(".music audio")
.evaluate((element: HTMLAudioElement) => element.paused),
).toBe(false);
await launch();
await page.getByRole("button", { name: "Pause", exact: true }).click();
await page.getByLabel("Import audio", { exact: true }).setInputFiles({
name: "second.wav",
mimeType: "audio/wav",
buffer: wave(),
});
await expect(page.getByRole("status")).toHaveText("Imported 1 track(s).");
async function openFirstFromExplorer() {
await page.evaluate(async () => {
const fsPath = "/src/stores/useFileSystemStore.ts";
const openPath = "/src/lib/openNode.ts";
const { useFileSystemStore } = await import(fsPath);
const { openFsNode } = await import(openPath);
const file = (
Object.values(useFileSystemStore.getState().nodes) as { name: string }[]
).find((node) => node.name === "sample.wav");
openFsNode(file);
});
}
await openFirstFromExplorer();
await page.getByRole("button", { name: "second.wav", exact: true }).click();
await expect(page.locator(".music__player > strong")).toHaveText(
"second.wav",
);
await openFirstFromExplorer();
await expect(page.locator(".music__player > strong")).toHaveText(
"sample.wav",
);
await page.getByLabel("Playlist name", { exact: true }).fill("Favorites");
await page
.getByRole("button", { name: "Create playlist", exact: true })
.click();
await page
.getByLabel("Add sample.wav to playlist", { exact: true })
.selectOption({ label: "Favorites" });
await page.reload();
await expect(page.locator(".boot")).toHaveCount(0);
await launch();
await page
.getByLabel("Music playlist", { exact: true })
.selectOption({ label: "Favorites" });
await expect(
page.getByRole("button", { name: "sample.wav", exact: true }),
).toBeVisible();
await expect(
page.getByRole("button", { name: "Play", exact: true }),
).toBeVisible();
await page.getByRole("button", { name: "sample.wav", exact: true }).click();
await expect(
page.getByRole("button", { name: "Pause", exact: true }),
).toBeVisible();
const player = await page.locator(".music audio").elementHandle();
await page.evaluate(async () => {
const path = "/src/stores/useWindowStore.ts";
const { useWindowStore } = await import(path);
const window = useWindowStore
.getState()
.windows.find((item: { appId: string }) => item.appId === "music");
useWindowStore.getState().closeWindow(window.id);
});
await expect(page.locator(".music")).toHaveCount(0);
expect(
await player!.evaluate((element: HTMLAudioElement) => element.paused),
).toBe(true);
const media = await page.evaluate(async () => {
const path = "/src/stores/useFileSystemStore.ts";
const { useFileSystemStore } = await import(path);
const fs = useFileSystemStore.getState();
const file = (
Object.values(fs.nodes) as { id: string; name: string; content: string }[]
).find((node) => node.name === "sample.wav")!;
fs.deleteNode(file.id);
fs.permanentlyDelete(file.id);
return file.content.slice(12);
});
await expect
.poll(async () =>
page.evaluate(async (id) => {
const path = "/src/lib/audioStorage.ts";
const { getAudio } = await import(path);
return !!(await getAudio(id));
}, media),
)
.toBe(false);
});
59 changes: 59 additions & 0 deletions src/apps/Music/Music.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
.music {
height: 100%;
overflow: auto;
display: flex;
flex-direction: column;
background: var(--color-bg);
color: var(--color-text);
padding: 12px;
gap: 12px;
}
.music__toolbar {
display: flex;
flex-wrap: wrap;
gap: 8px;
align-items: center;
}
.music button,
.music select,
.music input:not([type="range"]):not([type="checkbox"]) {
background: var(--color-surface);
color: inherit;
padding: 8px;
border: 1px solid var(--color-border);
border-radius: 6px;
max-width: 100%;
}
.music label {
display: flex;
flex-wrap: wrap;
gap: 6px;
align-items: center;
}
.music__library {
flex: 1 0 120px;
overflow: auto;
}
.music__track {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-bottom: 8px;
}
.music__track > button:first-child {
flex: 1;
text-align: left;
overflow-wrap: anywhere;
}
.music button[aria-pressed="true"] {
outline: 2px solid var(--color-accent);
}
.music__player {
display: flex;
flex-direction: column;
gap: 10px;
}
.music__player > label input {
flex: 1;
min-width: 100px;
}
Loading
Loading