From 8861ee038dfbf44da1b97f8cf91a6bb4517f86ab Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 9 Jan 2024 10:35:39 +0100 Subject: [PATCH 1/8] refs #6384 fix: redirect to same path when id change --- src/components/ui/VnSearchbar.vue | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/components/ui/VnSearchbar.vue b/src/components/ui/VnSearchbar.vue index 35f6c1548..bb54f6d31 100644 --- a/src/components/ui/VnSearchbar.vue +++ b/src/components/ui/VnSearchbar.vue @@ -72,15 +72,10 @@ async function search() { }); if (!props.redirect) return; - const rows = store.data; - const module = route.matched[1]; - if (rows.length === 1) { - const [firstRow] = rows; - await router.push({ path: `${module.path}/${firstRow.id}` }); - } else if (route.matched.length > 3) { - await router.push({ path: `/${module.path}` }); - arrayData.updateStateParams(); - } + const { matched: matches } = route; + const { path } = matches[matches.length-1]; + const newRoute = path.replace(':id', searchText.value); + await router.push(newRoute); } From d139d670f17bc8f239455937b7ed47b12e41d20e Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 9 Jan 2024 10:37:59 +0100 Subject: [PATCH 2/8] refs #6384 perf: replace code with VnSubToolbar --- src/pages/Claim/Card/ClaimCard.vue | 1 - src/pages/Customer/Card/CustomerCard.vue | 7 ++----- src/pages/InvoiceIn/Card/InvoiceInCard.vue | 7 ++----- src/pages/Supplier/Card/SupplierCard.vue | 7 ++----- src/pages/Ticket/Card/TicketCard.vue | 7 ++----- src/pages/Travel/Card/TravelCard.vue | 7 ++----- src/pages/Worker/Card/WorkerCard.vue | 7 ++----- 7 files changed, 12 insertions(+), 31 deletions(-) diff --git a/src/pages/Claim/Card/ClaimCard.vue b/src/pages/Claim/Card/ClaimCard.vue index b6c948c96..8ebfcc285 100644 --- a/src/pages/Claim/Card/ClaimCard.vue +++ b/src/pages/Claim/Card/ClaimCard.vue @@ -1,6 +1,5 @@ @@ -11,11 +12,7 @@ const stateStore = useStateStore(); - -
- -
-
+
diff --git a/src/pages/Worker/Card/WorkerCard.vue b/src/pages/Worker/Card/WorkerCard.vue index 972eb52ec..19397b62e 100644 --- a/src/pages/Worker/Card/WorkerCard.vue +++ b/src/pages/Worker/Card/WorkerCard.vue @@ -4,6 +4,7 @@ import { useStateStore } from 'stores/useStateStore'; import WorkerDescriptor from './WorkerDescriptor.vue'; import LeftMenu from 'components/LeftMenu.vue'; import VnSearchbar from 'src/components/ui/VnSearchbar.vue'; +import VnSubToolbar from 'src/components/ui/VnSubToolbar.vue'; const stateStore = useStateStore(); const { t } = useI18n(); @@ -26,11 +27,7 @@ const { t } = useI18n(); - -
- -
-
+
From 762daa620b6e62da265491912e915b948e33fcde Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 9 Jan 2024 12:06:17 +0100 Subject: [PATCH 3/8] refs #6384 test: e2e --- test/cypress/integration/vnSearchBar.spec.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 test/cypress/integration/vnSearchBar.spec.js diff --git a/test/cypress/integration/vnSearchBar.spec.js b/test/cypress/integration/vnSearchBar.spec.js new file mode 100644 index 000000000..6a769c9d9 --- /dev/null +++ b/test/cypress/integration/vnSearchBar.spec.js @@ -0,0 +1,20 @@ +/// +describe('VnSearchBar', () => { + beforeEach(() => { + cy.login('developer'); + cy.visit('/'); + }); + + it('should redirect to new customer', () => { + cy.visit('#/customer/1112/basic-data') + cy.get('.q-toolbar > .q-btn--round.q-btn--dense > .q-btn__content > .q-icon').click(); + cy.get('.q-item > .q-item__label').should('have.text',' #1112') + cy.get('.fullscreen').click(); + cy.get('#searchbar > form > label > div:nth-child(1) input').clear(); + cy.get('#searchbar > form > label > div:nth-child(1) input').type('1{enter}'); + cy.get('.q-toolbar > .q-btn--round.q-btn--dense > .q-btn__content > .q-icon').click(); + cy.get('.q-item > .q-item__label').should('have.text',' #1') + }); + + + }); From b4f330a2378ea217ee8e10a4d8f955b055a33e8b Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 9 Jan 2024 12:20:56 +0100 Subject: [PATCH 4/8] refs #6384 test: e2e --- test/cypress/integration/vnSearchBar.spec.js | 15 +++++++-------- test/cypress/support/commands.js | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/test/cypress/integration/vnSearchBar.spec.js b/test/cypress/integration/vnSearchBar.spec.js index 6a769c9d9..d6dea0780 100644 --- a/test/cypress/integration/vnSearchBar.spec.js +++ b/test/cypress/integration/vnSearchBar.spec.js @@ -7,14 +7,13 @@ describe('VnSearchBar', () => { it('should redirect to new customer', () => { cy.visit('#/customer/1112/basic-data') - cy.get('.q-toolbar > .q-btn--round.q-btn--dense > .q-btn__content > .q-icon').click(); + cy.openLeftMenu(); cy.get('.q-item > .q-item__label').should('have.text',' #1112') - cy.get('.fullscreen').click(); - cy.get('#searchbar > form > label > div:nth-child(1) input').clear(); - cy.get('#searchbar > form > label > div:nth-child(1) input').type('1{enter}'); - cy.get('.q-toolbar > .q-btn--round.q-btn--dense > .q-btn__content > .q-icon').click(); + cy.closeLeftMenu(); + cy.clearSearchbar(); + cy.writeSearchbar('1{enter}'); + cy.openLeftMenu(); cy.get('.q-item > .q-item__label').should('have.text',' #1') + cy.closeLeftMenu(); }); - - - }); +}); diff --git a/test/cypress/support/commands.js b/test/cypress/support/commands.js index 4dfde6e21..7effb94a6 100755 --- a/test/cypress/support/commands.js +++ b/test/cypress/support/commands.js @@ -166,6 +166,23 @@ Cypress.Commands.add('openRightMenu', (element) => { cy.get('#actions-append').click(); }); +Cypress.Commands.add('openLeftMenu', (element) => { + if (element) cy.waitForElement(element); + cy.get('.q-toolbar > .q-btn--round.q-btn--dense > .q-btn__content > .q-icon').click(); +}); +Cypress.Commands.add('closeLeftMenu', (element) => { + if (element) cy.waitForElement(element); + cy.get('.fullscreen').click(); +}); + +Cypress.Commands.add('clearSearchbar', (element) => { + if (element) cy.waitForElement(element); + cy.get('#searchbar > form > label > div:nth-child(1) input').clear(); +}); + +Cypress.Commands.add('writeSearchbar', (value) => { + cy.get('#searchbar > form > label > div:nth-child(1) input').type(value); +}); Cypress.Commands.add('validateContent', (selector, expectedValue) => { cy.get(selector).should('have.text', expectedValue); }); From ef8e77904d78772a4a2517829f71a205c0b907f3 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 9 Jan 2024 16:54:07 +0100 Subject: [PATCH 5/8] refs #6384 test: vitest --- .../components/common/VnSearchBar.spec.js | 70 +++++++++++++++++++ test/vitest/helper.js | 20 +----- 2 files changed, 71 insertions(+), 19 deletions(-) create mode 100644 test/vitest/__tests__/components/common/VnSearchBar.spec.js diff --git a/test/vitest/__tests__/components/common/VnSearchBar.spec.js b/test/vitest/__tests__/components/common/VnSearchBar.spec.js new file mode 100644 index 000000000..24111e90e --- /dev/null +++ b/test/vitest/__tests__/components/common/VnSearchBar.spec.js @@ -0,0 +1,70 @@ +import { vi, describe, expect, it, beforeAll, beforeEach, afterEach } from 'vitest'; +import { createWrapper, axios } from 'app/test/vitest/helper'; +import VnSearchbar from 'components/ui/VnSearchbar.vue'; + +vi.mock('vue-router', () => ({ + useRouter: () => ({ + push: vi.fn( ), + currentRoute: { + value: { + params: { + id: 11, + }, + }, + }, + }), + useRoute: () => ({ + matched: [ + { + path: '/', + }, + { + path: '/customer', + }, + { + path: '/customer/:id', + }, + { + path: '/customer/:id/basic-data', + }, + ], + query: {}, + params: {}, + }), +})); + +describe('VnSearchBar', () => { + let vm; + let wrapper; + + beforeAll(() => { + wrapper = createWrapper(VnSearchbar, { + propsData: { + dataKey: 'CustomerList', + label: 'Search customer', + info: 'Info customer', + }, + }); + vm = wrapper.vm; + + }); + + afterEach(() => { + vi.clearAllMocks(); + }); + it('should be defined', async () => { + expect(vm.searchText).toBeDefined(); + expect(vm.searchText).toEqual(''); + }); + it('should redirect', async () => { + vi.spyOn(vm.router,'push'); + vm.searchText = '1'; + await vm.search(); + expect(vm.router.push).toHaveBeenCalledWith('/customer/1/basic-data'); + vm.searchText = '1112'; + expect(vm.searchText).toEqual('1112'); + vi.spyOn(vm.router,'push'); + await vm.search(); + expect(vm.router.push).toHaveBeenCalledWith('/customer/1112/basic-data'); + }); +}); diff --git a/test/vitest/helper.js b/test/vitest/helper.js index 89cc640fd..2b8c70a5f 100644 --- a/test/vitest/helper.js +++ b/test/vitest/helper.js @@ -14,25 +14,6 @@ installQuasarPlugin({ }, }); const pinia = createTestingPinia({ createSpy: vi.fn, stubActions: false }); -const mockPush = vi.fn(); - -vi.mock('vue-router', () => ({ - useRouter: () => ({ - push: mockPush, - currentRoute: { - value: { - params: { - id: 1, - }, - }, - }, - }), - useRoute: () => ({ - matched: [], - query: {}, - params: {}, - }), -})); vi.mock('axios'); @@ -74,6 +55,7 @@ export function createWrapper(component, options) { mocks: { t: (tKey) => tKey, $t: (tKey) => tKey, + customRouter: false }, }; From 988c47677b8287f9591e0be543b9b20cb957f35f Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 9 Jan 2024 17:01:11 +0100 Subject: [PATCH 6/8] refs #6384 test: fix vitest --- .../components/common/VnSearchBar.spec.js | 45 ++++++------------- test/vitest/helper.js | 20 ++++++++- 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/test/vitest/__tests__/components/common/VnSearchBar.spec.js b/test/vitest/__tests__/components/common/VnSearchBar.spec.js index 24111e90e..fd0a026ef 100644 --- a/test/vitest/__tests__/components/common/VnSearchBar.spec.js +++ b/test/vitest/__tests__/components/common/VnSearchBar.spec.js @@ -2,36 +2,6 @@ import { vi, describe, expect, it, beforeAll, beforeEach, afterEach } from 'vite import { createWrapper, axios } from 'app/test/vitest/helper'; import VnSearchbar from 'components/ui/VnSearchbar.vue'; -vi.mock('vue-router', () => ({ - useRouter: () => ({ - push: vi.fn( ), - currentRoute: { - value: { - params: { - id: 11, - }, - }, - }, - }), - useRoute: () => ({ - matched: [ - { - path: '/', - }, - { - path: '/customer', - }, - { - path: '/customer/:id', - }, - { - path: '/customer/:id/basic-data', - }, - ], - query: {}, - params: {}, - }), -})); describe('VnSearchBar', () => { let vm; @@ -46,7 +16,20 @@ describe('VnSearchBar', () => { }, }); vm = wrapper.vm; - + vm.route.matched = [ + { + path: '/', + }, + { + path: '/customer', + }, + { + path: '/customer/:id', + }, + { + path: '/customer/:id/basic-data', + }, + ]; }); afterEach(() => { diff --git a/test/vitest/helper.js b/test/vitest/helper.js index 2b8c70a5f..89cc640fd 100644 --- a/test/vitest/helper.js +++ b/test/vitest/helper.js @@ -14,6 +14,25 @@ installQuasarPlugin({ }, }); const pinia = createTestingPinia({ createSpy: vi.fn, stubActions: false }); +const mockPush = vi.fn(); + +vi.mock('vue-router', () => ({ + useRouter: () => ({ + push: mockPush, + currentRoute: { + value: { + params: { + id: 1, + }, + }, + }, + }), + useRoute: () => ({ + matched: [], + query: {}, + params: {}, + }), +})); vi.mock('axios'); @@ -55,7 +74,6 @@ export function createWrapper(component, options) { mocks: { t: (tKey) => tKey, $t: (tKey) => tKey, - customRouter: false }, }; From d4968d060b9181857966784049763fbf707ffb11 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 9 Jan 2024 17:02:21 +0100 Subject: [PATCH 7/8] Revert "refs #6384 perf: replace code with VnSubToolbar" This reverts commit d139d670f17bc8f239455937b7ed47b12e41d20e. --- src/pages/Claim/Card/ClaimCard.vue | 1 + src/pages/Customer/Card/CustomerCard.vue | 7 +++++-- src/pages/InvoiceIn/Card/InvoiceInCard.vue | 7 +++++-- src/pages/Supplier/Card/SupplierCard.vue | 7 +++++-- src/pages/Ticket/Card/TicketCard.vue | 7 +++++-- src/pages/Travel/Card/TravelCard.vue | 7 +++++-- src/pages/Worker/Card/WorkerCard.vue | 7 +++++-- 7 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/pages/Claim/Card/ClaimCard.vue b/src/pages/Claim/Card/ClaimCard.vue index 8ebfcc285..b6c948c96 100644 --- a/src/pages/Claim/Card/ClaimCard.vue +++ b/src/pages/Claim/Card/ClaimCard.vue @@ -1,5 +1,6 @@ @@ -12,7 +11,11 @@ const stateStore = useStateStore(); - + +
+ +
+
diff --git a/src/pages/Worker/Card/WorkerCard.vue b/src/pages/Worker/Card/WorkerCard.vue index 19397b62e..972eb52ec 100644 --- a/src/pages/Worker/Card/WorkerCard.vue +++ b/src/pages/Worker/Card/WorkerCard.vue @@ -4,7 +4,6 @@ import { useStateStore } from 'stores/useStateStore'; import WorkerDescriptor from './WorkerDescriptor.vue'; import LeftMenu from 'components/LeftMenu.vue'; import VnSearchbar from 'src/components/ui/VnSearchbar.vue'; -import VnSubToolbar from 'src/components/ui/VnSubToolbar.vue'; const stateStore = useStateStore(); const { t } = useI18n(); @@ -27,7 +26,11 @@ const { t } = useI18n(); - + +
+ +
+
From 96fdd3f4106b4776f15218536d94f57fcdea1dae Mon Sep 17 00:00:00 2001 From: JAVIER SEGARRA MARTINEZ Date: Thu, 11 Jan 2024 12:35:58 +0000 Subject: [PATCH 8/8] refs #6384 perf: remove unused dependencie --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index c4f5b828a..1d729b82f 100644 --- a/package.json +++ b/package.json @@ -24,8 +24,7 @@ "validator": "^13.9.0", "vue": "^3.3.4", "vue-i18n": "^9.2.2", - "vue-router": "^4.2.1", - "vue-router-mock": "^0.2.0" + "vue-router": "^4.2.1" }, "devDependencies": { "@intlify/unplugin-vue-i18n": "^0.8.1",