forked from verdnatura/salix-front
Merge pull request '#6384 Redirect to summary when route changes' (!149) from 6384_vnSearchbar_redirect into dev
Reviewed-on: verdnatura/salix-front#149 Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
commit
76b3f2295a
|
@ -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",
|
||||
|
|
|
@ -87,15 +87,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);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
/// <reference types="cypress" />
|
||||
describe('VnSearchBar', () => {
|
||||
beforeEach(() => {
|
||||
cy.login('developer');
|
||||
cy.visit('/');
|
||||
});
|
||||
|
||||
it('should redirect to new customer', () => {
|
||||
cy.visit('#/customer/1112/basic-data')
|
||||
cy.openLeftMenu();
|
||||
cy.get('.q-item > .q-item__label').should('have.text',' #1112')
|
||||
cy.closeLeftMenu();
|
||||
cy.clearSearchbar();
|
||||
cy.writeSearchbar('1{enter}');
|
||||
cy.openLeftMenu();
|
||||
cy.get('.q-item > .q-item__label').should('have.text',' #1')
|
||||
cy.closeLeftMenu();
|
||||
});
|
||||
});
|
|
@ -163,6 +163,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);
|
||||
});
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
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';
|
||||
|
||||
|
||||
describe('VnSearchBar', () => {
|
||||
let vm;
|
||||
let wrapper;
|
||||
|
||||
beforeAll(() => {
|
||||
wrapper = createWrapper(VnSearchbar, {
|
||||
propsData: {
|
||||
dataKey: 'CustomerList',
|
||||
label: 'Search customer',
|
||||
info: 'Info customer',
|
||||
},
|
||||
});
|
||||
vm = wrapper.vm;
|
||||
vm.route.matched = [
|
||||
{
|
||||
path: '/',
|
||||
},
|
||||
{
|
||||
path: '/customer',
|
||||
},
|
||||
{
|
||||
path: '/customer/:id',
|
||||
},
|
||||
{
|
||||
path: '/customer/:id/basic-data',
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
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');
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue