Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Fix act errors in DatabaseList test #22970

Merged
merged 1 commit into from
Feb 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ jest.mock('react-redux', () => ({
useSelector: jest.fn(),
}));

jest.mock('src/components/Icons/Icon', () => ({
__esModule: true,
default: ({ fileName, role }) => (
<span role={role ?? 'img'} aria-label={fileName.replace('_', '-')} />
),
StyledIcon: () => <span />,
}));

fetchMock.get(databasesInfoEndpoint, {
permissions: ['can_write'],
});
Expand Down Expand Up @@ -131,35 +139,35 @@ describe('Admin DatabaseList', () => {
await waitForComponentToPaint(wrapper);
});

it('renders', () => {
test('renders', () => {
expect(wrapper.find(DatabaseList)).toExist();
});

it('renders a SubMenu', () => {
test('renders a SubMenu', () => {
expect(wrapper.find(SubMenu)).toExist();
});

it('renders a SubMenu with no tabs', () => {
test('renders a SubMenu with no tabs', () => {
expect(wrapper.find(SubMenu).props().tabs).toBeUndefined();
});

it('renders a DatabaseModal', () => {
test('renders a DatabaseModal', () => {
expect(wrapper.find(DatabaseModal)).toExist();
});

it('renders a ListView', () => {
test('renders a ListView', () => {
expect(wrapper.find(ListView)).toExist();
});

it('fetches Databases', () => {
test('fetches Databases', () => {
const callsD = fetchMock.calls(/database\/\?q/);
expect(callsD).toHaveLength(2);
expect(callsD[0][0]).toMatchInlineSnapshot(
`"http://localhost/api/v1/database/?q=(order_column:changed_on_delta_humanized,order_direction:desc,page:0,page_size:25)"`,
);
});

it('deletes', async () => {
test('deletes', async () => {
act(() => {
wrapper.find('[data-test="database-delete"]').first().props().onClick();
});
Expand Down Expand Up @@ -189,7 +197,7 @@ describe('Admin DatabaseList', () => {
expect(fetchMock.calls(/database\/0/, 'DELETE')).toHaveLength(1);
});

it('filters', async () => {
test('filters', async () => {
const filtersWrapper = wrapper.find(Filters);
act(() => {
filtersWrapper
Expand Down Expand Up @@ -217,7 +225,7 @@ describe('Admin DatabaseList', () => {
);
});

it('should not render dropdown menu button if user is not admin', () => {
test('should not render dropdown menu button if user is not admin', async () => {
userSelectorMock.mockReturnValue({
createdOn: '2021-05-27T18:12:38.952304',
email: 'alpha@gmail.com',
Expand All @@ -240,6 +248,8 @@ describe('Admin DatabaseList', () => {
<DatabaseList />
</Provider>,
);
await waitForComponentToPaint(newWrapper);

expect(newWrapper.find('.dropdown-menu-links')).not.toExist();
});
});