Skip to content

Commit

Permalink
fix(Notification test): rewrite notifications test file when user rol…
Browse files Browse the repository at this point in the history
…e is admin.
  • Loading branch information
Hakizimana-Clement committed Aug 1, 2024
1 parent ac1e528 commit a07e7d8
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions test/components/notifications/Notifications.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ import {
import { store } from '../../../src/redux/store';
import { toast } from 'sonner';
import { DynamicData } from '../../../src/@types/DynamicData';
import { io } from 'socket.io-client';

vi.spyOn(window.HTMLMediaElement.prototype, 'play').mockImplementation(() =>
Promise.resolve(),
Expand All @@ -127,9 +126,9 @@ vi.mock('sonner', () => ({
success: vi.fn(),
},
}));

vi.mock('socket.io-client', () => {
//@ts-ignore
const originalModule = vi.requireActual('socket.io-client');
const originalModule = require('socket.io-client');
return {
...originalModule,
__esModule: true,
Expand Down Expand Up @@ -162,7 +161,7 @@ describe('Notification component', () => {
it('should show notification tab when a user clicks on the bell', async () => {
const notification = {
id: '1',
message: 'Test Notification',
message: 'New Notification',
unread: true,
createdAt: new Date().toISOString(),
};
Expand All @@ -171,12 +170,14 @@ describe('Notification component', () => {
const { bell, user } = renderComponent();
await user.click(bell);
expect(screen.getByLabelText('notification-tab')).toBeInTheDocument();
expect(screen.getByText('Test Notification')).toBeInTheDocument();
expect(screen.getByText('New Notification')).toBeInTheDocument();
});

it('should show a toast when a new message is received', async () => {
const { bell, user } = renderComponent();
const socket = io(import.meta.env.VITE_API_APP_ROOT_URL);
const socket = require('socket.io-client')(
import.meta.env.VITE_API_APP_ROOT_URL,
);

socket.emit('notification-user1', {
id: '2',
Expand Down

0 comments on commit a07e7d8

Please sign in to comment.