Skip to content

Commit

Permalink
refactor: use screen and remove unnecessary args
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera committed Oct 8, 2024
1 parent 71f735a commit 316166b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
20 changes: 10 additions & 10 deletions src/course-outline/CourseOutline.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ describe('<CourseOutline />', () => {
});

it('check video sharing option shows error on failure', async () => {
const { findByLabelText, queryAllByRole } = render(<RootWrapper />);
render(<RootWrapper />);

axiosMock
.onPost(getCourseBlockApiUrl(courseId), {
Expand All @@ -235,7 +235,7 @@ describe('<CourseOutline />', () => {
},
})
.reply(500);
const optionDropdown = await findByLabelText(statusBarMessages.videoSharingTitle.defaultMessage);
const optionDropdown = await screen.findByLabelText(statusBarMessages.videoSharingTitle.defaultMessage);
await act(
async () => fireEvent.change(optionDropdown, { target: { value: VIDEO_SHARING_OPTIONS.allOff } }),
);
Expand All @@ -247,7 +247,7 @@ describe('<CourseOutline />', () => {
},
}));

const alertElements = queryAllByRole('alert');
const alertElements = screen.queryAllByRole('alert');
expect(alertElements.find(
(el) => el.classList.contains('alert-content'),
)).toHaveTextContent(
Expand Down Expand Up @@ -513,10 +513,10 @@ describe('<CourseOutline />', () => {
notificationDismissUrl: '/some/url',
});

const { findByRole, findByText } = render(<RootWrapper />);
const alert = await findByText(pageAlertMessages.configurationErrorTitle.defaultMessage);
render(<RootWrapper />);
const alert = await screen.findByText(pageAlertMessages.configurationErrorTitle.defaultMessage);
expect(alert).toBeInTheDocument();
const dismissBtn = await findByRole('button', { name: 'Dismiss' });
const dismissBtn = await screen.findByRole('button', { name: 'Dismiss' });
axiosMock
.onDelete('/some/url')
.reply(204);
Expand Down Expand Up @@ -2163,10 +2163,10 @@ describe('<CourseOutline />', () => {
});

it('check whether unit copy & paste option works correctly', async () => {
const { findAllByTestId, queryByTestId, findAllByRole } = render(<RootWrapper />);
render(<RootWrapper />);
// get first section -> first subsection -> first unit element
const [section] = courseOutlineIndexMock.courseStructure.childInfo.children;
const [sectionElement] = await findAllByTestId('section-card');
const [sectionElement] = await screen.findAllByTestId('section-card');
const [subsection] = section.childInfo.children;
axiosMock
.onGet(getXBlockApiUrl(section.id))
Expand Down Expand Up @@ -2205,7 +2205,7 @@ describe('<CourseOutline />', () => {
await act(async () => fireEvent.mouseOver(clipboardLabel));

// find clipboard content popover link
const popoverContent = queryByTestId('popover-content');
const popoverContent = screen.queryByTestId('popover-content');
expect(popoverContent.tagName).toBe('A');
expect(popoverContent).toHaveAttribute('href', `${getConfig().STUDIO_BASE_URL}${unit.studioUrl}`);

Expand Down Expand Up @@ -2236,7 +2236,7 @@ describe('<CourseOutline />', () => {
errorFiles: ['error.css'],
});

let alerts = await findAllByRole('alert');
let alerts = await screen.findAllByRole('alert');
// Exclude processing notification toast
alerts = alerts.filter((el) => !el.classList.contains('toast-container'));
// 3 alerts should be present
Expand Down
10 changes: 5 additions & 5 deletions src/course-unit/CourseUnit.test.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import MockAdapter from 'axios-mock-adapter';
import {
act, render, waitFor, fireEvent, within,
act, render, waitFor, fireEvent, within, screen,
} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { IntlProvider } from '@edx/frontend-platform/i18n';
Expand Down Expand Up @@ -525,10 +525,10 @@ describe('<CourseUnit />', () => {
});

it('should display a warning alert for unpublished course unit version', async () => {
const { getAllByRole } = render(<RootWrapper />);
render(<RootWrapper />);

await waitFor(() => {
const unpublishedAlert = getAllByRole('alert').find(
const unpublishedAlert = screen.getAllByRole('alert').find(
(el) => el.classList.contains('alert-content'),
);
expect(unpublishedAlert).toHaveTextContent(messages.alertUnpublishedVersion.defaultMessage);
Expand All @@ -537,7 +537,7 @@ describe('<CourseUnit />', () => {
});

it('should not display an unpublished alert for a course unit with explicit staff lock and unpublished status', async () => {
const { queryAllByRole } = render(<RootWrapper />);
render(<RootWrapper />);

axiosMock
.onGet(getCourseUnitApiUrl(courseId))
Expand All @@ -549,7 +549,7 @@ describe('<CourseUnit />', () => {
await executeThunk(fetchCourseUnitQuery(courseId), store.dispatch);

await waitFor(() => {
const alert = queryAllByRole('alert').find(
const alert = screen.queryAllByRole('alert').find(
(el) => el.classList.contains('alert-content'),
);
expect(alert).toBeUndefined();
Expand Down
9 changes: 3 additions & 6 deletions src/library-authoring/data/apiHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,7 @@ export const useUpdateCollectionComponents = (libraryId?: string, collectionId?:
}
return undefined;
},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onSettled: (_data, _error, _variables) => {
onSettled: () => {
if (libraryId !== undefined && collectionId !== undefined) {
queryClient.invalidateQueries({ predicate: (query) => libraryQueryPredicate(query, libraryId) });
}
Expand All @@ -321,8 +320,7 @@ export const useDeleteCollection = (libraryId: string, collectionId: string) =>
const queryClient = useQueryClient();
return useMutation({
mutationFn: async () => deleteCollection(libraryId, collectionId),
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onSettled: (_data, _error, _variables) => {
onSettled: () => {
queryClient.invalidateQueries({ queryKey: libraryAuthoringQueryKeys.contentLibrary(libraryId) });
queryClient.invalidateQueries({ predicate: (query) => libraryQueryPredicate(query, libraryId) });
},
Expand All @@ -336,8 +334,7 @@ export const useRestoreCollection = (libraryId: string, collectionId: string) =>
const queryClient = useQueryClient();
return useMutation({
mutationFn: async () => restoreCollection(libraryId, collectionId),
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onSettled: (_data, _error, _variables) => {
onSettled: () => {
queryClient.invalidateQueries({ queryKey: libraryAuthoringQueryKeys.contentLibrary(libraryId) });
queryClient.invalidateQueries({ predicate: (query) => libraryQueryPredicate(query, libraryId) });
},
Expand Down

0 comments on commit 316166b

Please sign in to comment.