Skip to content

Commit e44e18c

Browse files
committed
test: fixes test cases related to pagination
1 parent eb5dc08 commit e44e18c

File tree

3 files changed

+12
-24
lines changed

3 files changed

+12
-24
lines changed

src/Notifications/data/api.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe('Notifications API', () => {
6666

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

69-
expect(Object.keys(notifications.results)).toHaveLength(2);
69+
expect(notifications.results).toHaveLength(2);
7070
});
7171

7272
it.each([

src/Notifications/data/redux.test.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { initializeMockApp } from '@edx/frontend-platform/testing';
66

77
import { initializeStore } from '../../store';
88
import executeThunk from '../../test-utils';
9+
import mockNotificationsResponse from '../test-utils';
910
import {
1011
getNotificationsListApiUrl, getNotificationsCountApiUrl, markNotificationAsReadApiUrl, markNotificationsSeenApiUrl,
1112
} from './api';
@@ -38,10 +39,7 @@ describe('Notification Redux', () => {
3839
Factory.resetAll();
3940
store = initializeStore();
4041

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

4745
afterEach(() => {
@@ -60,14 +58,12 @@ describe('Notification Redux', () => {
6058
expect(notifications.notifications).toEqual({});
6159
expect(notifications.tabsCount).toEqual({});
6260
expect(notifications.showNotificationsTray).toEqual(false);
63-
expect(notifications.pagination.totalPages).toEqual(1);
64-
expect(notifications.pagination.currentPage).toEqual(1);
65-
expect(notifications.pagination.nextPage).toBeNull();
61+
expect(notifications.pagination).toEqual({});
6662
});
6763

6864
it('Successfully loaded notifications list in the redux.', async () => {
6965
const { notifications: { notifications } } = store.getState();
70-
expect(Object.keys(notifications)).toHaveLength(2);
66+
expect(Object.keys(notifications)).toHaveLength(10);
7167
});
7268

7369
it.each([

src/Notifications/data/selector.test.jsx

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
55
import { initializeMockApp } from '@edx/frontend-platform/testing';
66

77
import { initializeStore } from '../../store';
8-
import executeThunk from '../../test-utils';
9-
import { getNotificationsListApiUrl, getNotificationsCountApiUrl } from './api';
8+
import mockNotificationsResponse from '../test-utils';
109
import {
1110
selectNotifications,
1211
selectNotificationsByIds,
@@ -18,13 +17,9 @@ import {
1817
selectSelectedAppNotificationIds,
1918
selectShowNotificationTray,
2019
} from './selectors';
21-
import { fetchAppsNotificationCount, fetchNotificationList } from './thunks';
2220

2321
import './__factories__';
2422

25-
const notificationCountsApiUrl = getNotificationsCountApiUrl();
26-
const notificationsApiUrl = getNotificationsListApiUrl();
27-
2823
let axiosMock;
2924
let store;
3025

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

45-
axiosMock.onGet(notificationCountsApiUrl).reply(200, (Factory.build('notificationsCount')));
46-
axiosMock.onGet(notificationsApiUrl).reply(200, (Factory.build('notificationsList')));
47-
await executeThunk(fetchAppsNotificationCount(), store.dispatch, store.getState);
48-
await executeThunk(fetchNotificationList({ appName: 'discussion', page: 1 }), store.dispatch, store.getState);
40+
({ store, axiosMock } = await mockNotificationsResponse());
4941
});
5042

5143
afterEach(() => {
@@ -81,7 +73,7 @@ describe('Notification Selectors', () => {
8173
const state = store.getState();
8274
const notificationIds = selectSelectedAppNotificationIds('discussion')(state);
8375

84-
expect(notificationIds).toHaveLength(2);
76+
expect(notificationIds).toHaveLength(10);
8577
});
8678

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

98-
expect(Object.keys(notifications)).toHaveLength(2);
90+
expect(Object.keys(notifications)).toHaveLength(10);
9991
});
10092

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

105-
expect(notifications).toHaveLength(2);
97+
expect(notifications).toHaveLength(10);
10698
});
10799

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

119111
expect(paginationData.currentPage).toEqual(1);
120-
expect(paginationData.totalPages).toEqual(1);
121-
expect(paginationData.nextPage).toEqual(null);
112+
expect(paginationData.numPages).toEqual(2);
113+
expect(paginationData.hasMorePages).toEqual(true);
122114
});
123115
});

0 commit comments

Comments
 (0)