Skip to content
Closed
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
15 changes: 11 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ jobs:
- name: Linux system libraries
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y libwebkit2gtk-4.1-dev libgtk-3-dev libasound2-dev libdbus-1-dev \
sudo apt-get update && sudo apt-get install -y libwebkit2gtk-4.1-dev libgtk-3-dev libasound2-dev libdbus-1-dev \
libssl-dev libayatana-appindicator3-dev librsvg2-dev libsoup-3.0-dev ffmpeg

- name: ffmpeg (test fixtures)
Expand Down Expand Up @@ -86,7 +85,16 @@ jobs:
npx playwright install --with-deps chromium
- name: Test
working-directory: ui-tests
env:
PM_SCREENSHOTS: ${{ runner.temp }}/pm-screenshots
run: npm test
- name: Upload UI screenshots
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: ui-screenshots
path: ${{ runner.temp }}/pm-screenshots
if-no-files-found: ignore

bundle:
name: Bundle (${{ matrix.name }})
Expand All @@ -105,8 +113,7 @@ jobs:
- name: Linux system libraries
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y libwebkit2gtk-4.1-dev libgtk-3-dev libasound2-dev libdbus-1-dev \
sudo apt-get update && sudo apt-get install -y libwebkit2gtk-4.1-dev libgtk-3-dev libasound2-dev libdbus-1-dev \
libssl-dev libayatana-appindicator3-dev librsvg2-dev libsoup-3.0-dev

- name: macOS targets
Expand Down
26 changes: 26 additions & 0 deletions ui-tests/mini-gesture-policy.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import assert from "node:assert/strict";
import test from "node:test";
import { gestureAction, isMiniGestureTarget } from "../ui/js/mobile/mini-gesture-policy.js";

test("an upward cover gesture opens the full player", () => {
assert.equal(gestureAction({ x: 3, y: -70 }, { x: 3, y: -70 }), "open");
const cover = { classList: { contains: name => name === "cover-button" } };
const target = { closest: () => cover };
assert.equal(isMiniGestureTarget(target), true);
});

test("horizontal swipes keep their transport meaning", () => {
assert.equal(gestureAction({ x: -90, y: 2 }, { x: -90, y: 2 }), "next");
assert.equal(gestureAction({ x: 90, y: 2 }, { x: 90, y: 2 }), "previous");
});

test("play, next and links do not become gesture starters", () => {
const button = { classList: { contains: () => false } };
const target = { closest: () => button };
assert.equal(isMiniGestureTarget(target), false);
});

test("short and downward movements have no action and need no click suppression", () => {
assert.equal(gestureAction({ x: 5, y: 10 }, { x: 5, y: 10 }), null);
assert.equal(gestureAction({ x: 2, y: 70 }, { x: 2, y: 70 }), null);
});
40 changes: 40 additions & 0 deletions ui-tests/mix-playback.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import assert from "node:assert/strict";
import test from "node:test";
import { loadMixTracks, mixOptionsRejected } from "../ui/js/mix-playback.js";

const mix = { id: "artist-mix", options: '{"curator":"anya"}' };

test("a rejected tuned mix retries untuned and continues with the working options", async () => {
const calls = [];
const tracks = [{ track_id: 1 }];
const result = await loadMixTracks(mix, async (id, options) => {
calls.push({ id, options });
if (options) throw { kind: "vk", message: "VK error 8: bad request" };
return tracks;
});
assert.deepEqual(result, { tracks, options: null });
assert.deepEqual(calls, [
{ id: "artist-mix", options: mix.options },
{ id: "artist-mix", options: null },
]);
});

test("an empty tuned response also falls back to the plain mix", async () => {
const tracks = [{ track_id: 2 }];
const result = await loadMixTracks(mix, async (_id, options) => options ? [] : tracks);
assert.deepEqual(result, { tracks, options: null });
});

test("network and service failures are not hidden by a second request", async () => {
const failure = { kind: "offline", message: "No internet connection." };
let calls = 0;
await assert.rejects(loadMixTracks(mix, async () => { calls += 1; throw failure; }), error => error === failure);
assert.equal(calls, 1);
assert.equal(mixOptionsRejected(failure), false);
});

test("an accepted tuned mix keeps its options for radio continuation", async () => {
const tracks = [{ track_id: 3 }];
const result = await loadMixTracks(mix, async () => tracks);
assert.deepEqual(result, { tracks, options: mix.options });
});
25 changes: 25 additions & 0 deletions ui-tests/mix-shelf-regressions.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import assert from "node:assert/strict";
import test from "node:test";
import { openApp } from "./harness.js";

test("a catalog mix rejected by VK starts untuned and keeps that continuation", async () => {
const app = await openApp({ config: { signedIn: true, platform: "android", catalogMixes: true }, phone: "small" });
try {
const { page } = app;
await page.locator(".mix-tile").nth(1).waitFor();
await page.evaluate(() => {
const invoke = window.__TAURI__.core.invoke;
window.__TAURI__.core.invoke = (command, args) => {
if (command === "stream_mix" && args.options) throw { kind: "vk", message: "VK error 8: bad request" };
return invoke(command, args);
};
});
await page.locator(".mix-tile").nth(1).click();
await page.waitForFunction(() => window.__mock.calls.some(call => call.command === "play_radio"));
const calls = await page.evaluate(() => window.__mock.calls.filter(call => call.command === "stream_mix").map(call => call.args.options));
assert.deepEqual(calls, ['{"mood":["calm"]}', null]);
assert.equal(await page.evaluate(() => window.__mock.last("play_radio").args.source.options), null);
if (process.env.PM_SCREENSHOTS) await page.screenshot({ path: `${process.env.PM_SCREENSHOTS}/mix-untuned-playing.png` });
assert.deepEqual(app.problems, []);
} finally { await app.close(); }
});
2 changes: 1 addition & 1 deletion ui-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"type": "module",
"scripts": {
"test": "node --test --test-concurrency=1 catalogue-gate.test.js polish.test.js ui.test.js network.test.js features.test.js phone.test.js parity.test.js share-links.test.js radio-snapshot.test.js saved-lyrics.test.js download-details.test.js player-regressions.test.js lyrics-copy.test.js performance.test.js ios-phone-parity.test.js audio-export-lyrics.test.js screen-audit.test.js updates.test.js artwork.test.js interface-regressions.test.js html-entities.test.js track-filter.test.js state-regressions.test.js security-regressions.test.js local-audio.test.js local-audio-actions.test.js queue-transport.test.js"
"test": "node --test --test-concurrency=1 catalogue-gate.test.js polish.test.js ui.test.js network.test.js features.test.js phone.test.js parity.test.js share-links.test.js radio-snapshot.test.js saved-lyrics.test.js download-details.test.js player-regressions.test.js lyrics-copy.test.js performance.test.js ios-phone-parity.test.js audio-export-lyrics.test.js screen-audit.test.js updates.test.js artwork.test.js interface-regressions.test.js html-entities.test.js track-filter.test.js state-regressions.test.js security-regressions.test.js local-audio.test.js local-audio-actions.test.js queue-transport.test.js seek-gate.test.js mix-playback.test.js mini-gesture-policy.test.js player-seek-regressions.test.js mix-shelf-regressions.test.js"
},
"devDependencies": {
"playwright": "1.64.1"
Expand Down
87 changes: 87 additions & 0 deletions ui-tests/player-seek-regressions.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import assert from "node:assert/strict";
import test from "node:test";
import { openApp } from "./harness.js";

const config = { signedIn: true, platform: "android", catalogMixes: true };

async function startTrack(page) {
await page.locator(".stage-cta").click();
await page.locator(".player:not(.is-empty)").waitFor();
}

test("the scrubber does not flash the pre-seek position while the command is pending", async () => {
const app = await openApp({ config, phone: "small" });
try {
const { page } = app;
await startTrack(page);
await page.locator(".player .now").click();
const lane = page.locator(".np .np-seek input");
await lane.waitFor();
await page.waitForTimeout(400);
await page.evaluate(() => {
const invoke = window.__TAURI__.core.invoke;
window.__TAURI__.core.invoke = (command, args) => {
if (command === "seek") return new Promise(resolve => {
window.__finishSeek = () => {
window.__mock.state.player.position = args.seconds;
window.__mock.emitState();
resolve();
};
});
return invoke(command, args);
};
});
const box = await lane.boundingBox();
const max = Number(await lane.getAttribute("max"));
await page.touchscreen.tap(box.x + box.width * 0.75, box.y + box.height / 2);
await page.waitForFunction(() => !!window.__finishSeek);
await page.evaluate(() => {
window.__mock.state.player.position = 0;
window.__mock.emitState();
});
assert.ok(Math.abs(Number(await lane.inputValue()) - max * 0.75) <= max * 0.03);
await page.evaluate(() => window.__finishSeek());
await page.waitForFunction(() => Math.abs(window.__mock.state.player.position - window.__mock.last("seek").args.seconds) < 0.01);
if (process.env.PM_SCREENSHOTS) await page.screenshot({ path: `${process.env.PM_SCREENSHOTS}/phone-seek-confirmed.png` });
assert.deepEqual(app.problems, []);
} finally { await app.close(); }
});

test("the compact player timeline keeps advancing while its slider has focus", async () => {
const app = await openApp({ config });
try {
const { page } = app;
await page.locator(".main .row").first().dblclick();
const slider = page.locator(".mini-player input[type=range]");
await slider.focus();
await page.evaluate(() => {
window.__mock.state.player.duration = 300;
window.__mock.state.player.position = 42;
window.__mock.emitState();
});
assert.equal(Number(await slider.inputValue()), 42);
assert.equal(await page.locator(".mini-time").textContent(), "0:42");
assert.deepEqual(app.problems, []);
} finally { await app.close(); }
});

test("an upward swipe that starts on the mini player cover opens Now Playing", async () => {
const app = await openApp({ config, phone: "small" });
try {
const { page } = app;
await startTrack(page);
const box = await page.locator(".player .cover-button").boundingBox();
const x = box.x + box.width / 2;
const y = box.y + box.height / 2;
const cdp = await page.context().newCDPSession(page);
try {
await cdp.send("Input.dispatchTouchEvent", { type: "touchStart", touchPoints: [{ x, y, id: 1 }] });
for (let i = 1; i <= 5; i += 1) {
await cdp.send("Input.dispatchTouchEvent", { type: "touchMove", touchPoints: [{ x, y: y - i * 16, id: 1 }] });
}
await cdp.send("Input.dispatchTouchEvent", { type: "touchEnd", touchPoints: [] });
} finally { await cdp.detach(); }
await page.locator(".np:not([hidden])").waitFor();
assert.deepEqual(app.problems, []);
} finally { await app.close(); }
});
46 changes: 46 additions & 0 deletions ui-tests/seek-gate.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import assert from "node:assert/strict";
import test from "node:test";
import { createSeekGate } from "../ui/js/seek-gate.js";

test("an old state packet cannot replace the requested position", async () => {
const gate = createSeekGate(() => {});
gate.preview();
assert.equal(gate.shouldRender(10), false);
await gate.commit(90, async () => {});
assert.equal(gate.shouldRender(10), false);
assert.equal(gate.shouldRender(90), true);
assert.equal(gate.shouldRender(91), true);
});

test("an invoke acknowledgement alone does not release the scrubber", async () => {
const gate = createSeekGate(() => {});
await gate.commit(75, async () => {});
assert.equal(gate.shouldRender(4), false);
});

test("a failed or unanswered seek returns to the real position after the timeout", async () => {
let notified = 0;
const gate = createSeekGate(() => { notified += 1; }, { timeout: 5 });
await gate.commit(80, async () => { throw new Error("seek failed"); }).catch(() => {});
assert.equal(gate.shouldRender(8), false);
await new Promise(resolve => setTimeout(resolve, 15));
assert.equal(gate.shouldRender(8), true);
assert.ok(notified >= 1);
});

test("an older request cannot clear a newer gesture", async () => {
const gate = createSeekGate(() => {});
let finish;
const first = gate.commit(30, () => new Promise(resolve => { finish = resolve; }));
gate.preview();
finish();
await first;
assert.equal(gate.shouldRender(12), false);
});

test("changing tracks cancels the pending position", async () => {
const gate = createSeekGate(() => {});
await gate.commit(80, async () => {});
gate.track("7_2");
assert.equal(gate.shouldRender(0), true);
});
19 changes: 15 additions & 4 deletions ui/js/mini-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { artBox } from "./ui-parts.js";
import { setWindowMode } from "./window-mode.js";
import { toast } from "./toast.js";
import { errorText } from "./i18n.js";
import { createSeekGate } from "./seek-gate.js";
export function createMiniPlayer(onLike) {
const safe = (fn) => () =>
Promise.resolve()
Expand All @@ -32,14 +33,19 @@ export function createMiniPlayer(onLike) {
const previous = button(ft("Предыдущий"), "prev", () => api.previous());
const next = button(ft("Следующий"), "next", () => api.next());
const like = button(ft("Избранное"), "heart", () => onLike(store.player.track));
const seekGate = createSeekGate(() => render());
const seek = h("input", {
type: "range",
min: 0,
max: 1,
step: 0.1,
value: 0,
"aria-label": ft("Позиция воспроизведения"),
onchange: (event) => safe(() => api.seek(Number(event.target.value)))(),
oninput: () => { seekGate.preview(); time.textContent = formatTime(Number(seek.value)); },
onchange: (event) => {
const value = Number(event.target.value);
safe(() => seekGate.commit(value, () => api.seek(value)))();
},
});
const time = h("span", { class: "mini-time" });
const element = h(
Expand Down Expand Up @@ -68,6 +74,7 @@ export function createMiniPlayer(onLike) {
function render() {
const p = store.player;
const key = p.track ? `${p.track.owner_id}_${p.track.track_id}` : null;
seekGate.track(key);
if (key !== previousKey) {
previousKey = key;
art.replaceChildren(artBox(p.track?.artwork_url));
Expand All @@ -91,9 +98,13 @@ export function createMiniPlayer(onLike) {
like.setAttribute("aria-pressed", String(liked));
like.hidden = isLocalTrack(p.track);
like.disabled = !p.track || isLocalTrack(p.track);
seek.max = String(p.duration || 1);
if (document.activeElement !== seek) seek.value = String(p.position || 0);
time.textContent = formatTime(p.position);
const duration = Math.max(0, p.duration || 0);
const position = Math.min(Math.max(0, p.position || 0), duration);
seek.max = String(duration || 1);
if (seekGate.shouldRender(p.position)) {
seek.value = String(position);
time.textContent = formatTime(position);
}
}
subscribe("player", render);
subscribe("likes", render);
Expand Down
23 changes: 23 additions & 0 deletions ui/js/mix-playback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// VK rejects some undocumented mix_options shapes with error 8. Match the iOS
// client: retry the tile untuned and use the working options for continuation.
export function mixOptionsRejected(error) {
const message = String(error?.message ?? error ?? "");
return error?.kind === "invalid" || (error?.kind === "vk" && /error\s+8|bad request/i.test(message));
}

export async function loadMixTracks(mix, stream) {
let options = mix.options ?? null;
let tracks;
try {
tracks = await stream(mix.id, options);
} catch (error) {
if (!options || !mixOptionsRejected(error)) throw error;
tracks = await stream(mix.id, null);
options = null;
}
if (!tracks.length && options) {
tracks = await stream(mix.id, null);
options = null;
}
return { tracks, options };
}
26 changes: 26 additions & 0 deletions ui/js/mobile/mini-gesture-policy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const MIN_DISTANCE = 18;
const HORIZONTAL = 58;
const VERTICAL = 42;
const DOMINANCE = 1.2;

/** The iOS policy: "next" | "previous" | "open" | null for a drag. */
export function gestureAction(translation, predicted) {
const settled = Math.hypot(translation.x, translation.y);
const heading = Math.hypot(predicted.x, predicted.y);
const t = heading > settled ? predicted : translation;
const horizontal = Math.abs(t.x);
const vertical = Math.abs(t.y);
if (Math.max(horizontal, vertical) < MIN_DISTANCE) return null;
if (vertical >= horizontal * DOMINANCE) return t.y <= -VERTICAL ? "open" : null;
if (horizontal >= vertical * DOMINANCE) {
if (t.x <= -HORIZONTAL) return "next";
if (t.x >= HORIZONTAL) return "previous";
}
return null;
}

/** Cover swipes are allowed; transport and other native controls keep their taps. */
export function isMiniGestureTarget(target) {
const control = target?.closest?.("button, input, a, [role=button]");
return !control || control.classList.contains("cover-button");
}
Loading
Loading