From d4cbdeaec9953df5e4e5e5ddd39a5ecf4f01ad41 Mon Sep 17 00:00:00 2001 From: George He Date: Fri, 15 Dec 2023 16:38:51 +0800 Subject: [PATCH] fix: revert commented tests --- .../tests/smoke/git-sync.test.ts | 93 +++++++++---------- .../tests/smoke/oauth-gitlab.test.ts | 64 ++++++------- 2 files changed, 78 insertions(+), 79 deletions(-) diff --git a/packages/insomnia-smoke-test/tests/smoke/git-sync.test.ts b/packages/insomnia-smoke-test/tests/smoke/git-sync.test.ts index dafd24d37f..d9c9618a0a 100644 --- a/packages/insomnia-smoke-test/tests/smoke/git-sync.test.ts +++ b/packages/insomnia-smoke-test/tests/smoke/git-sync.test.ts @@ -1,61 +1,60 @@ import { test } from '../../playwright/test'; test('Clone from github', async ({ page }) => { - await page.getByLabel('Clone git repository').click(); - await page.getByRole('tab', { name: ' Git' }).click(); - await page.getByPlaceholder('https://github.com/org/repo.git').fill('https://github.com/gatzjames/insomnia-git-example.git'); - await page.getByPlaceholder('Name').fill('J'); - await page.getByPlaceholder('Email').fill('J'); - await page.getByPlaceholder('MyUser').fill('J'); - await page.getByPlaceholder('88e7ee63b254e4b0bf047559eafe86ba9dd49507').fill('J'); - await page.getByTestId('git-repository-settings-modal__sync-btn').click(); - await page.getByLabel('Toggle preview').click(); + await page.getByLabel('Clone git repository').click(); + await page.getByRole('tab', { name: ' Git' }).click(); + await page.getByPlaceholder('https://github.com/org/repo.git').fill('https://github.com/gatzjames/insomnia-git-example.git'); + await page.getByPlaceholder('Name').fill('J'); + await page.getByPlaceholder('Email').fill('J'); + await page.getByPlaceholder('MyUser').fill('J'); + await page.getByPlaceholder('88e7ee63b254e4b0bf047559eafe86ba9dd49507').fill('J'); + await page.getByTestId('git-repository-settings-modal__sync-btn').click(); + await page.getByLabel('Toggle preview').click(); }); - test('Sign in with GitHub', async ({ app, page }) => { - await page.getByRole('button', { name: 'New Document' }).click(); - await page.getByRole('dialog').getByRole('button', { name: 'Create' }).click(); - await page.getByLabel('Insomnia Sync').click(); - await page.getByRole('menuitemradio', { name: 'Switch to Git Repository' }).click(); + await page.getByRole('button', { name: 'New Document' }).click(); + await page.getByRole('dialog').getByRole('button', { name: 'Create' }).click(); + await page.getByLabel('Insomnia Sync').click(); + await page.getByRole('menuitemradio', { name: 'Switch to Git Repository' }).click(); - await page.getByRole('tab', { name: 'Github' }).click(); + await page.getByRole('tab', { name: 'Github' }).click(); - // Prevent the app from opening the browser to the authorization page - // and return the url that would be created by following the GitHub OAuth flow. - // https://docs.github.com/en/developers/apps/building-oauth-apps/authorizing-oauth-apps#web-application-flow - const fakeGitHubOAuthWebFlow = app.evaluate(electron => { - return new Promise<{ redirectUrl: string }>(resolve => { - const webContents = electron.BrowserWindow.getAllWindows()[0].webContents; - // Remove all navigation listeners so that only the one we inject will run - webContents.removeAllListeners('will-navigate'); - webContents.on('will-navigate', (event: Event, url: string) => { - event.preventDefault(); - const parsedUrl = new URL(url); - // We use the same state parameter that the app created to assert that we prevent CSRF - const stateSearchParam = parsedUrl.searchParams.get('state') || ''; - const redirectUrl = `insomnia://oauth/github/authenticate?state=${stateSearchParam}&code=12345`; - resolve({ redirectUrl }); - }); - }); + // Prevent the app from opening the browser to the authorization page + // and return the url that would be created by following the GitHub OAuth flow. + // https://docs.github.com/en/developers/apps/building-oauth-apps/authorizing-oauth-apps#web-application-flow + const fakeGitHubOAuthWebFlow = app.evaluate(electron => { + return new Promise<{ redirectUrl: string }>(resolve => { + const webContents = electron.BrowserWindow.getAllWindows()[0].webContents; + // Remove all navigation listeners so that only the one we inject will run + webContents.removeAllListeners('will-navigate'); + webContents.on('will-navigate', (event: Event, url: string) => { + event.preventDefault(); + const parsedUrl = new URL(url); + // We use the same state parameter that the app created to assert that we prevent CSRF + const stateSearchParam = parsedUrl.searchParams.get('state') || ''; + const redirectUrl = `insomnia://oauth/github/authenticate?state=${stateSearchParam}&code=12345`; + resolve({ redirectUrl }); + }); }); + }); - const [{ redirectUrl }] = await Promise.all([ - fakeGitHubOAuthWebFlow, - page.getByText('Authenticate with GitHub').click({ - // When playwright clicks a link it waits for navigation to finish. - // In our case we are stubbing the navigation and we don't want to wait for it. - noWaitAfter: true, - }), - ]); + const [{ redirectUrl }] = await Promise.all([ + fakeGitHubOAuthWebFlow, + page.getByText('Authenticate with GitHub').click({ + // When playwright clicks a link it waits for navigation to finish. + // In our case we are stubbing the navigation and we don't want to wait for it. + noWaitAfter: true, + }), + ]); - await page.locator('input[name="link"]').click(); + await page.locator('input[name="link"]').click(); - await page.locator('input[name="link"]').fill(redirectUrl); + await page.locator('input[name="link"]').fill(redirectUrl); - await page.getByRole('button', { name: 'Authenticate' }).click(); + await page.getByRole('button', { name: 'Authenticate' }).click(); - await page - .locator('input[name="uri"]') - .fill('https://github.com/insomnia/example-repo'); + await page + .locator('input[name="uri"]') + .fill('https://github.com/insomnia/example-repo'); - await page.locator('data-testid=git-repository-settings-modal__sync-btn').click(); + await page.locator('data-testid=git-repository-settings-modal__sync-btn').click(); }); diff --git a/packages/insomnia-smoke-test/tests/smoke/oauth-gitlab.test.ts b/packages/insomnia-smoke-test/tests/smoke/oauth-gitlab.test.ts index 836fe130c7..588877c493 100644 --- a/packages/insomnia-smoke-test/tests/smoke/oauth-gitlab.test.ts +++ b/packages/insomnia-smoke-test/tests/smoke/oauth-gitlab.test.ts @@ -1,41 +1,41 @@ import { test } from '../../playwright/test'; test('Sign in with Gitlab', async ({ app, page }) => { - await page.getByRole('button', { name: 'New Document' }).click(); - await page.getByRole('dialog').getByRole('button', { name: 'Create' }).click(); - await page.getByLabel('Insomnia Sync').click(); - await page.getByRole('menuitemradio', { name: 'Switch to Git Repository' }).click(); - await page.getByRole('tab', { name: 'GitLab' }).click(); + await page.getByRole('button', { name: 'New Document' }).click(); + await page.getByRole('dialog').getByRole('button', { name: 'Create' }).click(); + await page.getByLabel('Insomnia Sync').click(); + await page.getByRole('menuitemradio', { name: 'Switch to Git Repository' }).click(); + await page.getByRole('tab', { name: 'GitLab' }).click(); - const fakeGitLabOAuthWebFlow = app.evaluate(electron => { - return new Promise<{ redirectUrl: string }>(resolve => { - const webContents = electron.BrowserWindow.getAllWindows()[0].webContents; - // Remove all navigation listeners so that only the one we inject will run - webContents.removeAllListeners('will-navigate'); - webContents.on('will-navigate', (event: Event, url: string) => { - event.preventDefault(); - const parsedUrl = new URL(url); - // We use the same state parameter that the app created to assert that we prevent CSRF - const stateSearchParam = parsedUrl.searchParams.get('state') || ''; - const redirectUrl = `insomnia://oauth/gitlab/authenticate?code=12345&state=${stateSearchParam}`; - resolve({ redirectUrl }); - }); - }); + const fakeGitLabOAuthWebFlow = app.evaluate(electron => { + return new Promise<{ redirectUrl: string }>(resolve => { + const webContents = electron.BrowserWindow.getAllWindows()[0].webContents; + // Remove all navigation listeners so that only the one we inject will run + webContents.removeAllListeners('will-navigate'); + webContents.on('will-navigate', (event: Event, url: string) => { + event.preventDefault(); + const parsedUrl = new URL(url); + // We use the same state parameter that the app created to assert that we prevent CSRF + const stateSearchParam = parsedUrl.searchParams.get('state') || ''; + const redirectUrl = `insomnia://oauth/gitlab/authenticate?code=12345&state=${stateSearchParam}`; + resolve({ redirectUrl }); + }); }); + }); - const [{ redirectUrl }] = await Promise.all([ - fakeGitLabOAuthWebFlow, - page.getByText('Authenticate with GitLab').click({ - // When playwright clicks a link it waits for navigation to finish. - // In our case we are stubbing the navigation and we don't want to wait for it. - noWaitAfter: true, - }), - ]); + const [{ redirectUrl }] = await Promise.all([ + fakeGitLabOAuthWebFlow, + page.getByText('Authenticate with GitLab').click({ + // When playwright clicks a link it waits for navigation to finish. + // In our case we are stubbing the navigation and we don't want to wait for it. + noWaitAfter: true, + }), + ]); - await page.locator('input[name="link"]').click(); - await page.locator('input[name="link"]').fill(redirectUrl); - await page.getByRole('button', { name: 'Authenticate' }).click(); + await page.locator('input[name="link"]').click(); + await page.locator('input[name="link"]').fill(redirectUrl); + await page.getByRole('button', { name: 'Authenticate' }).click(); - test.expect(await page.locator('text="Mark Kim"')).toBeTruthy(); - test.expect(await page.locator('button[name="sign-out"]')).toBeTruthy(); + test.expect(await page.locator('text="Mark Kim"')).toBeTruthy(); + test.expect(await page.locator('button[name="sign-out"]')).toBeTruthy(); });