Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DaryaLari committed Dec 9, 2024
1 parent a68bb89 commit 0c51d2f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 93 deletions.
8 changes: 2 additions & 6 deletions src/shared/constants/qa/dash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,10 @@ export enum DashCommonQa {
}

export enum FixedHeaderQa {
ExpandCollapseFixedHeaderButton = 'expand-collapse-fixed-header-button',
StaticFixedHeaderGroupWrapper = 'static-fixed-header-group-wrapper',
StaticFixedHeaderGroupContent = 'static-fixed-header-group-content',
HidableFixedHeaderGroupWrapper = 'hidable-fixed-header-group-wrapper',
HidableFixedHeaderGroupContent = 'hidable-fixed-header-group-content',

Wrapper = 'dash-fixed-header-wrapper',
Container = 'dash-fixed-header-containter',
Controls = 'dash-fixed-header-controls',
ExpandCollapseButton = 'dash-fixed-header-expand-collapse-button',
}

export enum DashRelationTypes {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/units/dash/containers/Body/Body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ class Body extends React.PureComponent<BodyProps> {
'dash.main.view',
isCollapsed ? 'tooltip_expand-fixed-group' : 'tooltip_collapse-fixed-group',
)}
qa={FixedHeaderQa.ExpandCollapseFixedHeaderButton}
qa={FixedHeaderQa.ExpandCollapseButton}
>
<Icon data={isCollapsed ? ArrowChevronDown : ArrowChevronUp} />
</Button>
Expand Down
1 change: 1 addition & 0 deletions src/ui/units/dash/containers/FixedHeader/FixedHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ export function FixedHeaderWrapper({
})}
style={style}
ref={wrapperRef}
data-qa={FixedHeaderQa.Wrapper}
>
<div className={b('content')}>
<div className={b('scrollable-container')}>
Expand Down
77 changes: 26 additions & 51 deletions tests/opensource-suites/dash/base/fixedHeader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,43 +28,29 @@ datalensTest.describe('Fixed header', () => {
const collapsibleStateToggleButton = fixedHeader.expandCollapseButton;

await expect(collapsibleStateToggleButton).toBeVisible();
await expect(fixedHeader.staticFixedHeaderGroupContent).toBeVisible();
await expect(fixedHeader.hidableFixedHeaderGroupContent).toBeVisible();

const initialStaticFixedHeaderGroupVerticalOffset =
await fixedHeader.getStaticFixedHeaderGroupVerticalOffset();
await expect(fixedHeader.controls).toBeVisible();
await expect(fixedHeader.container).toBeVisible();

// check that "fixed" header is not fixed without scrolling
expect(initialStaticFixedHeaderGroupVerticalOffset).toBeGreaterThan(actionPanelHeight);
expect(await fixedHeader.getHidableFixedHeaderGroupVerticalOffset()).toBeGreaterThan(
initialStaticFixedHeaderGroupVerticalOffset + actionPanelHeight,
);
expect(await fixedHeader.getWrapperVerticalOffset()).toBeGreaterThan(actionPanelHeight);

await fixedHeader.toggleFixedHeaderCollapsibleState(); // collapse

await expect(collapsibleStateToggleButton).toBeVisible();
await expect(fixedHeader.staticFixedHeaderGroupContent).toBeVisible();
await expect(fixedHeader.hidableFixedHeaderGroupContent).toBeHidden();
await expect(fixedHeader.controls).toBeVisible();
await expect(fixedHeader.container).toBeHidden();

await page.mouse.wheel(0, 500);

await expect(collapsibleStateToggleButton).toBeVisible();
await expect(fixedHeader.staticFixedHeaderGroupContent).toBeVisible();
await expect(fixedHeader.hidableFixedHeaderGroupContent).toBeHidden();
await expect(fixedHeader.controls).toBeVisible();
await expect(fixedHeader.container).toBeHidden();

expect(await fixedHeader.getStaticFixedHeaderGroupVerticalOffset()).toEqual(
actionPanelHeight,
);
expect(await fixedHeader.getWrapperVerticalOffset()).toEqual(actionPanelHeight);

await fixedHeader.toggleFixedHeaderCollapsibleState(); // expand

await expect(fixedHeader.hidableFixedHeaderGroupContent).toBeVisible();

const staticFixedHeaderHeight =
(await fixedHeader.staticFixedHeaderGroupWrapper.boundingBox())?.height ?? 0;
expect(await fixedHeader.getHidableFixedHeaderGroupVerticalOffset()).toEqual(
actionPanelHeight + staticFixedHeaderHeight,
);
await expect(fixedHeader.container).toBeVisible();
});

datalensTest('With second group only', async ({page}: {page: Page}) => {
Expand All @@ -78,34 +64,29 @@ datalensTest.describe('Fixed header', () => {
const collapsibleStateToggleButton = fixedHeader.expandCollapseButton;

await expect(collapsibleStateToggleButton).toBeVisible();
await expect(fixedHeader.staticFixedHeaderGroupContent).toBeHidden();
await expect(fixedHeader.hidableFixedHeaderGroupContent).toBeVisible();

const initialStaticHidableHeaderGroupVerticalOffset =
await fixedHeader.getHidableFixedHeaderGroupVerticalOffset();
await expect(fixedHeader.controls).toBeHidden();
await expect(fixedHeader.container).toBeVisible();

// check that "fixed" header is not fixed without scrolling
expect(initialStaticHidableHeaderGroupVerticalOffset).toBeGreaterThan(actionPanelHeight);
expect(await fixedHeader.getWrapperVerticalOffset()).toBeGreaterThan(actionPanelHeight);

await fixedHeader.toggleFixedHeaderCollapsibleState(); // collapse

await expect(collapsibleStateToggleButton).toBeVisible();
await expect(fixedHeader.staticFixedHeaderGroupContent).toBeHidden();
await expect(fixedHeader.hidableFixedHeaderGroupContent).toBeHidden();
await expect(fixedHeader.controls).toBeHidden();
await expect(fixedHeader.container).toBeHidden();

await page.mouse.wheel(0, 500);

await expect(collapsibleStateToggleButton).toBeVisible();
await expect(fixedHeader.staticFixedHeaderGroupContent).toBeHidden();
await expect(fixedHeader.hidableFixedHeaderGroupContent).toBeHidden();
await expect(fixedHeader.controls).toBeHidden();
await expect(fixedHeader.container).toBeHidden();

await fixedHeader.toggleFixedHeaderCollapsibleState(); // expand

await expect(fixedHeader.hidableFixedHeaderGroupContent).toBeVisible();
await expect(fixedHeader.container).toBeVisible();

expect(await fixedHeader.getHidableFixedHeaderGroupVerticalOffset()).toEqual(
actionPanelHeight,
);
expect(await fixedHeader.getWrapperVerticalOffset()).toEqual(actionPanelHeight);
});
datalensTest('Header with overflown second group', async ({page}: {page: Page}) => {
await openTestPage(page, getTabUrl(tabsIds.overflownSecondGroup));
Expand All @@ -118,39 +99,33 @@ datalensTest.describe('Fixed header', () => {
const collapsibleStateToggleButton = fixedHeader.expandCollapseButton;

await expect(collapsibleStateToggleButton).toBeVisible();
await expect(fixedHeader.staticFixedHeaderGroupContent).toBeVisible();
await expect(fixedHeader.hidableFixedHeaderGroupContent).toBeVisible();
await expect(fixedHeader.controls).toBeVisible();
await expect(fixedHeader.container).toBeVisible();

const body = page.locator('body');

const initialStaticFixedHeaderGroupVerticalOffset =
await fixedHeader.getStaticFixedHeaderGroupVerticalOffset();

// check that "fixed" header is not fixed without scrolling
expect(initialStaticFixedHeaderGroupVerticalOffset).toBeGreaterThan(actionPanelHeight);
expect(await fixedHeader.getHidableFixedHeaderGroupVerticalOffset()).toBeGreaterThan(
initialStaticFixedHeaderGroupVerticalOffset + actionPanelHeight,
);
expect(await fixedHeader.getWrapperVerticalOffset()).toBeGreaterThan(actionPanelHeight);

await page.mouse.wheel(0, 500);

const bodyScrollPositionBeforeCollapsing = (await body.boundingBox())?.y ?? 0;
const fixedHeaderScrollPositionBeforeCollapsing =
(await fixedHeader.hidableFixedHeaderGroupContent.boundingBox())?.y ?? 0;
(await fixedHeader.container.boundingBox())?.y ?? 0;

await fixedHeader.hidableFixedHeaderGroupContent.hover();
await fixedHeader.container.hover();
await page.mouse.wheel(0, 500);

expect((await body.boundingBox())?.y).toEqual(bodyScrollPositionBeforeCollapsing);
expect((await fixedHeader.hidableFixedHeaderGroupContent.boundingBox())?.y).toEqual(
expect((await fixedHeader.container.boundingBox())?.y).toEqual(
fixedHeaderScrollPositionBeforeCollapsing - 500,
);

await fixedHeader.toggleFixedHeaderCollapsibleState(); // collapse

await expect(collapsibleStateToggleButton).toBeVisible();
await expect(fixedHeader.staticFixedHeaderGroupContent).toBeVisible();
await expect(fixedHeader.hidableFixedHeaderGroupContent).toBeHidden();
await expect(fixedHeader.controls).toBeVisible();
await expect(fixedHeader.container).toBeHidden();

await page.mouse.wheel(0, 500);
expect((await body.boundingBox())?.y).toEqual(bodyScrollPositionBeforeCollapsing - 500);
Expand Down
45 changes: 10 additions & 35 deletions tests/page-objects/dashboard/FixedHeader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import {FixedHeaderQa} from '../../../src/shared';

export class FixedHeader {
static selectors = {
expandCollapseButton: slct(FixedHeaderQa.ExpandCollapseFixedHeaderButton),
staticFixedHeaderGroupWrapper: slct(FixedHeaderQa.StaticFixedHeaderGroupWrapper),
staticFixedHeaderGroupContent: slct(FixedHeaderQa.StaticFixedHeaderGroupContent),
hidableFixedHeaderGroupWrapper: slct(FixedHeaderQa.HidableFixedHeaderGroupWrapper),
hidableFixedHeaderGroupContent: slct(FixedHeaderQa.HidableFixedHeaderGroupContent),
expandCollapseButton: slct(FixedHeaderQa.ExpandCollapseButton),
wrapper: slct(FixedHeaderQa.Wrapper),
controls: slct(FixedHeaderQa.Controls),
container: slct(FixedHeaderQa.Container),
};

protected page: Page;
Expand All @@ -25,39 +24,15 @@ export class FixedHeader {
return this.page.locator(FixedHeader.selectors.expandCollapseButton).click();
}

get staticFixedHeaderGroupContent() {
return this.page.locator(FixedHeader.selectors.staticFixedHeaderGroupContent);
get controls() {
return this.page.locator(FixedHeader.selectors.controls);
}

get hidableFixedHeaderGroupContent() {
return this.page.locator(FixedHeader.selectors.hidableFixedHeaderGroupContent);
get container() {
return this.page.locator(FixedHeader.selectors.container);
}

get staticFixedHeaderGroupWrapper() {
return this.page.locator(FixedHeader.selectors.staticFixedHeaderGroupWrapper);
}

get hidableFixedHeaderGroupWrapper() {
return this.page.locator(FixedHeader.selectors.hidableFixedHeaderGroupWrapper);
}

async getStaticFixedHeaderGroupVerticalOffset() {
return (
(
await this.page
.locator(FixedHeader.selectors.staticFixedHeaderGroupWrapper)
.boundingBox()
)?.y ?? 0
);
}

async getHidableFixedHeaderGroupVerticalOffset() {
return (
(
await this.page
.locator(FixedHeader.selectors.hidableFixedHeaderGroupWrapper)
.boundingBox()
)?.y ?? 0
);
async getWrapperVerticalOffset() {
return (await this.page.locator(FixedHeader.selectors.wrapper).boundingBox())?.y ?? 0;
}
}

0 comments on commit 0c51d2f

Please sign in to comment.