-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.test.js
55 lines (47 loc) · 1.98 KB
/
popup.test.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const puppeteer = require('puppeteer');
describe('Popup Duration Save Tests', () => {
let browser;
let page;
beforeAll(async () => {
browser = await puppeteer.launch({ headless: true, args: ['--no-sandbox', '--disable-setuid-sandbox'] });
page = await browser.newPage();
// Mock chrome.storage.sync API
await page.evaluateOnNewDocument(() => {
window.chrome = {
storage: {
sync: {
get: (keys, callback) => {
const data = { timestampDuration: 24 };
callback(data);
},
set: (items, callback) => {
callback();
}
}
}
};
});
await page.goto(`file://${__dirname}/../html/popup.html`);
});
afterAll(async () => {
await browser.close();
});
test('should load the default duration value', async () => {
const durationValue = await page.$eval('#duration', el => el.value);
expect(durationValue).toBe('24');
});
test('should save a valid duration value', async () => {
await page.evaluate(() => document.getElementById('duration').value = ''); // Clear input
await page.type('#duration', '48');
await page.click('#save');
const saveMessage = await page.$eval('#saveMessage', el => el.innerText);
expect(saveMessage).toBe('Duration saved successfully!');
});
test('should show error message for invalid duration value', async () => {
await page.evaluate(() => document.getElementById('duration').value = ''); // Clear input
await page.type('#duration', '200');
await page.click('#save');
const saveMessage = await page.$eval('#saveMessage', el => el.innerText);
expect(saveMessage).toBe('Please enter a valid duration between 1 and 168 hours.');
});
});