|
| 1 | +import {expect, Page, test} from "@playwright/test"; |
| 2 | +import {clearPadContent, goToNewPad, writeToPad} from "../helper/padHelper"; |
| 3 | + |
| 4 | +test.describe('timeslider playback speed', function () { |
| 5 | + test.describe.configure({mode: 'serial'}); |
| 6 | + |
| 7 | + test.beforeEach(async ({context}) => { |
| 8 | + await context.clearCookies(); |
| 9 | + }); |
| 10 | + |
| 11 | + const waitForTimesliderReady = async (page: Page) => { |
| 12 | + await page.waitForSelector('#timeslider-wrapper', {state: 'visible'}); |
| 13 | + await page.waitForFunction(() => { |
| 14 | + return Boolean(document.querySelector('#playpause_button_icon')?.getAttribute('title')); |
| 15 | + }); |
| 16 | + }; |
| 17 | + |
| 18 | + test('defaults to original speed with no cookies', async function ({page}) { |
| 19 | + const padId = await goToNewPad(page); |
| 20 | + await clearPadContent(page); |
| 21 | + await writeToPad(page, 'One'); |
| 22 | + await page.waitForTimeout(1000); |
| 23 | + |
| 24 | + await page.goto(`http://localhost:9001/p/${padId}/timeslider#0`); |
| 25 | + await waitForTimesliderReady(page); |
| 26 | + |
| 27 | + await expect.poll(async () => await page.evaluate(() => { |
| 28 | + const select = document.querySelector('#playbackspeed') as HTMLSelectElement | null; |
| 29 | + return { |
| 30 | + value: select?.value, |
| 31 | + firstOptionText: select?.options[0]?.text, |
| 32 | + selectedText: select?.options[select.selectedIndex]?.text, |
| 33 | + }; |
| 34 | + })).toEqual({ |
| 35 | + value: '100', |
| 36 | + firstOptionText: 'Original speed', |
| 37 | + selectedText: 'Original speed', |
| 38 | + }); |
| 39 | + }); |
| 40 | + |
| 41 | + test('persists the selected playback speed', async function ({page}) { |
| 42 | + const padId = await goToNewPad(page); |
| 43 | + await clearPadContent(page); |
| 44 | + await writeToPad(page, 'One'); |
| 45 | + await page.waitForTimeout(300); |
| 46 | + await writeToPad(page, ' Two'); |
| 47 | + await page.waitForTimeout(1000); |
| 48 | + |
| 49 | + await page.goto(`http://localhost:9001/p/${padId}/timeslider#1`); |
| 50 | + await waitForTimesliderReady(page); |
| 51 | + |
| 52 | + await page.evaluate(() => { |
| 53 | + const select = document.querySelector('#playbackspeed') as HTMLSelectElement; |
| 54 | + select.value = '500'; |
| 55 | + select.dispatchEvent(new Event('change', {bubbles: true})); |
| 56 | + }); |
| 57 | + |
| 58 | + await expect.poll(async () => await page.evaluate(() => { |
| 59 | + const select = document.querySelector('#playbackspeed') as HTMLSelectElement | null; |
| 60 | + return { |
| 61 | + controlValue: select?.value, |
| 62 | + }; |
| 63 | + })).toEqual({controlValue: '500'}); |
| 64 | + |
| 65 | + await page.reload(); |
| 66 | + await waitForTimesliderReady(page); |
| 67 | + |
| 68 | + await expect.poll(async () => await page.evaluate(() => { |
| 69 | + const select = document.querySelector('#playbackspeed') as HTMLSelectElement | null; |
| 70 | + return { |
| 71 | + controlValue: select?.value, |
| 72 | + }; |
| 73 | + })).toEqual({controlValue: '500'}); |
| 74 | + }); |
| 75 | + |
| 76 | + test('uses revision timestamps for realtime playback', async function ({page}) { |
| 77 | + const padId = await goToNewPad(page); |
| 78 | + await clearPadContent(page); |
| 79 | + await writeToPad(page, 'A'); |
| 80 | + await page.waitForTimeout(1000); |
| 81 | + |
| 82 | + await page.goto(`http://localhost:9001/p/${padId}/timeslider#0`); |
| 83 | + await waitForTimesliderReady(page); |
| 84 | + |
| 85 | + const scheduledDelays = await page.evaluate(() => { |
| 86 | + (window as any).revisionInfo.getPath = () => ({ |
| 87 | + status: 'complete', |
| 88 | + times: [1234], |
| 89 | + }); |
| 90 | + const select = document.querySelector('#playbackspeed') as HTMLSelectElement; |
| 91 | + select.value = 'realtime'; |
| 92 | + select.dispatchEvent(new Event('change', {bubbles: true})); |
| 93 | + (window as any).__playbackTimeouts = []; |
| 94 | + window.setTimeout = ((fn: TimerHandler, delay?: number, ...args: any[]) => { |
| 95 | + (window as any).__playbackTimeouts.push({ |
| 96 | + delay, |
| 97 | + name: typeof fn === 'function' ? fn.name : String(fn), |
| 98 | + }); |
| 99 | + return 1 as any; |
| 100 | + }) as typeof window.setTimeout; |
| 101 | + (document.querySelector('#playpause_button_icon') as HTMLButtonElement).click(); |
| 102 | + return (window as any).__playbackTimeouts; |
| 103 | + }); |
| 104 | + |
| 105 | + const scheduledDelay = scheduledDelays[0]?.delay; |
| 106 | + expect(scheduledDelay).toBe(1234); |
| 107 | + }); |
| 108 | +}); |
0 commit comments