-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(collapse): add PO, e2e tests and au-collapse class (#1069)
- Loading branch information
Showing
7 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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,31 @@ | ||
import {CollapsePO} from '@agnos-ui/page-objects'; | ||
import {expect, test} from '../fixture'; | ||
import {CollapseDemoPO} from '../demo-po/collapse.po'; | ||
import {assign} from 'common/utils'; | ||
import type {PromiseValue} from 'e2e/utils'; | ||
|
||
type State = PromiseValue<ReturnType<CollapsePO['state']>>; | ||
|
||
test.describe(`Collapse tests`, () => { | ||
test(`Default collapse`, async ({page}) => { | ||
const collapseDemoPO = new CollapseDemoPO(page); | ||
const collapsePO = new CollapsePO(page, 0); | ||
|
||
await page.goto('#/collapse/default'); | ||
await collapseDemoPO.locatorRoot.waitFor(); | ||
|
||
const expectedState: State = { | ||
rootClasses: ['au-collapse', 'collapse', 'show'], | ||
}; | ||
expect(await collapsePO.state()).toStrictEqual(expectedState); | ||
|
||
await collapseDemoPO.locatorToggleCollapseButton.click(); | ||
await collapsePO.locatorRoot.waitFor({state: 'hidden'}); | ||
|
||
expect(await collapsePO.state()).toStrictEqual( | ||
assign(expectedState, { | ||
rootClasses: ['au-collapse', 'collapse'], | ||
}), | ||
); | ||
}); | ||
}); |
This file contains 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,20 @@ | ||
import {BasePO} from '@agnos-ui/base-po'; | ||
import type {Locator} from '@playwright/test'; | ||
|
||
export class CollapseDemoPO extends BasePO { | ||
override getComponentSelector(): string { | ||
return '.container'; | ||
} | ||
|
||
get locatorToggleCollapseButton(): Locator { | ||
return this.locatorRoot.getByRole('button', {name: /toggle/i}); | ||
} | ||
|
||
async defaultCollapseDemoState() { | ||
return await this.locatorRoot.evaluate((rootNode: HTMLElement) => { | ||
return { | ||
page: +rootNode.querySelector('#defaultPage')!.textContent!, | ||
}; | ||
}); | ||
} | ||
} |
This file contains 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 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 |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
id="root" | ||
> | ||
<div | ||
class="collapse show" | ||
class="au-collapse collapse show" | ||
> | ||
"Visible content" | ||
</div> | ||
|
This file contains 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,21 @@ | ||
import {BasePO} from '@agnos-ui/base-po'; | ||
|
||
export const collapseSelectors = { | ||
rootComponent: '.au-collapse', | ||
}; | ||
|
||
export class CollapsePO extends BasePO { | ||
selectors = structuredClone(collapseSelectors); | ||
|
||
override getComponentSelector(): string { | ||
return this.selectors.rootComponent; | ||
} | ||
|
||
async state() { | ||
return this.locatorRoot.evaluate((rootNode: HTMLElement, _selectors) => { | ||
return { | ||
rootClasses: rootNode.className.trim().split(' ').sort(), | ||
}; | ||
}, this.selectors); | ||
} | ||
} |
This file contains 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