Skip to content

Commit

Permalink
test: fix some failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bra-i-am committed May 2, 2024
1 parent c096c71 commit 3821d8e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/files-and-uploads/FilesAndUploads.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ const FilesAndUploads = ({
<Button variant="tertiary" onClick={closeDeleteConfirmation}>
{intl.formatMessage(messages.cancelButtonLabel)}
</Button>
<Button onClick={handleBulkDelete}>
<Button data-testid="deletion-button" onClick={handleBulkDelete}>
{intl.formatMessage(messages.deleteFileButtonLabel)}
</Button>
</ActionRow>
Expand Down
11 changes: 6 additions & 5 deletions src/files-and-uploads/FilesAndUploads.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,16 @@ describe('FilesAndUploads', () => {
expect(deleteButton).not.toHaveClass('disabled');

axiosMock.onDelete(`${getAssetsUrl(courseId)}mOckID1`).reply(204);
await waitFor(() => {
fireEvent.click(deleteButton);
expect(screen.getByText(messages.deleteConfirmationTitle.defaultMessage)).toBeVisible();
fireEvent.click(deleteButton);
expect(screen.queryByText(messages.deleteConfirmationTitle.defaultMessage)).toBeVisible();

fireEvent.click(screen.getByText(messages.deleteFileButtonLabel.defaultMessage));
expect(screen.queryByText(messages.deleteConfirmationTitle.defaultMessage)).toBeNull();
fireEvent.click(screen.getByTestId('deletion-button'));
expect(screen.queryByText(messages.deleteConfirmationTitle.defaultMessage)).toBeNull();

await waitFor(() => {
executeThunk(deleteAssetFile(courseId, 'mOckID1', 5), store.dispatch);
});

const deleteStatus = store.getState().assets.deletingStatus;
expect(deleteStatus).toEqual(RequestStatus.SUCCESSFUL);

Expand Down
18 changes: 15 additions & 3 deletions src/pages-and-resources/discussions/DiscussionsSettings.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import {
import userEvent from '@testing-library/user-event';
import MockAdapter from 'axios-mock-adapter';
import React from 'react';
import { Routes, Route, MemoryRouter } from 'react-router-dom';
import {
Routes,
Route,
MemoryRouter,
useLocation,
} from 'react-router-dom';
import { fetchCourseDetail } from '../../data/thunks';
import initializeStore from '../../store';
import { executeThunk } from '../../utils';
Expand All @@ -37,6 +42,12 @@ let container;
// Modal creates a portal. Overriding ReactDOM.createPortal allows portals to be tested in jest.
ReactDOM.createPortal = jest.fn(node => node);

// eslint-disable-next-line import/prefer-default-export
export const LocationDisplay = () => {
const location = useLocation();
return <div data-testid="location-display">{location.pathname}</div>;
};

function renderComponent(route) {
const wrapper = render(
<AppProvider store={store} wrapWithRouter={false}>
Expand All @@ -52,6 +63,7 @@ function renderComponent(route) {
element={<PageWrap><DiscussionsSettings courseId={courseId} /></PageWrap>}
/>
</Routes>
<LocationDisplay />
</MemoryRouter>
</PagesAndResourcesProvider>
</AppProvider>,
Expand Down Expand Up @@ -196,7 +208,7 @@ describe('DiscussionsSettings', () => {
// then it's safe to proceed with our expectations.
await waitForElementToBeRemoved(queryByRole(container, 'button', { name: 'Close' }));

await waitFor(() => expect(window.location.pathname).toEqual(`/course/${courseId}/pages-and-resources`));
expect(screen.getByTestId('location-display')).toHaveTextContent(`/course/${courseId}/pages-and-resources`);
});

test('requires confirmation if changing provider', async () => {
Expand Down Expand Up @@ -351,7 +363,7 @@ describe('DiscussionsSettings', () => {
expect(queryByTestId(container, 'appConfigForm')).not.toBeInTheDocument();

// We don't technically leave the route in this case, though the modal is hidden.
expect(window.location.pathname).toEqual(`/course/${courseId}/pages-and-resources/discussion/configure/piazza`);
expect(screen.getByTestId('location-display')).toHaveTextContent(`/course/${courseId}/pages-and-resources/discussion/configure/piazza`);

const alert = await findByRole(container, 'alert');
expect(alert).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ describe('<PacingSection />', () => {
});

it('shows disabled radio inputs correctly', () => {
const pastDate = '2023-12-31';
const initialProps = { ...props, startDate: pastDate };
const todayDate = new Date();
const startDate = todayDate.setDate(todayDate.getDate() + 1);

// If it is wanted that radioList.disabled to be False
// it is necessary that the course hasn't started yet
const initialProps = { ...props, startDate };
const { getAllByRole, queryAllByText } = render(
<RootWrapper {...initialProps} />,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ describe('<ScheduleRow />', () => {
it('calls onChange on datepicker input change', () => {
const { getByPlaceholderText } = render(<RootWrapper {...props} />);
const input = getByPlaceholderText('MM/DD/YYYY');
fireEvent.change(input, { target: { value: '06/15/2023' } });
fireEvent.change(input, { target: { value: '2023-06-15T00:00:00Z' } });

expect(onChangeMock).toHaveBeenCalledWith(
'2023-06-15T00:00:00Z',
props.controlName,
Expand Down

0 comments on commit 3821d8e

Please sign in to comment.