Skip to content

Commit ada8624

Browse files
committed
add automatic auth
1 parent 3a58471 commit ada8624

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import { expect, test } from './helpers/fixtures';
22

33
test.describe('dashboard', () => {
4-
test.beforeEach(async ({ login, page }) => {
5-
await login();
6-
await expect(page).toHaveURL('/dashboard');
7-
});
8-
94
test('should display the dashboard header', async ({ getPageModel }) => {
10-
const dashboardPage = getPageModel('/dashboard');
5+
const dashboardPage = await getPageModel('/dashboard');
116
await expect(dashboardPage.pageHeader).toBeVisible();
127
await expect(dashboardPage.pageHeader).toContainText('Dashboard');
138
});

testing/e2e/src/helpers/fixtures.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,16 @@ const pageModels = {
3434
} satisfies { [K in RouteTo]?: any };
3535

3636
export const test = base.extend<TestArgs, WorkerArgs>({
37-
getPageModel: ({ page }, use) => {
37+
getPageModel: ({ getProjectAuth, page }, use) => {
3838
return use(
3939
async <TKey extends Extract<keyof PageModels, RouteTo>>(key: TKey, ...args: NavigateVariadicArgs<TKey>) => {
4040
const pageModel = new pageModels[key](page) as InstanceType<PageModels[TKey]>;
41+
if (pageModel._requiresAuth) {
42+
const auth = await getProjectAuth();
43+
await page.addInitScript((accessToken) => {
44+
window.__PLAYWRIGHT_ACCESS_TOKEN__ = accessToken;
45+
}, auth.accessToken);
46+
}
4147
await pageModel.goto(key, ...args);
4248
return pageModel;
4349
}

0 commit comments

Comments
 (0)