|
| 1 | +import type { ConsoleMessage } from '@playwright/test'; |
1 | 2 | import { expect, test } from './fixtures';
|
2 | 3 |
|
| 4 | +// TODO: Write tests to verify: |
| 5 | +// - No console logs/errors -- including/especially CSP violations |
| 6 | +// - Theme loader works |
| 7 | +// - Custom order of sections (default, reorder, remove one, remove all) |
| 8 | +// - Bookmarks load correctly |
| 9 | +// - Open tabs is correctly populated |
| 10 | +// - Open tabs events produce expected results |
| 11 | +// - Top sites is populated |
| 12 | +// - Search works |
| 13 | +// - Open extension settings link works |
| 14 | +// - Clicking on a link works: |
| 15 | +// - bookmark |
| 16 | +// - bookmark to chrome internal page |
| 17 | +// - open tab |
| 18 | +// - open tab to chrome internal page) |
| 19 | +// - Every use of the "chrome" API |
| 20 | +// - No external requests |
| 21 | + |
3 | 22 | test('newtab page', async ({ page, extensionId }) => {
|
4 | 23 | await page.goto(`chrome-extension://${extensionId}/newtab.html`);
|
5 | 24 |
|
6 |
| - // FIXME: Better assertions |
| 25 | + await expect(page).toHaveTitle('New Tab'); |
| 26 | + await expect(page).toHaveURL(`chrome-extension://${extensionId}/newtab.html`); // didn't redirect |
7 | 27 |
|
8 | 28 | const h2s = await page.locator('h2').all();
|
9 |
| - expect(h2s).toHaveLength(5); |
10 | 29 | await expect(h2s[0]).toHaveText('Open Tabs');
|
11 | 30 | await expect(h2s[1]).toHaveText('Bookmarks');
|
12 | 31 | await expect(h2s[2]).toHaveText('History');
|
13 | 32 | await expect(h2s[3]).toHaveText('Top Sites');
|
14 | 33 | await expect(h2s[4]).toHaveText('Recently Closed Tabs');
|
| 34 | + await expect(h2s[0]).toBeAttached(); |
| 35 | + await expect(h2s[1]).toBeAttached(); |
| 36 | + await expect(h2s[2]).toBeAttached(); |
| 37 | + await expect(h2s[3]).toBeAttached(); |
| 38 | + await expect(h2s[4]).toBeAttached(); |
| 39 | + expect(h2s).toHaveLength(5); |
| 40 | + |
| 41 | + await expect(page.locator('#b')).toBeAttached(); // bookmarks |
| 42 | + await expect(page.locator('#s')).toBeAttached(); // search |
| 43 | + await expect(page.locator('#m')).toBeAttached(); // menu |
| 44 | + await expect(page.locator('#d')).toBeAttached(); // menu dropdown |
| 45 | + |
| 46 | + // TODO: Move these to their own test. |
| 47 | + // const menuDropdown = page.locator('#d'); |
| 48 | + // await expect(menuDropdown).toBeAttached(); |
| 49 | + // await expect(menuDropdown).not.toBeVisible(); |
| 50 | + |
| 51 | + // TODO: More and better assertions. |
15 | 52 | });
|
16 | 53 |
|
17 |
| -// TODO: Test it makes no external requests |
| 54 | +test('matches screenshot', async ({ page, extensionId }) => { |
| 55 | + await page.goto(`chrome-extension://${extensionId}/newtab.html`); |
| 56 | + await expect(page).toHaveScreenshot('newtab-default.png', { fullPage: true }); |
| 57 | +}); |
| 58 | + |
| 59 | +test('has no console calls or unhandled errors', async ({ page, extensionId }) => { |
| 60 | + const unhandledErrors: Error[] = []; |
| 61 | + const consoleMessages: ConsoleMessage[] = []; |
| 62 | + page.on('pageerror', (err) => unhandledErrors.push(err)); |
| 63 | + page.on('console', (msg) => consoleMessages.push(msg)); |
| 64 | + await page.goto(`chrome-extension://${extensionId}/newtab.html`); |
| 65 | + expect(unhandledErrors).toHaveLength(0); |
| 66 | + expect(consoleMessages).toHaveLength(0); |
| 67 | +}); |
0 commit comments