diff --git a/.vscode/settings.json b/.vscode/settings.json index ecc1d50d7..5026b7d3b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -13,5 +13,6 @@ ], "[vue]": { "editor.defaultFormatter": "esbenp.prettier-vscode" - } + }, + "cSpell.words": ["axios"] } diff --git a/package.json b/package.json index 454e53e53..e09a2ac9e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salix-front", - "version": "23.46.01", + "version": "23.48.01", "description": "Salix frontend", "productName": "Salix", "author": "Verdnatura", @@ -15,7 +15,7 @@ "test:unit:ci": "vitest run" }, "dependencies": { - "@quasar/cli": "^2.2.1", + "@quasar/cli": "^2.3.0", "@quasar/extras": "^1.16.4", "axios": "^1.4.0", "chromium": "^3.0.3", @@ -53,4 +53,4 @@ "vite": "^4.3.5", "vitest": "^0.31.1" } -} \ No newline at end of file +} diff --git a/src/components/CrudModel.vue b/src/components/CrudModel.vue index 2a4982fce..96d52b98c 100644 --- a/src/components/CrudModel.vue +++ b/src/components/CrudModel.vue @@ -89,6 +89,7 @@ async function fetch(data) { watch(formData, () => (hasChanges.value = true), { deep: true }); emit('onFetch', data); + return data; } async function reset() { diff --git a/src/pages/Claim/Card/ClaimDevelopment.vue b/src/pages/Claim/Card/ClaimDevelopment.vue index c2c9b925c..09422f7a1 100644 --- a/src/pages/Claim/Card/ClaimDevelopment.vue +++ b/src/pages/Claim/Card/ClaimDevelopment.vue @@ -249,9 +249,6 @@ function goToAction() { .grid-style-transition { transition: transform 0.28s, background-color 0.28s; } -.maxwidth { - width: 100%; -} diff --git a/src/pages/Customer/CustomerCreate.vue b/src/pages/Customer/CustomerCreate.vue deleted file mode 100644 index d87af6cab..000000000 --- a/src/pages/Customer/CustomerCreate.vue +++ /dev/null @@ -1,56 +0,0 @@ - - - - - diff --git a/src/pages/Worker/Card/WorkerNotificationsManager.vue b/src/pages/Worker/Card/WorkerNotificationsManager.vue index 13c9b3de2..44573adca 100644 --- a/src/pages/Worker/Card/WorkerNotificationsManager.vue +++ b/src/pages/Worker/Card/WorkerNotificationsManager.vue @@ -1,10 +1,12 @@ + + + diff --git a/src/router/modules/customer.js b/src/router/modules/customer.js index c7e978eec..832a1e0fd 100644 --- a/src/router/modules/customer.js +++ b/src/router/modules/customer.js @@ -10,7 +10,7 @@ export default { component: RouterView, redirect: { name: 'CustomerMain' }, menus: { - main: ['CustomerList', 'CustomerPayments', 'CustomerCreate'], + main: ['CustomerList', 'CustomerPayments'], card: ['CustomerBasicData'], }, children: [ @@ -27,7 +27,7 @@ export default { title: 'list', icon: 'view_list', }, - component: () => import('src/pages/Customer/CustomerList.vue') + component: () => import('src/pages/Customer/CustomerList.vue'), }, { path: 'payments', @@ -36,17 +36,7 @@ export default { title: 'webPayments', icon: 'vn:onlinepayment', }, - component: () => import('src/pages/Customer/CustomerPayments.vue') - }, - { - path: 'create', - name: 'CustomerCreate', - meta: { - title: 'createCustomer', - icon: 'vn:addperson', - roles: ['developer'], - }, - component: () => import('src/pages/Customer/CustomerCreate.vue'), + component: () => import('src/pages/Customer/CustomerPayments.vue'), }, ], }, @@ -63,7 +53,8 @@ export default { title: 'summary', icon: 'launch', }, - component: () => import('src/pages/Customer/Card/CustomerSummary.vue'), + component: () => + import('src/pages/Customer/Card/CustomerSummary.vue'), }, { path: 'basic-data', @@ -72,7 +63,8 @@ export default { title: 'basicData', icon: 'vn:settings', }, - component: () => import('src/pages/Customer/Card/CustomerBasicData.vue'), + component: () => + import('src/pages/Customer/Card/CustomerBasicData.vue'), }, ], }, diff --git a/src/router/modules/worker.js b/src/router/modules/worker.js index f79d7f06d..e5ee7c1a2 100644 --- a/src/router/modules/worker.js +++ b/src/router/modules/worker.js @@ -11,7 +11,7 @@ export default { redirect: { name: 'WorkerMain' }, menus: { main: ['WorkerList'], - // card: ['WorkerNotificationsManager'], + card: ['WorkerNotificationsManager'], }, children: [ { @@ -46,15 +46,16 @@ export default { }, component: () => import('src/pages/Worker/Card/WorkerSummary.vue'), }, - // { - // name: 'WorkerNotificationsManager', - // path: 'notifications', - // meta: { - // title: 'notifications', - // icon: 'notifications', - // }, - // component: () => import('src/pages/Worker/Card/WorkerNotificationsManager.vue'), - // }, + { + name: 'WorkerNotificationsManager', + path: 'notifications', + meta: { + title: 'notifications', + icon: 'notifications', + }, + component: () => + import('src/pages/Worker/Card/WorkerNotificationsManager.vue'), + }, ], }, ], diff --git a/test/cypress/integration/ClaimNotes.spec.js b/test/cypress/integration/claimNotes.spec.js similarity index 100% rename from test/cypress/integration/ClaimNotes.spec.js rename to test/cypress/integration/claimNotes.spec.js diff --git a/test/cypress/integration/workerNotificationsManager.spec.js b/test/cypress/integration/workerNotificationsManager.spec.js index 4cd54629a..175933277 100644 --- a/test/cypress/integration/workerNotificationsManager.spec.js +++ b/test/cypress/integration/workerNotificationsManager.spec.js @@ -1,36 +1,79 @@ -xdescribe('WorkerNotificationsManager', () => { +describe('WorkerNotificationsManager', () => { + const salesPersonId = 18; + const developerId = 9; + + const activeList = ':nth-child(1) > .q-list'; + const availableList = ':nth-child(2) > .q-list'; + const firstActiveNotification = + ':nth-child(1) > .q-list > :nth-child(1) > .q-item > .q-toggle > .q-toggle__inner'; + const firstAvailableNotification = + ':nth-child(2) > .q-list > :nth-child(1) > .q-item > .q-toggle > .q-toggle__inner'; + beforeEach(() => { - const workerId = 1110; cy.viewport(1280, 720); - cy.login('salesBoss'); - cy.visit(`/#/worker/${workerId}/notifications`); }); - it('should unsubscribe 2 notifications, check the unsubscription has been saved, subscribe to other one and should check the data has been saved', () => { - cy.get('.q-chip').should('have.length', 3); - cy.get('.q-toggle__thumb').eq(0).click(); - cy.get('.q-notification__message').should( - 'have.text', - 'Unsubscribed from the notification' + it('should throw an error if you try to change a notification that is not yours', () => { + cy.login('developer'); + cy.visit(`/#/worker/${salesPersonId}/notifications`); + cy.get(firstAvailableNotification).click(); + cy.notificationHas( + '.q-notification__message', + 'The notification subscription of this worker cant be modified' ); - cy.get('.q-chip > .q-icon').eq(0).click(); + }); - cy.reload(); + it('should active a notification that is yours', () => { + cy.login('developer'); + cy.visit(`/#/worker/${developerId}/notifications`); + cy.waitForElement(activeList); + cy.waitForElement(availableList); - cy.get('.q-chip').should('have.length', 1); - cy.get('.q-toggle__thumb').should('have.length', 3).eq(0).click(); - cy.get('.q-notification__message').should( - 'have.text', - 'Subscribed to the notification' - ); - cy.get('.q-toggle__thumb').should('have.length', 3).eq(1).click(); - cy.get('.q-notification__message').should( - 'have.text', - 'Subscribed to the notification' - ); + cy.get(activeList) + .children() + .its('length') + .then((beforeSize) => { + cy.get(firstAvailableNotification).click(); + cy.get(activeList) + .children() + .should('have.length', beforeSize + 1); + }); + }); - cy.reload(); + it('should deactivate a notification that is yours', () => { + cy.login('developer'); + cy.visit(`/#/worker/${developerId}/notifications`); + cy.waitForElement(activeList); + cy.waitForElement(availableList); - cy.get('.q-chip').should('have.length', 3); + cy.get(availableList) + .children() + .its('length') + .then((beforeSize) => { + cy.get(firstActiveNotification).click(); + cy.get(availableList) + .children() + .should('have.length', beforeSize + 1); + }); + }); + + it('should active a notification if you are their boss', () => { + cy.login('salesBoss'); + cy.visit(`/#/worker/${salesPersonId}/notifications`); + cy.waitForElement(activeList); + cy.waitForElement(availableList); + + cy.get(activeList) + .children() + .its('length') + .then((beforeSize) => { + cy.get(firstAvailableNotification).click(); + cy.get(activeList) + .children() + .should('have.length', beforeSize + 1); + + //Rollback + cy.get(firstActiveNotification).click(); + }); }); }); diff --git a/test/cypress/support/commands.js b/test/cypress/support/commands.js index a725837a1..a67df121e 100755 --- a/test/cypress/support/commands.js +++ b/test/cypress/support/commands.js @@ -91,6 +91,10 @@ Cypress.Commands.add('clickConfirm', () => { cy.get('.q-btn--unelevated > .q-btn__content > .block').click(); }); +Cypress.Commands.add('notificationHas', (selector, text) => { + cy.get(selector).should('have.text', text); +}); + Cypress.Commands.add('fillRow', (rowSelector, data) => { // Usar el selector proporcionado para obtener la fila deseada cy.waitForElement('tbody'); diff --git a/test/vitest/__tests__/pages/Worker/WorkerNotificationsManager.spec.js b/test/vitest/__tests__/pages/Worker/WorkerNotificationsManager.spec.js index 744346078..35ce91e61 100644 --- a/test/vitest/__tests__/pages/Worker/WorkerNotificationsManager.spec.js +++ b/test/vitest/__tests__/pages/Worker/WorkerNotificationsManager.spec.js @@ -1,15 +1,15 @@ 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 { ref } from 'vue'; describe('WorkerNotificationsManager', () => { let vm; - const entityId = 1110; beforeAll(() => { vm = createWrapper(WorkerNotificationsManager, { - propsData: { - id: entityId, + global: { + stubs: ['CrudModel'], }, }).vm; }); @@ -18,83 +18,16 @@ describe('WorkerNotificationsManager', () => { vi.clearAllMocks(); }); - describe('fetch()', () => { - it('should fetch notification subscriptions and role mappings', async () => { - vi.spyOn(axios, 'get') - .mockResolvedValueOnce({ - data: [ - { - id: 1, - name: 'Name 1', - description: 'Description 1', - notificationFk: 1, - active: true - }, - ], - }); - await vm.fetch(); + describe('swapEntry()', () => { + it('should swap notification', async () => { + const from = ref(new Map()); + const to = ref(new Map()); + from.value.set(1, { notificationFk: 1 }); + to.value.set(2, { notificationFk: 2 }); - expect(axios.get).toHaveBeenCalledWith(`NotificationSubscriptions/${entityId}/getList`); - expect(vm.notifications).toEqual([ - { - 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(); + await vm.swapEntry(from.value, to.value, 1); + expect(to.value.size).toBe(2); + expect(from.value.size).toBe(0); }); }); });