diff --git a/test/frontend/__fixtures__/notification_types.ts b/test/frontend/__fixtures__/notification_types.ts index e69de29bb..df22a4a44 100644 --- a/test/frontend/__fixtures__/notification_types.ts +++ b/test/frontend/__fixtures__/notification_types.ts @@ -0,0 +1,9 @@ +import { NotificationType } from '../../../app/frontend/src/javascript/models/notification-type'; + +const notificationTypes: Array = [ + { id: 1, name: 'notify_admin_when_project_published', category: 'projects', is_configurable: true }, + { id: 2, name: 'notify_project_collaborator_to_valid', category: 'projects', is_configurable: true }, + { id: 3, name: 'notify_project_author_when_collaborator_valid', category: 'projects', is_configurable: true } +]; + +export default notificationTypes; diff --git a/test/frontend/__fixtures__/notifications.ts b/test/frontend/__fixtures__/notifications.ts new file mode 100644 index 000000000..6dab3d2c0 --- /dev/null +++ b/test/frontend/__fixtures__/notifications.ts @@ -0,0 +1,47 @@ +import { Notification, NotificationsIndex } from '../../../app/frontend/src/javascript/models/notification'; + +const newNotifications: Array = [ + { + id: 1, + notification_type: 'notify_admin_when_project_published', + notification_type_id: 1, + created_at: '2023-02-03T14:42:34.678Z', + is_read: false, + message: { + title: '', + description: 'Decription of the first notification' + } + }, + { + id: 2, + notification_type: 'notify_project_collaborator_to_valid', + notification_type_id: 2, + created_at: '2023-02-03T14:42:34.678Z', + is_read: false, + message: { + title: '', + description: 'Decription of the second notification' + } + }, + { + id: 3, + notification_type: 'notify_project_author_when_collaborator_valid', + notification_type_id: 3, + created_at: '2023-02-03T14:42:34.678Z', + is_read: false, + message: { + title: '', + description: 'Decription of the third notification' + } + } +]; + +const notificationsIndex: NotificationsIndex = { + notifications: newNotifications, + totals: { + total: 3, + unread: 3 + } +}; + +export default notificationsIndex; diff --git a/test/frontend/__lib__/fixtures.ts b/test/frontend/__lib__/fixtures.ts index 28e4ea997..ef7ed6663 100644 --- a/test/frontend/__lib__/fixtures.ts +++ b/test/frontend/__lib__/fixtures.ts @@ -11,6 +11,8 @@ import providers from '../__fixtures__/auth_providers'; import profileCustomFields from '../__fixtures__/profile_custom_fields'; import spaces from '../__fixtures__/spaces'; import statuses from '../__fixtures__/statuses'; +import notificationTypes from '../__fixtures__/notification_types'; +import notifications from '../__fixtures__/notifications'; const FixturesLib = { init: () => { @@ -29,7 +31,9 @@ const FixturesLib = { providers: JSON.parse(JSON.stringify(providers)), profileCustomFields: JSON.parse(JSON.stringify(profileCustomFields)), spaces: JSON.parse(JSON.stringify(spaces)), - statuses: JSON.parse(JSON.stringify(statuses)) + statuses: JSON.parse(JSON.stringify(statuses)), + notificationTypes: JSON.parse(JSON.stringify(notificationTypes)), + notifications: JSON.parse(JSON.stringify(notifications)) }; } }; diff --git a/test/frontend/__setup__/server.js b/test/frontend/__setup__/server.js index bd2748ac9..09e578c12 100644 --- a/test/frontend/__setup__/server.js +++ b/test/frontend/__setup__/server.js @@ -111,6 +111,12 @@ export const server = setupServer( status.id = fixtures.statuses.length + 1; fixtures.statuses.push(status); return res(ctx.json({ status })); + }), + rest.get('/api/notification_types', (req, res, ctx) => { + return res(ctx.json(fixtures.notification_types)); + }), + rest.get('/api/notifications', (req, res, ctx) => { + return res(ctx.json(fixtures.notifications)); }) ); diff --git a/test/frontend/components/notifications/notifications-list.test.tsx b/test/frontend/components/notifications/notifications-list.test.tsx index c6af63ab7..cc2a55626 100644 --- a/test/frontend/components/notifications/notifications-list.test.tsx +++ b/test/frontend/components/notifications/notifications-list.test.tsx @@ -8,5 +8,8 @@ describe('Notifications list', () => { render(); await waitFor(() => screen.getByTestId('notifications-list')); + expect(screen.getByText('Decription of the first notification')).toBeDefined(); + expect(screen.getByText('Decription of the second notification')).toBeDefined(); + expect(screen.getByText('Decription of the third notification')).toBeDefined(); }); });