Skip to content

Commit

Permalink
test: fixes test cases related to pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
ayesha-waris committed Jul 6, 2023
1 parent eb5dc08 commit e44e18c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/Notifications/data/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('Notifications API', () => {

const notifications = await getNotificationsList('discussion', 1);

expect(Object.keys(notifications.results)).toHaveLength(2);
expect(notifications.results).toHaveLength(2);
});

it.each([
Expand Down
12 changes: 4 additions & 8 deletions src/Notifications/data/redux.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { initializeMockApp } from '@edx/frontend-platform/testing';

import { initializeStore } from '../../store';
import executeThunk from '../../test-utils';
import mockNotificationsResponse from '../test-utils';
import {
getNotificationsListApiUrl, getNotificationsCountApiUrl, markNotificationAsReadApiUrl, markNotificationsSeenApiUrl,
} from './api';
Expand Down Expand Up @@ -38,10 +39,7 @@ describe('Notification Redux', () => {
Factory.resetAll();
store = initializeStore();

axiosMock.onGet(notificationCountsApiUrl).reply(200, (Factory.build('notificationsCount')));
axiosMock.onGet(notificationsListApiUrl).reply(200, (Factory.build('notificationsList')));
await executeThunk(fetchAppsNotificationCount(), store.dispatch, store.getState);
await executeThunk(fetchNotificationList({ appName: 'discussion', page: 1 }), store.dispatch, store.getState);
({ store, axiosMock } = await mockNotificationsResponse());
});

afterEach(() => {
Expand All @@ -60,14 +58,12 @@ describe('Notification Redux', () => {
expect(notifications.notifications).toEqual({});
expect(notifications.tabsCount).toEqual({});
expect(notifications.showNotificationsTray).toEqual(false);
expect(notifications.pagination.totalPages).toEqual(1);
expect(notifications.pagination.currentPage).toEqual(1);
expect(notifications.pagination.nextPage).toBeNull();
expect(notifications.pagination).toEqual({});
});

it('Successfully loaded notifications list in the redux.', async () => {
const { notifications: { notifications } } = store.getState();
expect(Object.keys(notifications)).toHaveLength(2);
expect(Object.keys(notifications)).toHaveLength(10);
});

it.each([
Expand Down
22 changes: 7 additions & 15 deletions src/Notifications/data/selector.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
import { initializeMockApp } from '@edx/frontend-platform/testing';

import { initializeStore } from '../../store';
import executeThunk from '../../test-utils';
import { getNotificationsListApiUrl, getNotificationsCountApiUrl } from './api';
import mockNotificationsResponse from '../test-utils';
import {
selectNotifications,
selectNotificationsByIds,
Expand All @@ -18,13 +17,9 @@ import {
selectSelectedAppNotificationIds,
selectShowNotificationTray,
} from './selectors';
import { fetchAppsNotificationCount, fetchNotificationList } from './thunks';

import './__factories__';

const notificationCountsApiUrl = getNotificationsCountApiUrl();
const notificationsApiUrl = getNotificationsListApiUrl();

let axiosMock;
let store;

Expand All @@ -42,10 +37,7 @@ describe('Notification Selectors', () => {
Factory.resetAll();
store = initializeStore();

axiosMock.onGet(notificationCountsApiUrl).reply(200, (Factory.build('notificationsCount')));
axiosMock.onGet(notificationsApiUrl).reply(200, (Factory.build('notificationsList')));
await executeThunk(fetchAppsNotificationCount(), store.dispatch, store.getState);
await executeThunk(fetchNotificationList({ appName: 'discussion', page: 1 }), store.dispatch, store.getState);
({ store, axiosMock } = await mockNotificationsResponse());
});

afterEach(() => {
Expand Down Expand Up @@ -81,7 +73,7 @@ describe('Notification Selectors', () => {
const state = store.getState();
const notificationIds = selectSelectedAppNotificationIds('discussion')(state);

expect(notificationIds).toHaveLength(2);
expect(notificationIds).toHaveLength(10);
});

it('Should return show notification tray status.', async () => {
Expand All @@ -95,14 +87,14 @@ describe('Notification Selectors', () => {
const state = store.getState();
const notifications = selectNotifications()(state);

expect(Object.keys(notifications)).toHaveLength(2);
expect(Object.keys(notifications)).toHaveLength(10);
});

it('Should return notifications from Ids.', async () => {
const state = store.getState();
const notifications = selectNotificationsByIds('discussion')(state);

expect(notifications).toHaveLength(2);
expect(notifications).toHaveLength(10);
});

it('Should return selected app name.', async () => {
Expand All @@ -117,7 +109,7 @@ describe('Notification Selectors', () => {
const paginationData = selectPaginationData()(state);

expect(paginationData.currentPage).toEqual(1);
expect(paginationData.totalPages).toEqual(1);
expect(paginationData.nextPage).toEqual(null);
expect(paginationData.numPages).toEqual(2);
expect(paginationData.hasMorePages).toEqual(true);
});
});

0 comments on commit e44e18c

Please sign in to comment.