-
Notifications
You must be signed in to change notification settings - Fork 0
/
boosty.to.spec.js
36 lines (29 loc) · 1.5 KB
/
boosty.to.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import path from 'path';
import { test, expect } from '@playwright/test';
const URL = 'https://boosty.to/gulderov/posts/2cedc29e-8a91-4130-92f7-32c20e1a781f';
test.describe('Boosty.to Seek Functionality', () => {
test.beforeEach(async ({ page }) => {
await page.goto(URL);
await page.waitForLoadState('networkidle');
await page.addScriptTag({ path: path.join(__dirname, '../Shared (Extension)/Resources/content.js') });
await page.waitForFunction(() => window.boostyTimecodesProcessPosts !== undefined);
await page.evaluate(() => window.boostyTimecodesProcessPosts());
await page.waitForSelector('.boosty-timecode');
});
test('Timecodes are converted to clickable links', async ({ page }) => {
const timecodeLinks = await page.$$('.boosty-timecode');
expect(timecodeLinks.length).toBeGreaterThan(0);
});
test('Clicking a timecode seeks the video', async ({ page }) => {
const timecodeLink = await page.$('.boosty-timecode');
expect(timecodeLink).not.toBeNull();
const timecode = await timecodeLink.getAttribute('data-timecode');
expect(timecode).not.toBeNull();
await timecodeLink.click();
const videoElement = await page.waitForSelector('video', { state: 'visible' });
const currentTime = await videoElement.evaluate(video => video.currentTime);
const expectedSeconds = await page.evaluate(({ timecode }) => window.convertTimecodeToSeconds(timecode), { timecode });
const diff = currentTime - expectedSeconds;
expect(diff).toBeLessThan(1);
});
});