Skip to content

Commit 5df9af4

Browse files
Add visual regression tests for bookmarked view
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 0a54039 commit 5df9af4

3 files changed

Lines changed: 218 additions & 0 deletions

File tree

tests/extension.spec.js

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,4 +1374,222 @@ test.describe('', () => {
13741374
await testPage.close();
13751375
});
13761376
});
1377+
1378+
test.describe('Visual > bookmarked view', { tag: ['@visual', '@auth-session'] }, () => {
1379+
test.skip(() => !!sessionSkipReason, sessionSkipReason || 'GitHub session auth unavailable');
1380+
1381+
let authContext;
1382+
let authExtensionId;
1383+
1384+
async function addAuthBookmarks(bookmarks) {
1385+
const tempPage = await authContext.newPage();
1386+
await tempPage.goto(`chrome-extension://${authExtensionId}/assets/options.html`);
1387+
await tempPage.evaluate((bookmarks) => {
1388+
return new Promise((resolve) => {
1389+
chrome.storage.sync.set({ bookmarked_issues: bookmarks }, resolve);
1390+
});
1391+
}, bookmarks);
1392+
await tempPage.close();
1393+
}
1394+
1395+
async function clearAuthBookmarks() {
1396+
const tempPage = await authContext.newPage();
1397+
await tempPage.goto(`chrome-extension://${authExtensionId}/assets/options.html`);
1398+
await tempPage.evaluate(() => {
1399+
return new Promise((resolve) => {
1400+
chrome.storage.sync.remove('bookmarked_issues', resolve);
1401+
});
1402+
});
1403+
await tempPage.close();
1404+
}
1405+
1406+
test.beforeAll(async () => {
1407+
const auth = getGitHubAuth();
1408+
if (!auth) return;
1409+
1410+
authContext = await chromium.launchPersistentContext('', {
1411+
headless: false,
1412+
args: [
1413+
'--headless=new',
1414+
`--disable-extensions-except=${extensionPath}`,
1415+
`--load-extension=${extensionPath}`,
1416+
],
1417+
});
1418+
1419+
if (auth.cookies) {
1420+
await authContext.addCookies(auth.cookies);
1421+
}
1422+
1423+
let [background] = authContext.serviceWorkers();
1424+
if (!background) {
1425+
background = await authContext.waitForEvent('serviceworker');
1426+
}
1427+
authExtensionId = background.url().split('/')[2];
1428+
});
1429+
1430+
test.afterAll(async () => {
1431+
if (authContext) {
1432+
await authContext.close();
1433+
}
1434+
});
1435+
1436+
test('bookmarked view with issues', async () => {
1437+
const bookmarks = makeBookmarks(TEST_ISSUES[0], TEST_ISSUES[2]);
1438+
await addAuthBookmarks(bookmarks);
1439+
1440+
const graphqlResponse = {
1441+
data: {
1442+
search: {
1443+
edges: [
1444+
{
1445+
node: {
1446+
id: 'I_test1',
1447+
number: 38673,
1448+
title: 'Add visual regression testing support',
1449+
createdAt: '2024-01-10T08:00:00Z',
1450+
updatedAt: '2024-01-15T10:30:00Z',
1451+
state: 'OPEN',
1452+
author: { login: 'testauthor', name: 'Test Author' },
1453+
repository: { name: 'playwright', owner: { login: 'microsoft' } },
1454+
labels: { edges: [] },
1455+
milestone: null,
1456+
assignedActors: { edges: [] }
1457+
}
1458+
},
1459+
{
1460+
node: {
1461+
id: 'I_test2',
1462+
number: 100,
1463+
title: 'Improve hydration performance',
1464+
createdAt: '2023-08-31T12:00:00Z',
1465+
updatedAt: '2024-01-12T09:00:00Z',
1466+
state: 'CLOSED',
1467+
author: { login: 'reactdev', name: 'React Dev' },
1468+
repository: { name: 'react', owner: { login: 'facebook' } },
1469+
labels: { edges: [] },
1470+
milestone: null,
1471+
assignedActors: { edges: [] }
1472+
}
1473+
}
1474+
]
1475+
}
1476+
}
1477+
};
1478+
1479+
const secondaryResponse = {
1480+
data: {
1481+
nodes: [
1482+
{ id: 'I_test1', state: 'OPEN', totalCommentsCount: 12 },
1483+
{ id: 'I_test2', state: 'CLOSED', totalCommentsCount: 42 }
1484+
]
1485+
}
1486+
};
1487+
1488+
const isExtensionQuery = (url) => {
1489+
if (!url.includes('IssueDashboardKnownViewPageQuery') && !url.includes('IssueRowSecondaryQuery')) {
1490+
return false;
1491+
}
1492+
const body = decodeURIComponent(url.split('body=')[1] || '');
1493+
return body.includes('microsoft/playwright') || body.includes('facebook/react');
1494+
};
1495+
1496+
await authContext.route('**/github.com/_graphql**', (route) => {
1497+
const url = route.request().url();
1498+
if (!isExtensionQuery(url)) {
1499+
route.continue();
1500+
return;
1501+
}
1502+
if (url.includes('IssueRowSecondaryQuery')) {
1503+
route.fulfill({
1504+
status: 200,
1505+
contentType: 'application/json',
1506+
body: JSON.stringify(secondaryResponse)
1507+
});
1508+
} else {
1509+
route.fulfill({
1510+
status: 200,
1511+
contentType: 'application/json',
1512+
body: JSON.stringify(graphqlResponse)
1513+
});
1514+
}
1515+
});
1516+
1517+
await authContext.route('**/api.github.com/repos/**', (route) => {
1518+
const url = route.request().url();
1519+
if (url.includes('microsoft/playwright/issues/38673')) {
1520+
route.fulfill({
1521+
status: 200,
1522+
contentType: 'application/json',
1523+
body: JSON.stringify({
1524+
number: 38673,
1525+
title: 'Add visual regression testing support',
1526+
html_url: 'https://github.com/microsoft/playwright/issues/38673',
1527+
url: 'https://api.github.com/repos/microsoft/playwright/issues/38673',
1528+
state: 'open',
1529+
created_at: '2024-01-10T08:00:00Z',
1530+
updated_at: '2024-01-15T10:30:00Z',
1531+
comments: 12
1532+
})
1533+
});
1534+
} else if (url.includes('facebook/react/issues/100')) {
1535+
route.fulfill({
1536+
status: 200,
1537+
contentType: 'application/json',
1538+
body: JSON.stringify({
1539+
number: 100,
1540+
title: 'Improve hydration performance',
1541+
html_url: 'https://github.com/facebook/react/issues/100',
1542+
url: 'https://api.github.com/repos/facebook/react/issues/100',
1543+
state: 'closed',
1544+
created_at: '2023-08-31T12:00:00Z',
1545+
updated_at: '2024-01-12T09:00:00Z',
1546+
comments: 42
1547+
})
1548+
});
1549+
} else {
1550+
route.continue();
1551+
}
1552+
});
1553+
1554+
const testPage = await authContext.newPage();
1555+
await testPage.goto('https://github.com/issues/created');
1556+
await testPage.waitForLoadState('domcontentloaded');
1557+
1558+
const bookmarksNav = testPage.locator('nav a:has-text("Bookmarked")');
1559+
await expect(bookmarksNav).toBeVisible({ timeout: 10000 });
1560+
await bookmarksNav.click();
1561+
1562+
await expect(testPage.locator('[data-issue-id]').first()).toBeVisible({ timeout: 15000 });
1563+
1564+
await testPage.evaluate(() => {
1565+
document.querySelectorAll('relative-time').forEach(el => {
1566+
el.textContent = 'Jan 15, 2024';
1567+
});
1568+
});
1569+
1570+
await expect(testPage.locator('[data-extension-bookmarks-container]')).toHaveScreenshot('bookmarked-view-with-issues.png');
1571+
1572+
await authContext.unroute('**/github.com/_graphql**');
1573+
await authContext.unroute('**/api.github.com/repos/**');
1574+
await testPage.close();
1575+
});
1576+
1577+
test('bookmarked view empty state', async () => {
1578+
await clearAuthBookmarks();
1579+
1580+
const testPage = await authContext.newPage();
1581+
await testPage.goto('https://github.com/issues/created');
1582+
await testPage.waitForLoadState('domcontentloaded');
1583+
1584+
const bookmarksNav = testPage.locator('nav a:has-text("Bookmarked")');
1585+
await expect(bookmarksNav).toBeVisible({ timeout: 10000 });
1586+
await bookmarksNav.click();
1587+
1588+
await expect(testPage.locator('#bookmarks-empty')).toBeVisible({ timeout: 15000 });
1589+
1590+
await expect(testPage.locator('[data-extension-bookmarks-container]')).toHaveScreenshot('bookmarked-view-empty.png');
1591+
1592+
await testPage.close();
1593+
});
1594+
});
13771595
});
13.2 KB
Loading
30.4 KB
Loading

0 commit comments

Comments
 (0)