Skip to content

Commit

Permalink
chore: added tests for pipeline list view action, expand content dele…
Browse files Browse the repository at this point in the history
…te and toggle action
  • Loading branch information
SagarRajput-7 committed Apr 30, 2024
1 parent 66131b3 commit 7acaf2c
Showing 1 changed file with 65 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render } from '@testing-library/react';
import { render, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { I18nextProvider } from 'react-i18next';
import { Provider } from 'react-redux';
Expand Down Expand Up @@ -83,4 +83,68 @@ describe('PipelinePage container test', () => {
expect(getByText('grok use common asd')).toBeInTheDocument();
expect(getByText('rename auth')).toBeInTheDocument();
});

it('should be able to perform actions and edit on expanded view content', async () => {
render(
<MemoryRouter>
<Provider store={store}>
<I18nextProvider i18n={i18n}>
<PipelineListsView
setActionType={jest.fn()}
isActionMode="editing-mode"
setActionMode={jest.fn()}
pipelineData={pipelineApiResponseMockData}
isActionType=""
refetchPipelineLists={jest.fn()}
/>
</I18nextProvider>
</Provider>
</MemoryRouter>,
);

// content assertion
expect(document.querySelectorAll('[data-icon="edit"]').length).toBe(2);

// expand action
const expandIcon = document.querySelectorAll(
'.ant-table-row-expand-icon-cell > span[class*="anticon-right"]',
);
expect(expandIcon.length).toBe(2);
await userEvent.click(expandIcon[0]);

const switchToggle = document.querySelector(
'.ant-table-expanded-row .ant-switch',
);

expect(switchToggle).toBeChecked();
await userEvent.click(switchToggle as HTMLElement);
expect(switchToggle).not.toBeChecked();

const deleteBtns = document.querySelectorAll(
'.ant-table-expanded-row [data-icon="delete"]',
);

expect(deleteBtns.length).toBe(2);

// delete pipeline
await userEvent.click(deleteBtns[0] as HTMLElement);

let deleteConfirmationModal;

await waitFor(async () => {
deleteConfirmationModal = document.querySelector('.ant-modal-wrap');
expect(deleteConfirmationModal).toBeInTheDocument();
});

await userEvent.click(
((deleteConfirmationModal as unknown) as HTMLElement)?.querySelector(
'.ant-modal-confirm-btns .ant-btn-primary',
) as HTMLElement,
);

expect(
document.querySelectorAll('.ant-table-expanded-row [data-icon="delete"]')
.length,
).toBe(1);
});
});

0 comments on commit 7acaf2c

Please sign in to comment.