-
Notifications
You must be signed in to change notification settings - Fork 116
chore(tests/e2e): proof of concept playwright e2e test #6530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jasonkuhrt
wants to merge
1
commit into
main
Choose a base branch
from
console-1075
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { expect, Locator } from '@playwright/test'; | ||
import { enhancePageWithHelpers, HelpersConstructor } from '../playwright'; | ||
|
||
export interface LaboratoryHelpers { | ||
graphiql: { | ||
documentEditor: Locator; | ||
documentEditorFill: (text: string) => Promise<void>; | ||
buttonNewTab: Locator; | ||
buttonCloseTab: Locator; | ||
}; | ||
} | ||
|
||
export const createLaboratoryHelpers: HelpersConstructor<LaboratoryHelpers> = page => { | ||
const documentEditor = page.getByRole('region', { name: 'Query Editor' }); | ||
const buttonNewTab = page.getByRole('button', { name: 'New tab' }); | ||
const buttonCloseTab = page.getByRole('button', { name: 'Close Tab' }); | ||
|
||
return { | ||
graphiql: { | ||
documentEditorFill: async (text: string) => { | ||
await documentEditor.click(); | ||
await page.keyboard.press('ControlOrMeta+KeyA'); | ||
await page.keyboard.type(text); | ||
await expect(documentEditor).toContainText(text); // sanity check content changed | ||
}, | ||
documentEditor, | ||
buttonNewTab, | ||
buttonCloseTab, | ||
}, | ||
}; | ||
}; | ||
|
||
export const enhancePageWithLaboratoryHelpers = enhancePageWithHelpers(createLaboratoryHelpers); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Page } from '@playwright/test'; | ||
|
||
export const enhancePageWithHelpers = | ||
<page extends Page, helpers extends object>(helpersConstructor: HelpersConstructor<helpers>) => | ||
(page: Page): page & helpers => { | ||
Object.assign(page, helpersConstructor(page)); | ||
return page as page & helpers; | ||
}; | ||
|
||
export type HelpersConstructor<$Helpers extends object> = (page: Page) => $Helpers; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { expect, Page, test as testBase } from '@playwright/test'; | ||
import { | ||
enhancePageWithLaboratoryHelpers, | ||
LaboratoryHelpers, | ||
} from '../__helpers__/page/laboratory'; | ||
import { initSeed } from '../../integration-tests/testkit/seed'; | ||
|
||
interface Context { | ||
page: Page & LaboratoryHelpers; | ||
} | ||
|
||
const test = testBase.extend<Context>({ | ||
page: async ({ page }, use) => { | ||
const seed = initSeed(); | ||
const owner = await seed.createOwner(); | ||
const org = await owner.createOrg(); | ||
const project = await org.createProject(); | ||
|
||
await page.context().addCookies([ | ||
{ | ||
name: 'sRefreshToken', | ||
value: owner.ownerRefreshToken, | ||
domain: 'localhost', | ||
path: '/', | ||
}, | ||
]); | ||
|
||
await page.goto(`${project.target.path}/laboratory`); | ||
await use(enhancePageWithLaboratoryHelpers(page)); | ||
}, | ||
}); | ||
|
||
test('closing the last tab should reset its state to defaults', async ({ page }) => { | ||
Check failure on line 33 in e2e-tests/laboratory/tabs.spec.ts
|
||
const { documentEditor, buttonNewTab, buttonCloseTab, documentEditorFill } = page.graphiql; | ||
|
||
const content = { | ||
partialDefault: '# Welcome to GraphiQL', | ||
document1: 'query { tab1 }', | ||
document2: 'query { tab2 }', | ||
}; | ||
|
||
// Begins with default content | ||
await expect(documentEditor).toContainText(content.partialDefault); | ||
// Change content | ||
await documentEditorFill(content.document1); | ||
// Open a new tab | ||
await buttonNewTab.click(); | ||
await documentEditorFill(content.document2); | ||
// close tab 2 | ||
await buttonCloseTab.click(); | ||
await expect(documentEditor).toContainText(content.document1); // sanity check tab 1 content unchanged | ||
// close tab 1 | ||
await buttonCloseTab.click(); | ||
// expect a new tab created with default content | ||
await expect(documentEditor).toContainText(content.partialDefault); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { defineConfig, devices } from '@playwright/test'; | ||
|
||
export default defineConfig({ | ||
globalSetup: './playwright.setup', | ||
testDir: './', | ||
fullyParallel: true, | ||
forbidOnly: !!process.env.CI, | ||
retries: process.env.CI ? 2 : 0, | ||
workers: process.env.CI ? 1 : undefined, | ||
reporter: 'html', | ||
use: { | ||
baseURL: 'http://localhost:3000', | ||
trace: 'on-first-retry', | ||
screenshot: 'only-on-failure', | ||
}, | ||
projects: [ | ||
{ | ||
name: 'chromium', | ||
use: { ...devices['Desktop Chrome'] }, | ||
}, | ||
], | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import * as Path from 'node:path'; | ||
import dotenv from 'dotenv'; | ||
|
||
/** | ||
* @see https://playwright.dev/docs/test-configuration#global-setup | ||
*/ | ||
export default async _config => { | ||
const path = process.env.CI | ||
? Path.join(import.meta.dirname, '../integration-tests/.env') | ||
: Path.join(import.meta.dirname, '../packages/services/server/.env.template'); | ||
|
||
dotenv.config({ path }); | ||
|
||
if (!process.env.CI) { | ||
process.env.RUN_AGAINST_LOCAL_SERVICES = '1'; | ||
} | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.