Skip to content

Commit

Permalink
fix: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pkulkark committed Sep 13, 2024
1 parent 1039d10 commit 5a6b2d8
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/studio-home/StudioHome.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,48 @@ describe('<StudioHome />', async () => {
});
});
});

describe('Enable pagination', () => {
beforeEach(async () => {
initializeMockApp({
authenticatedUser: {
userId: 3,
username: 'abc123',
administrator: true,
roles: [],
},
});
store = initializeStore();
axiosMock = new MockAdapter(getAuthenticatedHttpClient());
global.window = Object.create(window);
Object.defineProperty(window, 'location', {
value: {
search: '?search=test',
},
});
});

const RootWrapperWithPagination = () => (
<AppProvider store={store}>
<IntlProvider locale="en" messages={{}}>
<StudioHome intl={injectIntl} isPaginationCoursesEnabled />
</IntlProvider>
</AppProvider>
);

it('should dispatch fetchStudioHomeData with paginated parameters on component mount', async () => {
axiosMock.onGet(getStudioHomeApiUrl()).reply(200, studioHomeMock);

const { getByText } = render(<RootWrapperWithPagination />);

expect(getByText(`${studioShortName} home`)).toBeInTheDocument();
});

it('should only dispatch fetchStudioHomeData once when pagination is enabled', async () => {
axiosMock.onGet(getStudioHomeApiUrl()).reply(200, studioHomeMock);

render(<RootWrapperWithPagination />);

expect(axiosMock.history.get.length).toBe(1);
});
});

0 comments on commit 5a6b2d8

Please sign in to comment.