diff --git a/src/components/__tests__/UserPanel.spec.js b/src/components/__tests__/UserPanel.spec.js new file mode 100644 index 000000000..ac20f911e --- /dev/null +++ b/src/components/__tests__/UserPanel.spec.js @@ -0,0 +1,61 @@ +import { vi, describe, expect, it, beforeEach, beforeAll, afterEach } from 'vitest'; +import { createWrapper } from 'app/test/vitest/helper'; +import UserPanel from 'src/components/UserPanel.vue'; +import axios from 'axios'; +import { useState } from 'src/composables/useState'; + +describe('UserPanel', () => { + let wrapper; + let vm; + let state; + + beforeEach(() => { + wrapper = createWrapper(UserPanel, {}); + state = useState(); + state.setUser({ + id: 115, + name: 'itmanagement', + nickname: 'itManagementNick', + lang: 'en', + darkMode: false, + companyFk: 442, + warehouseFk: 1, + }); + wrapper = wrapper.wrapper; + vm = wrapper.vm; + }); + + afterEach(() => { + vi.clearAllMocks(); + }); + + it('should fetch warehouses data on mounted', async () => { + const fetchData = wrapper.findComponent({ name: 'FetchData' }); + expect(fetchData.props('url')).toBe('Warehouses'); + expect(fetchData.props('autoLoad')).toBe(true); + }); + + it('should toggle dark mode correctly and update preferences', async () => { + await vm.saveDarkMode(true); + expect(axios.patch).toHaveBeenCalledWith('/UserConfigs/115', { darkMode: true }); + expect(vm.user.darkMode).toBe(true); + vm.updatePreferences(); + expect(vm.darkMode).toBe(true); + }); + + it('should change user language and update preferences', async () => { + const userLanguage = 'es'; + await vm.saveLanguage(userLanguage); + expect(axios.patch).toHaveBeenCalledWith('/VnUsers/115', { lang: userLanguage }); + expect(vm.user.lang).toBe(userLanguage); + vm.updatePreferences(); + expect(vm.locale).toBe(userLanguage); + }); + + it('should update user data', async () => { + const key = 'name'; + const value = 'itboss'; + await vm.saveUserData(key, value); + expect(axios.post).toHaveBeenCalledWith('UserConfigs/setUserConfig', { [key]: value }); + }); +}); diff --git a/src/pages/Entry/EntryBuysTableDialog.vue b/src/pages/Entry/EntryBuysTableDialog.vue index a2d8c9117..86a9b018f 100644 --- a/src/pages/Entry/EntryBuysTableDialog.vue +++ b/src/pages/Entry/EntryBuysTableDialog.vue @@ -134,6 +134,7 @@ function downloadCSV(rows) { @click=" openReport(`Entries/${entityId}/labelSupplier`) " + data-cy="printLabelsBtn" /> diff --git a/src/pages/Item/Card/ItemDiary.vue b/src/pages/Item/Card/ItemDiary.vue index c2f2c19a0..4b6775183 100644 --- a/src/pages/Item/Card/ItemDiary.vue +++ b/src/pages/Item/Card/ItemDiary.vue @@ -125,7 +125,7 @@ onMounted(async () => { inventoriedDate.value = (await axios.get('Configs/findOne')).data?.inventoried || today; - if (query.warehouseFk) ref.warehouseFk = query.warehouseFk; + if (query.warehouseFk) ref.warehouseFk = +query.warehouseFk; else if (!ref.warehouseFk && user.value) ref.warehouseFk = user.value.warehouseFk; if (ref.date) showWhatsBeforeInventory.value = true; ref.itemFk = route.params.id; @@ -143,7 +143,7 @@ onMounted(async () => { const fetchItemBalances = async () => await arrayDataItemBalances.fetch({}); const getBadgeAttrs = (_date) => { - const isSameDate = date.isSameDate(today.value, _date); + const isSameDate = date.isSameDate(today, _date); const attrs = { 'text-color': isSameDate ? 'black' : 'white', color: isSameDate ? 'warning' : 'transparent', @@ -153,8 +153,6 @@ const getBadgeAttrs = (_date) => { const scrollToToday = async () => { await nextTick(); - const today = Date.vnNew(); - today.setHours(0, 0, 0, 0); const todayCell = document.querySelector(`td[data-date="${today.toISOString()}"]`); if (todayCell) { todayCell.scrollIntoView({ behavior: 'smooth', block: 'center' }); diff --git a/src/pages/Order/OrderList.vue b/src/pages/Order/OrderList.vue index 6e4f0aac8..21cb5ed7e 100644 --- a/src/pages/Order/OrderList.vue +++ b/src/pages/Order/OrderList.vue @@ -81,7 +81,7 @@ const columns = computed(() => [ label: t('module.created'), component: 'date', cardVisible: true, - format: (row) => toDateTimeFormat(row?.landed), + format: (row) => toDateTimeFormat(row?.created), columnField: { component: null, }, diff --git a/test/cypress/integration/client/clientList.spec.js b/test/cypress/integration/client/clientList.spec.js index 150f4a918..f2e3671ba 100644 --- a/test/cypress/integration/client/clientList.spec.js +++ b/test/cypress/integration/client/clientList.spec.js @@ -62,7 +62,7 @@ describe('Client list', () => { it('Client founded create order', () => { const search = 'Jessica Jones'; cy.searchByLabel('Name', search); - cy.get('[href="#/order/list?createForm={%22clientFk%22:1110,%22addressId%22:10}"]').click(); + cy.clickButtonWith('icon', 'icon-basketadd'); cy.waitForElement('#formModel'); cy.waitForElement('.q-form'); cy.checkValueForm(1, search); diff --git a/test/cypress/integration/entry/myEntry.spec.js b/test/cypress/integration/entry/myEntry.spec.js index c25476419..492e1b491 100644 --- a/test/cypress/integration/entry/myEntry.spec.js +++ b/test/cypress/integration/entry/myEntry.spec.js @@ -8,12 +8,12 @@ describe('EntryMy when is supplier', () => { }, }); }); - // https://redmine.verdnatura.es/issues/8418 - it.skip('should open buyLabel when is supplier', () => { + + it('should open buyLabel when is supplier', () => { cy.get( '[to="/null/3"] > .q-card > .column > .q-btn > .q-btn__content > .q-icon' ).click(); - cy.get('.q-card__actions > .q-btn').click(); + cy.dataCy('printLabelsBtn').click(); cy.window().its('open').should('be.called'); }); }); diff --git a/test/cypress/integration/item/itemTag.spec.js b/test/cypress/integration/item/itemTag.spec.js index 6748b748b..10d68d08a 100644 --- a/test/cypress/integration/item/itemTag.spec.js +++ b/test/cypress/integration/item/itemTag.spec.js @@ -12,28 +12,22 @@ describe('Item tag', () => { cy.get('.q-page-sticky > div').click(); cy.dataCy('Tag_select').eq(7).type('Tallos'); cy.get('.q-menu .q-item').contains('Tallos').click(); - cy.get( - ':nth-child(8) > [label="Value"] > .q-field > .q-field__inner > .q-field__control > .q-field__control-container > [data-cy="Value_input"]' - ).type('1'); + cy.get(':nth-child(8) > [label="Value"]').type('1'); +cy.dataCy('crudModelDefaultSaveBtn').click(); cy.checkNotification("The tag or priority can't be repeated for an item"); }); - // https://redmine.verdnatura.es/issues/8422 + it('should add a new tag', () => { cy.get('.q-page').should('be.visible'); cy.get('.q-page-sticky > div').click(); cy.get('.q-page-sticky > div').click(); cy.dataCy('Tag_select').eq(7).click(); - cy.get('.q-menu .q-item').contains('Ancho de la base').click(); - cy.get( - ':nth-child(8) > [label="Value"] > .q-field > .q-field__inner > .q-field__control > .q-field__control-container > [data-cy="Value_input"]' - ).type('50'); + cy.get('.q-menu .q-item').contains('Ancho de la base').type('{enter}'); + cy.get(':nth-child(8) > [label="Value"]').type('50'); cy.dataCy('crudModelDefaultSaveBtn').click(); cy.checkNotification('Data saved'); - cy.get( - '[data-cy="itemTags"] > :nth-child(7) > .justify-center > .q-icon' - ).click(); + cy.dataCy('itemTags').children(':nth-child(8)').find('.justify-center > .q-icon').click(); cy.dataCy('VnConfirm_confirm').click(); cy.checkNotification('Data saved'); }); -}); +}); \ No newline at end of file diff --git a/test/cypress/support/commands.js b/test/cypress/support/commands.js index c15ee6bb6..40f830cde 100755 --- a/test/cypress/support/commands.js +++ b/test/cypress/support/commands.js @@ -317,14 +317,13 @@ Cypress.Commands.add('openActionDescriptor', (opt) => { cy.openActionsDescriptor(); const listItem = '[role="menu"] .q-list .q-item'; cy.contains(listItem, opt).click(); - 1; }); Cypress.Commands.add('openActionsDescriptor', () => { cy.get('[data-cy="descriptor-more-opts"]').click(); }); -Cypress.Commands.add('clickButtonsDescriptor', (id) => { +Cypress.Commands.add('clickButtonDescriptor', (id) => { cy.get(`.actions > .q-card__actions> .q-btn:nth-child(${id})`) .invoke('removeAttr', 'target') .click(); @@ -376,3 +375,21 @@ Cypress.Commands.add('addBtnClick', () => { .and('be.visible') .click(); }); + +Cypress.Commands.add('clickButtonWith', (type, value) => { + switch (type) { + case 'icon': + cy.clickButtonWithIcon(value); + break; + + default: + cy.clickButtonWithText(value); + break; + } +}); +Cypress.Commands.add('clickButtonWithIcon', (iconClass) => { + cy.get(`.q-icon.${iconClass}`).parent().click(); +}); +Cypress.Commands.add('clickButtonWithText', (buttonText) => { + cy.get('.q-btn').contains(buttonText).click(); +});