Skip to content

Commit

Permalink
test(Table): visual tests for withTableSelection hoc (#1406)
Browse files Browse the repository at this point in the history
Co-authored-by: German Vorotnikov <[email protected]>
  • Loading branch information
GermanVor and German Vorotnikov authored Mar 6, 2024
1 parent 6cae52d commit 96b9365
Show file tree
Hide file tree
Showing 17 changed files with 56 additions and 9 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 1 addition & 4 deletions src/components/Table/__stories__/Table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ import type {DataItem} from './utils';
export default {
title: 'Components/Data Display/Table',
component: Table,
args: {
columns,
data,
},
args: {columns, data},
} as Meta<TableProps<DataItem>>;

const DefaultTemplate: StoryFn<TableProps<DataItem>> = (args) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';

import {withTableSelection} from '../hoc';

import {HOCWithTableSelection} from './helpersPlaywright';

import {test} from '~playwright/core';

test.describe('Table.withTableSelection', () => {
test('render story: <Default>', async ({mount, expectScreenshot}) => {
await mount(<HOCWithTableSelection />);

await expectScreenshot();
});

test('render story: <With selection>', async ({mount, expectScreenshot}) => {
const root = await mount(<HOCWithTableSelection />);
const fisrtRowCheckbox = root.getByTestId(withTableSelection.getCheckboxQa('0'));

await fisrtRowCheckbox.click();

await expectScreenshot();
});

test('render story: <With selection all>', async ({mount, expectScreenshot}) => {
const root = await mount(<HOCWithTableSelection />);
const fisrtRowCheckbox = root.getByTestId(withTableSelection.headerCheckboxQa);

await fisrtRowCheckbox.click();

await expectScreenshot();
});
});
5 changes: 5 additions & 0 deletions src/components/Table/__tests__/helpersPlaywright.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {composeStories} from '@storybook/react';

import * as TableStories from '../__stories__/Table.stories';

export const {HOCWithTableSelection} = composeStories(TableStories);
20 changes: 16 additions & 4 deletions src/components/Table/hoc/withTableSelection/withTableSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,29 +73,37 @@ export function withTableSelection<I extends TableDataItem, E extends {} = {}>(
checked = false;
}

return this.renderCheckBox({disabled, checked, handler: this.handleAllCheckBoxUpdate});
return this.renderCheckBox({
disabled,
checked,
handler: this.handleAllCheckBoxUpdate,
qa: withTableSelection.headerCheckboxQa,
});
};

private renderBodyCell = (item: I, index: number) => {
const {selectedIds} = this.props;
const id = Table.getRowId(this.props, item, index);
const checked = selectedIds.includes(id);
const rowId = Table.getRowId(this.props, item, index);
const checked = selectedIds.includes(rowId);

return this.renderCheckBox({
disabled: this.isDisabled(item, index),
checked,
handler: this.handleCheckBoxUpdate.bind(this, id, index),
handler: this.handleCheckBoxUpdate.bind(this, rowId, index),
qa: withTableSelection.getCheckboxQa(rowId),
});
};

private renderCheckBox({
disabled,
checked,
handler,
qa,
}: {
checked: boolean;
disabled: boolean;
handler: React.ChangeEventHandler<HTMLInputElement>;
qa: string;
}) {
return (
<Checkbox
Expand All @@ -106,6 +114,7 @@ export function withTableSelection<I extends TableDataItem, E extends {} = {}>(
className={b('selection-checkbox', {
'vertical-align': this.props.verticalAlign,
})}
qa={qa}
/>
);
}
Expand Down Expand Up @@ -237,3 +246,6 @@ export function withTableSelection<I extends TableDataItem, E extends {} = {}>(
};
};
}

withTableSelection.headerCheckboxQa = 'headerCheckboxQa';
withTableSelection.getCheckboxQa = (id: string) => `CheckboxQa_${id}`;
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export function withTableSorting<I extends TableDataItem, E extends {} = {}>(
</div>,
<div key="spacer" className={b('sort-spacer')} />,
<div key="indicator" className={b('sort-indicator')}>
<SortIndicator
<TableSortIndicator
order={sortOrder || this.getColumnDefaultSortOrder(column)}
/>
</div>,
Expand Down

0 comments on commit 96b9365

Please sign in to comment.