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/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 28e0a747f..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.skip('should add a new tag', () => { + + 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