Skip to content

Commit

Permalink
feat(collapse): add PO, e2e tests and au-collapse class (#1069)
Browse files Browse the repository at this point in the history
  • Loading branch information
ExFlo authored Dec 19, 2024
1 parent 7b19623 commit 9c85fb9
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 2 deletions.
3 changes: 3 additions & 0 deletions core-bootstrap/src/components/collapse/collapse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ export function createCollapse(config?: PropsConfig<CollapseProps>): CollapseWid
attributes: {
id: computed(() => id$() || undefined),
},
classNames: {
'au-collapse': true,
},
})),
),
},
Expand Down
31 changes: 31 additions & 0 deletions e2e/collapse/collapse.e2e-spec.ts
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'],
}),
);
});
});
20 changes: 20 additions & 0 deletions e2e/demo-po/collapse.po.ts
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!,
};
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"Toggle collapse"
</button>
<div
class="collapse show"
class="au-collapse collapse show"
id="rewritten-id-1"
>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
id="root"
>
<div
class="collapse show"
class="au-collapse collapse show"
>
"Visible content"
</div>
Expand Down
21 changes: 21 additions & 0 deletions page-objects/lib/collapse.po.ts
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);
}
}
1 change: 1 addition & 0 deletions page-objects/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './progressbar.po';
export * from './slider.po';
export * from './toast.po';
export * from './tree.po';
export * from './collapse.po';

0 comments on commit 9c85fb9

Please sign in to comment.