forked from verdnatura/salix-front
refs #4797 test: workerNotification front
This commit is contained in:
parent
0b3a957944
commit
b82f5d210f
|
@ -122,7 +122,6 @@ function setNotifications(data) {
|
||||||
grid-template-columns: repeat(4, 1fr);
|
grid-template-columns: repeat(4, 1fr);
|
||||||
grid-gap: 10px;
|
grid-gap: 10px;
|
||||||
|
|
||||||
/* we will explain what these classes do next! */
|
|
||||||
.v-enter-active,
|
.v-enter-active,
|
||||||
.v-leave-active {
|
.v-leave-active {
|
||||||
transition: opacity 0.5s ease;
|
transition: opacity 0.5s ease;
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest';
|
import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest';
|
||||||
import { createWrapper, axios } from 'app/test/vitest/helper';
|
import { createWrapper } from 'app/test/vitest/helper';
|
||||||
import WorkerNotificationsManager from 'src/pages/Worker/Card/WorkerNotificationsManager.vue';
|
import WorkerNotificationsManager from 'src/pages/Worker/Card/WorkerNotificationsManager.vue';
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
describe('WorkerNotificationsManager', () => {
|
describe('WorkerNotificationsManager', () => {
|
||||||
let vm;
|
let vm;
|
||||||
const entityId = 1110;
|
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
vm = createWrapper(WorkerNotificationsManager, {
|
vm = createWrapper(WorkerNotificationsManager, {
|
||||||
propsData: {
|
global: {
|
||||||
id: entityId,
|
stubs: ['CrudModel'],
|
||||||
},
|
},
|
||||||
}).vm;
|
}).vm;
|
||||||
});
|
});
|
||||||
|
@ -18,83 +18,16 @@ describe('WorkerNotificationsManager', () => {
|
||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('fetch()', () => {
|
describe('swapEntry()', () => {
|
||||||
it('should fetch notification subscriptions and role mappings', async () => {
|
it('should swap notification', async () => {
|
||||||
vi.spyOn(axios, 'get')
|
const from = ref(new Map());
|
||||||
.mockResolvedValueOnce({
|
const to = ref(new Map());
|
||||||
data: [
|
from.value.set(1, { notificationFk: 1 });
|
||||||
{
|
to.value.set(2, { notificationFk: 2 });
|
||||||
id: 1,
|
|
||||||
name: 'Name 1',
|
|
||||||
description: 'Description 1',
|
|
||||||
notificationFk: 1,
|
|
||||||
active: true
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
await vm.fetch();
|
|
||||||
|
|
||||||
expect(axios.get).toHaveBeenCalledWith(`NotificationSubscriptions/${entityId}/getList`);
|
await vm.swapEntry(from.value, to.value, 1);
|
||||||
expect(vm.notifications).toEqual([
|
expect(to.value.size).toBe(2);
|
||||||
{
|
expect(from.value.size).toBe(0);
|
||||||
id: 1,
|
|
||||||
notificationFk: 1,
|
|
||||||
name: 'Name 1',
|
|
||||||
description: 'Description 1',
|
|
||||||
active: true,
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
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