feat: refs #6273 add test & improve form
gitea/salix-front/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Jorge Penadés 2024-06-10 13:54:02 +02:00
parent 049783b16c
commit d81ce9fe95
3 changed files with 102 additions and 4 deletions

View File

@ -82,7 +82,12 @@ onBeforeMount(async () => {
/> />
</template> </template>
</VnSubToolbar> </VnSubToolbar>
<FormModel url-create="Workers/new" model="worker" :form-initial-data="formData"> <FormModel
url-create="Workers/new"
model="worker"
:form-initial-data="formData"
@on-data-saved="({ id }) => $router.push({ path: `/worker/${id}` })"
>
<template #form="{ data, validate }"> <template #form="{ data, validate }">
<VnRow> <VnRow>
<VnInput <VnInput
@ -194,7 +199,7 @@ onBeforeMount(async () => {
hide-selected hide-selected
:rules="validate('Worker.payMethodFk')" :rules="validate('Worker.payMethodFk')"
:disable="formData.isFreelance" :disable="formData.isFreelance"
@update:model-value="(val) => (formData.payMethodFk = val ?? 0)" @update:model-value="(val) => !val && delete formData.payMethodFk"
/> />
<VnInput <VnInput
v-model="data.iban" v-model="data.iban"

View File

@ -0,0 +1,59 @@
describe('WorkerCreate', () => {
const externalRadio = '.q-toolbar .q-radio:nth-child(2)';
const notification = '.q-notification__message';
const developerBossId = 120;
const internal = {
Fi: { val: '78457139E' },
'Web user': { val: 'defaulterworker' },
Name: { val: 'DEFAULT' },
'Last name': { val: 'WORKER' },
'Personal email': { val: 'defaultWorker@mydomain.com' },
Street: { val: 'S/ DEFAULTWORKERSTREET' },
Location: { val: 1, type: 'select' },
Phone: { val: '123456789' },
'Worker code': { val: 'DWW' },
Boss: { val: developerBossId, type: 'select' },
Birth: { val: '2022-12-11T23:00:00.000Z', type: 'date', day: 11 },
};
const external = {
Fi: { val: 'Z4531219V' },
'Web user': { val: 'pepe' },
Name: { val: 'PEPE' },
'Last name': { val: 'GARCIA' },
'Personal email': { val: 'pepe@gmail.com' },
'Worker code': { val: 'PG' },
Boss: { val: developerBossId, type: 'select' },
};
beforeEach(() => {
cy.viewport(1280, 720);
cy.login('hr');
cy.visit('/#/worker/create');
});
it('should throw an error if a pay method has not been selected', () => {
cy.fillInForm(internal);
cy.saveCard();
cy.get(notification).should(
'contains.text',
'That payment method requires an IBAN'
);
});
it('should create an internal', () => {
cy.fillInForm({
...internal,
'Pay method': { val: 'PayMethod one', type: 'select' },
});
cy.saveCard();
cy.get(notification).should('contains.text', 'Data created');
});
it('should create an external', () => {
cy.get(externalRadio).click();
cy.fillInForm(external);
cy.saveCard();
cy.get(notification).should('contains.text', 'Data created');
});
});

View File

@ -86,6 +86,36 @@ Cypress.Commands.add('selectOption', (selector, option) => {
cy.get('.q-menu .q-item').contains(option).click(); cy.get('.q-menu .q-item').contains(option).click();
}); });
Cypress.Commands.add('fillInForm', (obj, form = '.q-form > .q-card') => {
const days = '.q-date__calendar-days .q-date__calendar-item--in';
cy.waitForElement('.q-form > .q-card');
cy.get(`${form} input`).each(([el]) => {
cy.wrap(el)
.invoke('attr', 'aria-label')
.then((ariaLabel) => {
const field = obj[ariaLabel];
if (!field) return;
const { type, val, day } = field;
switch (type) {
case 'select':
cy.wrap(el).type(val);
cy.get('.q-menu .q-item').contains(val).click();
break;
case 'date':
cy.wrap(el).click();
cy.get(days)
.eq(day ? day - 1 : 0)
.click();
break;
default:
cy.wrap(el).type(val);
break;
}
});
});
});
Cypress.Commands.add('checkOption', (selector) => { Cypress.Commands.add('checkOption', (selector) => {
cy.get(selector).find('.q-checkbox__inner').click(); cy.get(selector).find('.q-checkbox__inner').click();
}); });
@ -198,11 +228,15 @@ Cypress.Commands.add('closeSideMenu', (element) => {
Cypress.Commands.add('clearSearchbar', (element) => { Cypress.Commands.add('clearSearchbar', (element) => {
if (element) cy.waitForElement(element); if (element) cy.waitForElement(element);
cy.get('#searchbar > form > div:nth-child(1) > label > div:nth-child(1) input').clear(); cy.get(
'#searchbar > form > div:nth-child(1) > label > div:nth-child(1) input'
).clear();
}); });
Cypress.Commands.add('writeSearchbar', (value) => { Cypress.Commands.add('writeSearchbar', (value) => {
cy.get('#searchbar > form > div:nth-child(1) > label > div:nth-child(1) input').type(value); cy.get('#searchbar > form > div:nth-child(1) > label > div:nth-child(1) input').type(
value
);
}); });
Cypress.Commands.add('validateContent', (selector, expectedValue) => { Cypress.Commands.add('validateContent', (selector, expectedValue) => {
cy.get(selector).should('have.text', expectedValue); cy.get(selector).should('have.text', expectedValue);