This commit is contained in:
parent
5702e23c6f
commit
d4cc8830d8
|
@ -0,0 +1,94 @@
|
||||||
|
import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest';
|
||||||
|
import { createWrapper, axios } from 'app/test/vitest/helper';
|
||||||
|
import WorkerNotificationsManager from 'src/pages/Worker/Card/WorkerNotificationsManager.vue';
|
||||||
|
|
||||||
|
describe('WorkerNotificationsManager', () => {
|
||||||
|
let vm;
|
||||||
|
const entityId = 1110;
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
vm = createWrapper(WorkerNotificationsManager, {
|
||||||
|
propsData: {
|
||||||
|
id: entityId,
|
||||||
|
},
|
||||||
|
}).vm;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
vi.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('fetch()', () => {
|
||||||
|
it('should fetch the data', async () => {
|
||||||
|
const subscriptions = [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
notification: {
|
||||||
|
name: 'Mock name',
|
||||||
|
description: 'Mock description',
|
||||||
|
},
|
||||||
|
notificationFk: 1,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
vi.spyOn(axios, 'get').mockResolvedValue({ data: subscriptions });
|
||||||
|
await vm.fetch();
|
||||||
|
expect(axios.get).toHaveBeenCalledTimes(3)
|
||||||
|
expect(vm.notifications.length).toEqual(1);
|
||||||
|
expect(vm.notifications[0].active).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('disableNotification()', () => {
|
||||||
|
it('should disable the notification', async () => {
|
||||||
|
vi.spyOn(axios, 'delete').mockResolvedValue({ data: { count: 1 } });
|
||||||
|
vi.spyOn(vm.quasar, 'notify');
|
||||||
|
const subscriptionId = 1;
|
||||||
|
vm.notifications = [{ id: 1, active: true }];
|
||||||
|
|
||||||
|
await vm.disableNotification(vm.notifications[0]);
|
||||||
|
|
||||||
|
expect(axios.delete).toHaveBeenCalledWith(
|
||||||
|
`NotificationSubscriptions/${subscriptionId}`
|
||||||
|
);
|
||||||
|
expect(vm.notifications[0].id).toBeNull();
|
||||||
|
expect(vm.notifications[0].id).toBeFalsy();
|
||||||
|
|
||||||
|
expect(vm.quasar.notify).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({ type: 'positive' })
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('toggleNotification()', () => {
|
||||||
|
it('should activate the notification', async () => {
|
||||||
|
vi.spyOn(axios, 'post').mockResolvedValue({
|
||||||
|
data: { id: 1, notificationFk: 1 },
|
||||||
|
});
|
||||||
|
vm.notifications = [{ id: null, active: true, notificationFk: 1 }];
|
||||||
|
|
||||||
|
await vm.toggleNotification(vm.notifications[0]);
|
||||||
|
|
||||||
|
expect(axios.post).toHaveBeenCalledWith('NotificationSubscriptions', {
|
||||||
|
notificationFk: 1,
|
||||||
|
userFk: entityId,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(vm.notifications[0].id).toBe(1);
|
||||||
|
expect(vm.notifications[0].active).toBeTruthy();
|
||||||
|
|
||||||
|
expect(vm.quasar.notify).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({ type: 'positive' })
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should disable the notification', async () => {
|
||||||
|
vi.spyOn(vm, 'disableNotification');
|
||||||
|
vm.notifications = [{ id: 1, active: false, notificationFk: 1 }];
|
||||||
|
|
||||||
|
await vm.toggleNotification(vm.notifications[0]);
|
||||||
|
|
||||||
|
expect(vm.notifications[0].id).toBe(null);
|
||||||
|
expect(vm.notifications[0].active).toBeFalsy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue