Skip to content

Commit

Permalink
Add tests, fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
MrFlashAccount committed Dec 23, 2024
1 parent f12fb87 commit 4bcd6fb
Show file tree
Hide file tree
Showing 13 changed files with 593 additions and 320 deletions.
26 changes: 15 additions & 11 deletions app/common/src/detect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,21 @@ export function isOnUnknownBrowser() {

let detectedArchitecture: string | null = null
// Only implemented by Chromium.
// @ts-expect-error This API exists, but no typings exist for it yet.
navigator.userAgentData?.getHighEntropyValues(['architecture']).then((values: unknown) => {
if (
typeof values === 'object' &&
values != null &&
'architecture' in values &&
typeof values.architecture === 'string'
) {
detectedArchitecture = String(values.architecture)
}
})
// navigator is undefined in Node.js, e.g. in integration tests(mock server).
// So we need to check if it is defined before using it.
if (typeof navigator !== 'undefined' && 'userAgentData' in navigator) {
// @ts-expect-error This API exists, but no typings exist for it yet.
navigator.userAgentData.getHighEntropyValues(['architecture']).then((values: unknown) => {
if (
typeof values === 'object' &&
values != null &&
'architecture' in values &&
typeof values.architecture === 'string'
) {
detectedArchitecture = String(values.architecture)
}
})
}

/** Possible processor architectures. */
export enum Architecture {
Expand Down
63 changes: 63 additions & 0 deletions app/gui/integration-test/dashboard/actions/DrivePageActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,27 @@ export default class DrivePageActions<Context> extends PageActions<Context> {
)
}

/**
* Expect the category to be selected.
*/
expectCategory(category: string) {
return this.step(`Expect category '${category}'`, (page) =>
expect(page.getByRole('button', { name: category })).toHaveAttribute('data-selected', 'true'),
)
}

/**
* Expect the category to be not selected.
*/
expectCategoryNotSelected(category: string) {
return this.step(`Expect category '${category}' not selected`, (page) =>
expect(page.getByRole('button', { name: category })).toHaveAttribute(
'data-selected',
'false',
),
)
}

/** Actions specific to the Drive table. */
get driveTable() {
// eslint-disable-next-line @typescript-eslint/no-this-alias
Expand All @@ -145,6 +166,11 @@ export default class DrivePageActions<Context> extends PageActions<Context> {
.getByLabel(TEXT.sortByModificationDate)
.or(page.getByLabel(TEXT.sortByModificationDateDescending))
.or(page.getByLabel(TEXT.stopSortingByModificationDate))

const locatePathColumnHeading = (page: Page) => page.getByTestId('path-column-heading')
const locatePathColumnCell = (page: Page, title: string) =>
page.getByTestId(`path-column-cell-${title.toLowerCase().replace(/\s+/g, '-')}`)

return {
/** Click the column heading for the "name" column to change its sort order. */
clickNameColumnHeading() {
Expand All @@ -158,6 +184,16 @@ export default class DrivePageActions<Context> extends PageActions<Context> {
callback(locateNameColumnHeading(page), context),
)
},
withPathColumnHeading(callback: LocatorCallback<Context>) {
return self.step('Interact with "path" column heading', (page, context) =>
callback(locatePathColumnHeading(page), context),
)
},
withPathColumnCell(title: string, callback: LocatorCallback<Context>) {
return self.step(`Interact with "path" column cell '${title}'`, (page, context) =>
callback(locatePathColumnCell(page, title), context),
)
},
/** Click the column heading for the "modified" column to change its sort order. */
clickModifiedColumnHeading() {
return self.step('Click "modified" column heading', (page) =>
Expand Down Expand Up @@ -206,6 +242,11 @@ export default class DrivePageActions<Context> extends PageActions<Context> {
await callback(locateAssetRows(page), locateNonAssetRows(page), self.context, page)
})
},
withSelectedRows(callback: LocatorCallback<Context>) {
return self.step('Interact with selected drive table rows', async (page, context) => {
await callback(locateAssetRows(page).and(page.locator('[data-selected="true"]')), context)
})
},
/** Drag a row onto another row. */
dragRowToRow(from: number, to: number) {
return self.step(`Drag drive table row #${from} to row #${to}`, async (page) => {
Expand All @@ -227,6 +268,28 @@ export default class DrivePageActions<Context> extends PageActions<Context> {
}),
)
},
expandDirectory(index: number) {
return self.step(`Expand drive table row #${index}`, async (page) => {
const expandButton = locateAssetRows(page)
.nth(index)
.getByTestId('directory-row-expand-button')

await expect(expandButton).toHaveAttribute('aria-label', TEXT.expand)

return expandButton.click()
})
},
collapseDirectory(index: number) {
return self.step(`Collapse drive table row #${index}`, async (page) => {
const collapseButton = locateAssetRows(page)
.nth(index)
.getByTestId('directory-row-expand-button')

await expect(collapseButton).toHaveAttribute('aria-label', TEXT.collapse)

return collapseButton.click()
})
},
/**
* A test assertion to confirm that there is only one row visible, and that row is the
* placeholder row displayed when there are no assets to show.
Expand Down
Loading

0 comments on commit 4bcd6fb

Please sign in to comment.