Skip to content

Commit

Permalink
test: improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
pomegranited committed Oct 17, 2024
1 parent c4c818c commit 9897cde
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/library-authoring/__mocks__/contentLibrariesListV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
next: null,
previous: null,
count: 2,
num_pages: 1,
num_pages: 2,
current_page: 1,
start: 0,
results: [
Expand Down
20 changes: 19 additions & 1 deletion src/studio-home/tabs-section/TabsSection.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import { getApiBaseUrl, getStudioHomeApiUrl } from '../data/api';
import { executeThunk } from '../../utils';
import { fetchLibraryData, fetchStudioHomeData } from '../data/thunks';
import { mockGetContentLibraryV2List } from '../../library-authoring/data/api.mocks';
import { getContentLibraryV2ListApiUrl } from '../../library-authoring/data/api';
import contentLibrariesListV2 from '../../library-authoring/__mocks__/contentLibrariesListV2';
import {
Expand Down Expand Up @@ -391,6 +392,7 @@ describe('<TabsSection />', () => {
expect(librariesTab).toHaveClass('active');

expect(screen.getByText('Showing 2 of 2')).toBeVisible();
expect(screen.getByText('Page 1, Current Page, of 2')).toBeVisible();

expect(screen.getByText(contentLibrariesListV2.results[0].title)).toBeVisible();
expect(screen.getByText(
Expand All @@ -403,6 +405,22 @@ describe('<TabsSection />', () => {
)).toBeVisible();
});

it('should show a "not found" message if no v2 libraries were loaded', async () => {
mockGetContentLibraryV2List.applyMockEmpty();
render();
axiosMock.onGet(getStudioHomeApiUrl()).reply(200, generateGetStudioHomeDataApiResponse());
await executeThunk(fetchStudioHomeData(), store.dispatch);

const librariesTab = screen.getByRole('tab', { name: librariesBetaTabTitle });
fireEvent.click(librariesTab);

expect(librariesTab).toHaveClass('active');

expect(await screen.findByText(
tabMessages.librariesV2TabLibraryNotFoundAlertMessage.defaultMessage,
)).toBeVisible();
});

it('should hide Libraries tab when libraries are disabled', async () => {
const data = generateGetStudioHomeDataApiResponse();

Expand All @@ -414,7 +432,7 @@ describe('<TabsSection />', () => {
expect(screen.queryByText(tabMessages.legacyLibrariesTabTitle.defaultMessage)).toBeNull();
});

it('should render libraries fetch failure alert', async () => {
it('should render legacy libraries fetch failure alert', async () => {
render();
axiosMock.onGet(getStudioHomeApiUrl()).reply(200, generateGetStudioHomeDataApiResponse());
axiosMock.onGet(libraryApiLink).reply(404);
Expand Down

0 comments on commit 9897cde

Please sign in to comment.