salix-front/test/cypress/integration/vnComponent/vnLocation.spec.js

211 lines
8.9 KiB
JavaScript
Raw Normal View History

describe('VnLocation', () => {
2024-07-29 13:03:21 +00:00
const locationOptions = '[role="listbox"] > div.q-virtual-scroll__content > .q-item';
const dialogInputs = '.q-dialog label input';
2024-07-29 13:03:21 +00:00
const createLocationButton = '.q-form > .q-card > .vn-row:nth-child(6) .--add-icon';
const inputLocation = '.q-form input[aria-label="Location"]';
2024-09-26 21:39:14 +00:00
const createForm = {
prefix: '.q-dialog__inner > .column > #formModel > .q-card',
sufix: ' .q-field__inner > .q-field__control',
};
describe('CreateFormDialog ', () => {
beforeEach(() => {
cy.viewport(1280, 720);
cy.login('developer');
cy.visit('/#/supplier/567/fiscal-data', { timeout: 7000 });
2024-10-29 13:23:06 +00:00
cy.domContentLoad();
2024-09-26 21:39:14 +00:00
cy.get(createLocationButton).click();
});
it('should filter provinces based on selected country', () => {
// Select a country
cy.selectOption(
`${createForm.prefix} > :nth-child(5) > :nth-child(3) > ${createForm.sufix}`,
2024-09-26 21:39:14 +00:00
'Ecuador'
);
// Verify that provinces are filtered
cy.get(
`${createForm.prefix} > :nth-child(5) > :nth-child(3) > ${createForm.sufix}`
2024-09-26 21:39:14 +00:00
).should('have.length', 1);
// Verify that towns are filtered
cy.get(
`${createForm.prefix} > :nth-child(4) > :nth-child(2) > ${createForm.sufix}`
2024-09-26 21:39:14 +00:00
).should('have.length', 1);
});
it.only('should filter towns based on selected province', () => {
2024-09-26 21:39:14 +00:00
// Select a country
cy.selectOption(
`${createForm.prefix} > :nth-child(5) > :nth-child(3) > ${createForm.sufix}`,
2024-09-26 21:39:14 +00:00
'Ecuador'
);
// Verify that provinces are filtered
cy.get(
`${createForm.prefix} > :nth-child(5) > :nth-child(2) > ${createForm.sufix}`
2024-09-26 21:39:14 +00:00
).should('have.length', 1);
// Verify that towns are filtered
cy.get(
`${createForm.prefix} > :nth-child(4) > :nth-child(2) > ${createForm.sufix}`
2024-09-26 21:39:14 +00:00
).should('have.length', 1);
});
2024-09-30 22:24:34 +00:00
it('should pass selected country', () => {
// Select a country
const country = 'Ecuador';
const province = 'Province five';
cy.selectOption(
`${createForm.prefix} > :nth-child(5) > :nth-child(3) > ${createForm.sufix}`,
2024-09-30 22:24:34 +00:00
country
);
cy.selectOption(
`${createForm.prefix} > :nth-child(4) > .q-select > ${createForm.sufix}`,
province
);
cy.get(
`${createForm.prefix} > :nth-child(4) > .q-select > ${createForm.sufix} > :nth-child(3) > .q-icon`
).click();
cy.get(
2024-10-08 11:07:05 +00:00
`#q-portal--dialog--5 > .q-dialog > ${createForm.prefix} > .vn-row > .q-select > ${createForm.sufix} > :nth-child(1) input`
2024-09-30 22:24:34 +00:00
).should('have.value', province);
});
2024-09-26 21:39:14 +00:00
});
describe('Worker Create', () => {
beforeEach(() => {
cy.viewport(1280, 720);
cy.login('developer');
cy.visit('/#/worker/create', { timeout: 5000 });
cy.waitForElement('.q-card');
2024-09-26 21:39:14 +00:00
cy.get(inputLocation).click();
});
it('Show all options', function () {
cy.get(locationOptions).should('have.length.at.least', 5);
});
it('input filter location as "al"', function () {
2024-09-26 21:39:14 +00:00
// cy.get(inputLocation).click();
cy.get(inputLocation).clear();
cy.get(inputLocation).type('al');
2024-07-24 12:58:51 +00:00
cy.get(locationOptions).should('have.length.at.least', 4);
});
it('input filter location as "ecuador"', function () {
2024-09-26 21:39:14 +00:00
// cy.get(inputLocation).click();
cy.get(inputLocation).clear();
cy.get(inputLocation).type('ecuador');
cy.get(locationOptions).should('have.length.at.least', 1);
});
});
describe('Fiscal-data', () => {
beforeEach(() => {
cy.viewport(1280, 720);
cy.login('developer');
cy.visit('/#/supplier/567/fiscal-data', { timeout: 7000 });
cy.waitForElement('.q-form');
});
2024-09-23 11:41:30 +00:00
it('Find by postalCode', () => {
2024-09-13 08:32:40 +00:00
const postCode = '46600';
2024-09-23 11:41:30 +00:00
const postCodeLabel = '46600, Valencia(Province one), España';
2024-09-13 08:32:40 +00:00
const firstOption = '[role="listbox"] .q-item:nth-child(1)';
cy.get(inputLocation).click();
cy.get(inputLocation).clear();
cy.get(inputLocation).type(postCode);
2024-09-23 11:41:30 +00:00
cy.get(locationOptions)
.get(':nth-child(1)')
.should('have.length.at.least', 2);
cy.get(
firstOption.concat(' > .q-item__section > .q-item__label--caption')
).should('have.text', postCodeLabel);
2024-09-13 08:32:40 +00:00
cy.get(firstOption).click();
cy.get('.q-btn-group > .q-btn--standard > .q-btn__content > .q-icon').click();
cy.reload();
cy.waitForElement('.q-form');
2024-09-23 11:41:30 +00:00
cy.get(inputLocation).should('have.value', postCodeLabel);
2024-09-13 08:32:40 +00:00
});
2024-07-29 13:03:21 +00:00
it('Create postCode', () => {
2024-07-30 08:01:16 +00:00
const postCode = '1234475';
const province = 'Valencia';
2024-09-13 08:32:40 +00:00
cy.get(createLocationButton).click();
cy.get('.q-card > h1').should('have.text', 'New postcode');
2024-07-29 13:03:21 +00:00
cy.get(dialogInputs).eq(0).clear();
cy.get(dialogInputs).eq(0).type(postCode);
cy.selectOption(
2024-09-26 21:39:14 +00:00
`${createForm.prefix} > :nth-child(4) > .q-select > ${createForm.sufix}`,
2024-07-30 08:01:16 +00:00
province
);
cy.get('.q-mt-lg > .q-btn--standard').click();
2024-09-26 21:39:14 +00:00
cy.get(`${createForm.prefix}`).should('not.exist');
2024-10-08 11:07:05 +00:00
cy.waitForElement('.q-form');
2024-07-30 08:01:16 +00:00
checkVnLocation(postCode, province);
});
it('Create city without country', () => {
const cityName = 'Saskatchew'.concat(Math.random(1 * 100));
2024-09-13 08:32:40 +00:00
cy.get(createLocationButton).click();
2024-07-30 08:01:16 +00:00
cy.get(
2024-09-26 21:39:14 +00:00
`${createForm.prefix} > :nth-child(4) > .q-select > ${createForm.sufix} > :nth-child(2) > .q-icon`
2024-07-30 08:01:16 +00:00
).click();
2024-10-08 11:07:05 +00:00
cy.selectOption('#q-portal--dialog--3 .q-select', 'one');
cy.get('#q-portal--dialog--3 .q-input').type(cityName);
2024-10-08 11:07:05 +00:00
cy.get('#q-portal--dialog--3 .q-btn--standard').click();
});
it('Create province without country', () => {
const provinceName = 'Saskatchew'.concat(Math.random(1 * 100));
cy.get(createLocationButton).click();
cy.get(
`${createForm.prefix} > :nth-child(5) > .q-select > ${createForm.sufix} > :nth-child(2) `
)
.eq(0)
.click();
cy.selectOption('#q-portal--dialog--3 .q-select', 'one');
cy.countSelectOptions('#q-portal--dialog--3 .q-select', 4);
cy.get('#q-portal--dialog--3 .q-input').type(provinceName);
cy.get('#q-portal--dialog--3 .q-btn--standard').click();
});
it('Create city with country', () => {
const cityName = 'Saskatchew'.concat(Math.random(1 * 100));
cy.get(createLocationButton).click();
cy.selectOption(
`${createForm.prefix} > :nth-child(5) > :nth-child(3) `,
'Italia'
);
cy.get(
`${createForm.prefix} > :nth-child(4) > .q-select > ${createForm.sufix} > :nth-child(2) > .q-icon`
).click();
cy.selectOption('#q-portal--dialog--4 .q-select', 'Province four');
cy.countSelectOptions('#q-portal--dialog--4 .q-select', 1);
cy.get('#q-portal--dialog--4 .q-input').type(cityName);
cy.get('#q-portal--dialog--4 .q-btn--standard').click();
});
it('Create province with country', () => {
const provinceName = 'Saskatchew'.concat(Math.random(1 * 100));
cy.get(createLocationButton).click();
cy.selectOption(
`${createForm.prefix} > :nth-child(5) > :nth-child(3) `,
'España'
);
cy.get(
`${createForm.prefix} > :nth-child(5) > .q-select > ${createForm.sufix} > :nth-child(2) `
)
.eq(0)
.click();
cy.selectOption('#q-portal--dialog--4 .q-select', 'one');
cy.countSelectOptions('#q-portal--dialog--4 .q-select', 2);
cy.get('#q-portal--dialog--4 .q-input').type(provinceName);
cy.get('#q-portal--dialog--4 .q-btn--standard').click();
});
2024-07-30 08:01:16 +00:00
function checkVnLocation(postCode, province) {
2024-09-26 21:39:14 +00:00
cy.get(`${createForm.prefix}`).should('not.exist');
2024-07-30 08:01:16 +00:00
cy.get('.q-form > .q-card > .vn-row:nth-child(6)')
.find('input')
.invoke('val')
.then((text) => {
expect(text).to.contain(postCode);
expect(text).to.contain(province);
});
}
});
});