-
-
Notifications
You must be signed in to change notification settings - Fork 287
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
Be more accepting of select options #1604
Changes from 3 commits
642b2fe
daad6be
6a157ba
6bd8f68
ffbb0aa
258024f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,34 @@ | ||
import * as path from 'path'; | ||
import { ToolpadEditor } from '../../models/ToolpadEditor'; | ||
import { ToolpadRuntime } from '../../models/ToolpadRuntime'; | ||
import { FrameLocator, Page, test } from '../../playwright/test'; | ||
import { FrameLocator, Page, test, expect } from '../../playwright/test'; | ||
import clickCenter from '../../utils/clickCenter'; | ||
import { readJsonFile } from '../../utils/fs'; | ||
import generateId from '../../utils/generateId'; | ||
|
||
async function waitForComponents(page: Page | FrameLocator) { | ||
await page.locator('text="foo button"').waitFor({ state: 'visible' }); | ||
await page.locator('img[alt="foo image"]').waitFor({ state: 'attached' }); | ||
await page.locator('text="foo datagrid column"').waitFor({ state: 'visible' }); | ||
await page.locator('text="custom component 1"').waitFor({ state: 'visible' }); | ||
await page.locator('label:has-text("foo textfield")').waitFor({ state: 'visible' }); | ||
await page.locator('text="foo typography"').waitFor({ state: 'visible' }); | ||
await page.locator('label:has-text("foo select")').waitFor({ state: 'visible' }); | ||
async function waitForComponents(page: Page, frame: Page | FrameLocator = page, isEditor = false) { | ||
await frame.locator('text="foo button"').waitFor({ state: 'visible' }); | ||
await frame.locator('img[alt="foo image"]').waitFor({ state: 'attached' }); | ||
await frame.locator('text="foo datagrid column"').waitFor({ state: 'visible' }); | ||
await frame.locator('text="custom component 1"').waitFor({ state: 'visible' }); | ||
await frame.locator('label:has-text("foo textfield")').waitFor({ state: 'visible' }); | ||
await frame.locator('text="foo typography"').waitFor({ state: 'visible' }); | ||
await frame.locator('label:has-text("foo select")').waitFor({ state: 'visible' }); | ||
|
||
const optionsSelect = frame.getByRole('button', { name: /select with options/ }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this more specific testing for the Select be in its own test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe, I'm sort of avoiding splitting tests too much as to keep the footprint down. The whole test with setup and page load takes about 2/3 seconds. While just interacting with this select takes an order of magnitude less. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah that's right, with a page load in every test things can get a lot slower... |
||
await optionsSelect.scrollIntoViewIfNeeded(); | ||
if (isEditor) { | ||
await clickCenter(page, optionsSelect); | ||
} | ||
await clickCenter(page, optionsSelect); | ||
await expect(frame.getByRole('option', { name: 'one' })).toBeVisible(); | ||
await expect(frame.getByRole('option', { name: '2' })).toBeVisible(); | ||
await expect(frame.getByRole('option', { name: 'three' })).toBeVisible(); | ||
await expect(frame.getByRole('option', { name: '4' })).toBeVisible(); | ||
await expect(frame.getByRole('option', { name: 'undefined' })).toBeVisible(); | ||
} | ||
|
||
test('components', async ({ page, browserName, api }) => { | ||
test('components runtime', async ({ page, api }) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be helpful for the test names to be more descriptive of what's being tested, like for example |
||
const dom = await readJsonFile(path.resolve(__dirname, './componentsDom.json')); | ||
|
||
const app = await api.mutation.createApp(`App ${generateId()}`, { | ||
|
@@ -26,9 +39,17 @@ test('components', async ({ page, browserName, api }) => { | |
await runtimeModel.gotoPage(app.id, 'components'); | ||
|
||
await waitForComponents(page); | ||
}); | ||
|
||
test('components editor', async ({ page, browserName, api }) => { | ||
const dom = await readJsonFile(path.resolve(__dirname, './componentsDom.json')); | ||
|
||
const app = await api.mutation.createApp(`App ${generateId()}`, { | ||
from: { kind: 'dom', dom }, | ||
}); | ||
|
||
const editorModel = new ToolpadEditor(page, browserName); | ||
editorModel.goto(app.id); | ||
|
||
await waitForComponents(editorModel.appCanvas); | ||
await waitForComponents(page, editorModel.appCanvas, true); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also thinking if it would be useful to have comments clarifying which component is being checked in each of these lines? The selector might not always be explicit enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll assign those locators to variables with more descriptive names. That makes it self-documenting.