-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import {Page} from '@playwright/test'; | ||
import {HoistPage} from './HoistPage'; | ||
import {PlainObject} from '@xh/hoist/core'; | ||
|
||
export class GridHelper { | ||
readonly hoistPage: HoistPage; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
readonly testId: string; | ||
|
||
constructor(hoistPage: HoistPage, testId: string) { | ||
This comment has been minimized.
Sorry, something went wrong.
ghsolomon
Contributor
|
||
this.hoistPage = hoistPage; | ||
this.testId = testId; | ||
} | ||
|
||
get page(): Page { | ||
return this.hoistPage.page; | ||
} | ||
|
||
async getRecordCount() { | ||
return this.page.evaluate(testId => { | ||
return window.XH.getActiveModelByTestId(testId).store.count; | ||
This comment has been minimized.
Sorry, something went wrong.
ghsolomon
Contributor
|
||
}, this.testId); | ||
} | ||
|
||
async ensureCount(count: number) { | ||
const gridCount = await this.getRecordCount(); | ||
if (gridCount !== count) | ||
throw new Error(`Found ${gridCount} records when ${count} is expected`); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
|
||
async getRowData(recordIdQuery: RecordIdQuery) { | ||
This comment has been minimized.
Sorry, something went wrong.
ghsolomon
Contributor
|
||
if ('id' in recordIdQuery) { | ||
return this.page.evaluate( | ||
([testId, id]) => window.XH.getActiveModelByTestId(testId).store.getById(id).data, | ||
[this.testId, recordIdQuery.id] | ||
); | ||
} else { | ||
return this.page.evaluate( | ||
([testId, agId]) => | ||
window.XH.getActiveModelByTestId(testId).store.allRecords.find( | ||
it => it.agId === agId | ||
).id, | ||
This comment has been minimized.
Sorry, something went wrong. |
||
[this.testId, recordIdQuery.agId] | ||
); | ||
} | ||
} | ||
|
||
async getRowAgId(query: RecordQuery) { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
if ('agId' in query) return query.agId; | ||
return 'id' in query | ||
? this.page.evaluate( | ||
([testId, id]) => window.XH.getActiveModelByTestId(testId).getById(id).agId, | ||
[this.testId, query.id] | ||
) | ||
: this.page.evaluate( | ||
([testId, recordData]) => | ||
window.XH.getActiveModelByTestId(testId).store.allRecords.find(({data}) => | ||
_.isMatch(data, recordData) | ||
).agId, | ||
[this.testId, query.recordData] as const | ||
); | ||
} | ||
|
||
async getRowId(query: RecordQuery) { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
if ('id' in query) return query.id; | ||
return 'agId' in query | ||
? this.page.evaluate( | ||
([testId, agId]) => | ||
window.XH.getActiveModelByTestId(testId).store.allRecords.find( | ||
it => it.agId === agId | ||
).id, | ||
[this.testId, query.agId] | ||
) | ||
: this.page.evaluate( | ||
([testId, recordData]) => | ||
window.XH.getActiveModelByTestId(testId).store.allRecords.find(({data}) => | ||
_.isMatch(data, recordData) | ||
).id, | ||
[this.testId, query.recordData] as const | ||
); | ||
} | ||
|
||
// select row with GridModel | ||
async selectRow(query: RecordQuery) { | ||
const id = await this.getRowId(query); | ||
this.page.evaluate( | ||
([testId, id]) => { | ||
const gridModel = window.XH.getActiveModelByTestId(testId), | ||
record = gridModel.store.getById(id); | ||
gridModel.selectAsync(record); | ||
}, | ||
[this.testId, id] | ||
); | ||
} | ||
|
||
// Functions to click / double click on grid row | ||
async clickRow(query: RecordQuery) { | ||
const agId = await this.getRowAgId(query); | ||
await this.page.getByTestId(this.testId).locator(`div[row-id="${agId}"]`).click(); | ||
} | ||
|
||
async dblClickRow(query: RecordQuery) { | ||
const agId = await this.getRowAgId(query); | ||
await this.page.getByTestId(this.testId).locator(`div[row-id="${agId}"]`).dblclick(); | ||
} | ||
} | ||
|
||
type RecordQuery = IdQuery | AgIdQuery | RecordDataQuery; | ||
This comment has been minimized.
Sorry, something went wrong.
ghsolomon
Contributor
|
||
type RecordIdQuery = IdQuery | AgIdQuery; | ||
|
||
interface IdQuery { | ||
id: string | number; | ||
} | ||
|
||
interface AgIdQuery { | ||
agId: string; | ||
} | ||
|
||
interface RecordDataQuery { | ||
recordData: PlainObject; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import {AppModel} from '../../client-app/src/desktop/AppModel'; | |
import {XHApi} from '@xh/hoist/core/XH'; | ||
import {StoreRecordId} from '@xh/hoist/data/StoreRecord'; | ||
import {PlainObject} from '@xh/hoist/core'; | ||
import { GridHelper } from './GridHelper'; | ||
|
||
export interface FilterSelectQuery { | ||
testId: string; | ||
|
@@ -33,16 +34,20 @@ export class HoistPage { | |
await this.waitForAppToBeRunning(); | ||
} | ||
|
||
getGridHelper(testId: string): GridHelper{ | ||
This comment has been minimized.
Sorry, something went wrong.
ghsolomon
Contributor
|
||
return new GridHelper(this, testId) | ||
} | ||
|
||
get(testId: string) { | ||
return this.page.getByTestId(testId); | ||
} | ||
|
||
async click(testId: string) { | ||
await this.get(testId).click(); | ||
getByText(text: string) { | ||
return this.page.getByText(text) | ||
} | ||
|
||
async expectText(testId: string, text: string) { | ||
await expect(this.get(testId)).toHaveText(text); | ||
async click(testId: string) { | ||
await this.get(testId).click(); | ||
} | ||
|
||
async fill(testId: string, value: string) { | ||
|
@@ -98,20 +103,6 @@ export class HoistPage { | |
await this.page.locator('label', {has: this.page.getByTestId(testId)}).uncheck(); | ||
} | ||
|
||
async getGridRowByRecordId(testId: string, id: StoreRecordId) { | ||
return this.page.evaluate(() => | ||
window.XH.getActiveModelByTestId(testId).gridModel.store.getById(id) | ||
); | ||
} | ||
|
||
async getGridRowByCellContents(testId: string, spec: PlainObject) { | ||
return this.page.evaluate(() => { | ||
window.XH.getActiveModelByTestId(testId).gridModel.store.allRecords.find(({data}) => | ||
_.isMatch(data, spec) | ||
); | ||
}); | ||
} | ||
|
||
onConsoleError(msg: ConsoleMessage) { | ||
throw new Error(msg.text()); | ||
} | ||
|
@@ -133,6 +124,16 @@ export class HoistPage { | |
await expect(this.maskLocator).toHaveCount(0, {timeout: 10000}); | ||
} | ||
|
||
//Expect | ||
async expectText(testId: string, text: string) { | ||
await expect(this.get(testId)).toHaveText(text); | ||
} | ||
|
||
async expectTextVisible(text: string) { | ||
await expect(this.getByText(text)).toBeVisible({timeout: 10000}) | ||
} | ||
|
||
|
||
//------------------------ | ||
// Implementation | ||
//------------------------ | ||
|
1 comment
on commit 1667998
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.
Looking good overall I think!
Wonder if these should be private?