feat: add unit test

This commit is contained in:
amlannandy 2024-12-07 10:40:14 +05:30 committed by Amlan Kumar Nandy
parent b35b975798
commit b499b10333
2 changed files with 83 additions and 58 deletions

View File

@ -521,63 +521,65 @@ function DashboardsList(): JSX.Element {
</div> </div>
{action && ( {action && (
<Popover <div data-testid="dashboard-action-popover">
trigger="click" <Popover
content={ trigger="click"
<div className="dashboard-action-content"> content={
<section className="section-1"> <div className="dashboard-action-content">
<Button <section className="section-1">
type="text" <Button
className="action-btn" type="text"
icon={<Expand size={12} />} className="action-btn"
onClick={onClickHandler} icon={<Expand size={12} />}
> onClick={onClickHandler}
View >
</Button> View
<Button </Button>
type="text" <Button
className="action-btn" type="text"
icon={<Link2 size={12} />} className="action-btn"
onClick={(e): void => { icon={<Link2 size={12} />}
e.stopPropagation(); onClick={(e): void => {
e.preventDefault(); e.stopPropagation();
setCopy(`${window.location.origin}${getLink()}`); e.preventDefault();
}} setCopy(`${window.location.origin}${getLink()}`);
> }}
Copy Link >
</Button> Copy Link
<Button </Button>
type="text" <Button
className="action-btn" type="text"
icon={<FileJson size={12} />} className="action-btn"
onClick={handleJsonExport} icon={<FileJson size={12} />}
> onClick={handleJsonExport}
Export JSON >
</Button> Export JSON
</section> </Button>
<section className="section-2"> </section>
<DeleteButton <section className="section-2">
name={dashboard.name} <DeleteButton
id={dashboard.id} name={dashboard.name}
isLocked={dashboard.isLocked} id={dashboard.id}
createdBy={dashboard.createdBy} isLocked={dashboard.isLocked}
/> createdBy={dashboard.createdBy}
</section> />
</div> </section>
} </div>
placement="bottomRight" }
arrow={false} placement="bottomRight"
rootClassName="dashboard-actions" arrow={false}
> rootClassName="dashboard-actions"
<EllipsisVertical >
className="dashboard-action-icon" <EllipsisVertical
size={14} className="dashboard-action-icon"
onClick={(e): void => { size={14}
e.stopPropagation(); onClick={(e): void => {
e.preventDefault(); e.stopPropagation();
}} e.preventDefault();
/> }}
</Popover> />
</Popover>
</div>
)} )}
</div> </div>
<div className="dashboard-details"> <div className="dashboard-details">

View File

@ -1,7 +1,10 @@
/* eslint-disable sonarjs/no-duplicate-string */ /* eslint-disable sonarjs/no-duplicate-string */
import ROUTES from 'constants/routes'; import ROUTES from 'constants/routes';
import DashboardsList from 'container/ListOfDashboard'; import DashboardsList from 'container/ListOfDashboard';
import { dashboardEmptyState } from 'mocks-server/__mockdata__/dashboards'; import {
dashboardEmptyState,
dashboardSuccessResponse,
} from 'mocks-server/__mockdata__/dashboards';
import { server } from 'mocks-server/server'; import { server } from 'mocks-server/server';
import { rest } from 'msw'; import { rest } from 'msw';
import { DashboardProvider } from 'providers/Dashboard/Dashboard'; import { DashboardProvider } from 'providers/Dashboard/Dashboard';
@ -204,4 +207,24 @@ describe('dashboard list page', () => {
), ),
); );
}); });
it('ensure that the popover actions on each list item renders list of options', async () => {
const { getByText, getAllByTestId } = render(
<MemoryRouter initialEntries={['/dashbords']}>
<DashboardProvider>
<DashboardsList />
</DashboardProvider>
</MemoryRouter>,
);
await waitFor(() => {
const popovers = getAllByTestId('dashboard-action-popover');
expect(popovers).toHaveLength(dashboardSuccessResponse.data.length);
fireEvent.click([...popovers[0].children][0]);
});
expect(getByText('View')).toBeInTheDocument();
expect(getByText('Copy Link')).toBeInTheDocument();
expect(getByText('Export JSON')).toBeInTheDocument();
});
}); });