Skip to content

Commit

Permalink
Fix tests again
Browse files Browse the repository at this point in the history
Signed-off-by: Taylor Smock <tsmock@meta.com>
  • Loading branch information
tsmock committed May 16, 2023
1 parent 3af2c03 commit 7f91467
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import '@testing-library/jest-dom';
import userEvent from '@testing-library/user-event';
import { render, screen, act, waitFor } from '@testing-library/react';

import { store } from '../../../store';
Expand All @@ -20,15 +19,14 @@ describe('test if QuestionsAndComments component', () => {
});

it('renders tabs for writing and previewing comments', async () => {
const user = userEvent.setup();
render(
const { user } = renderWithRouter(
<ReduxIntlProviders store={store}>
<PostProjectComment projectId={1} />
</ReduxIntlProviders>,
);
const previewBtn = screen.getByRole('button', { name: /preview/i });
expect(screen.getAllByRole('button').length).toBe(11);
const previewBtn = await screen.findByRole('button', { name: /preview/i }, { timeout: 3000 });
expect(screen.getByRole('button', { name: /write/i })).toBeInTheDocument();
expect(screen.getAllByRole('button')).toHaveLength(11);
expect(previewBtn).toBeInTheDocument();
expect(screen.getByRole('textbox')).toBeInTheDocument();
await user.click(previewBtn);
Expand Down
11 changes: 5 additions & 6 deletions frontend/src/components/taskSelection/tests/taskList.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ describe('Task Item', () => {
});

it('should copy task URL to the clipboard', async () => {
const originalClipboard = { ...global.navigator.clipboard };
const mockClipboard = {
writeText: jest.fn().mockImplementation(() => Promise.resolve()),
};
global.navigator.clipboard = mockClipboard;
const { user } = createComponentWithMemoryRouter(
<IntlProviders>
<TaskItem data={task} selectTask={jest.fn()} />
Expand All @@ -61,13 +56,17 @@ describe('Task Item', () => {
route: '/projects/6/tasks',
},
);
Object.defineProperty(navigator, 'clipboard', {
value: {
writeText: jest.fn().mockImplementation(() => Promise.resolve()),
},
});
await user.click(screen.getAllByRole('button')[2]);
expect(navigator.clipboard.writeText).toHaveBeenCalledTimes(1);
expect(navigator.clipboard.writeText).toHaveBeenCalledWith(
`${window.location.origin}/projects/6/tasks?search=8`,
);
jest.resetAllMocks();
global.navigator.clipboard = originalClipboard;
});

it('should display task detail modal', async () => {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/views/tests/fallback.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ describe('Fallback component', () => {
const returnBtn = screen.getByRole('button', {
name: messages.return.defaultMessage,
});
expect(returnBtn).toBeInTheDocument();
await user.click(returnBtn);
await waitFor(() => expect(mockedUsedNavigate).toHaveBeenCalledTimes(1));
});
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/tests/organisationManagement.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,12 @@ describe('EditCampaign', () => {
});

it('should copy the organization URL to clipboard', async () => {
const { user } = setup();
Object.defineProperty(navigator, 'clipboard', {
value: {
writeText: jest.fn().mockImplementation(() => Promise.resolve()),
},
});
const { user } = setup();
await waitFor(() => expect(screen.getByText('Manage organization')).toBeInTheDocument());
await user.click(screen.getAllByRole('button')[2]);
expect(navigator.clipboard.writeText).toHaveBeenCalledTimes(1);
Expand Down
6 changes: 2 additions & 4 deletions frontend/src/views/tests/project.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,8 @@ describe('Project Detail Page', () => {
<ProjectDetailPage id={123} navigate={() => jest.fn()} />
</ReduxIntlProviders>,
);
await waitFor(() => {
expect(screen.getByText(/sample project/i)).toBeInTheDocument();
expect(screen.getByText(/hello world/i)).toBeInTheDocument();
});
expect(await screen.findByText(/sample project/i)).toBeInTheDocument();
expect(await screen.findByText(/hello world/i)).toBeInTheDocument();
});

it('should display private project error message', async () => {
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/views/tests/taskSelection.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import '@testing-library/jest-dom';
import { render, screen, act } from '@testing-library/react';
import { render, screen, act, waitFor } from '@testing-library/react';
import { ReactRouter6Adapter } from 'use-query-params/adapters/react-router-6';
import { QueryParamProvider } from 'use-query-params';
import { MemoryRouter, Route, Routes } from 'react-router-dom';
Expand Down Expand Up @@ -84,6 +84,7 @@ describe('Task Selection Page', () => {
});
});
setup();
await waitFor(() => expect(screen.getByRole('link')).toBeInTheDocument());
const taskItems = await screen.findAllByText(/last updated by/i);
expect(taskItems.length).toBe(6);
expect(screen.queryByText(/Project Specific Mapping Notes/i)).not.toBeInTheDocument();
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/tests/teams.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describe('Edit Team', () => {
</ReduxIntlProviders>,
);
const nameInput = screen.getAllByRole('textbox')[0];
await waitFor(() => expect(nameInput.value).toBe('Team Test'));
await waitFor(() => expect(nameInput).toHaveValue('Team Test'), { timeout: 2000 });
expect(screen.getAllByRole('textbox')[1].value).toBe('Dummy team test');

await waitFor(() => expect(screen.getByText('Organisation Name 123')).toBeInTheDocument());
Expand Down

0 comments on commit 7f91467

Please sign in to comment.