#8448 - devToTest #1254

Merged
alexm merged 365 commits from 8448-devToTest into test 2025-01-21 10:44:46 +00:00
11 changed files with 68 additions and 21 deletions
Showing only changes of commit e0fca5d24b - Show all commits

View File

@ -0,0 +1,56 @@
import { createWrapper, axios } from 'app/test/vitest/helper';
import EditForm from 'components/EditTableCellValueForm.vue';
import { vi, afterEach, beforeAll, describe, expect, it } from 'vitest';
const fieldA = 'fieldA';
const fieldB = 'fieldB';
describe('EditForm', () => {
let vm;
const mockRows = [
{ id: 1, itemFk: 101 },
{ id: 2, itemFk: 102 },
];
const mockFieldsOptions = [
{ label: 'Field A', field: fieldA, component: 'input', attrs: {} },
{ label: 'Field B', field: fieldB, component: 'date', attrs: {} },
];
const editUrl = '/api/edit';
beforeAll(() => {
vi.spyOn(axios, 'post').mockResolvedValue({ status: 200 });
vm = createWrapper(EditForm, {
props: {
rows: mockRows,
fieldsOptions: mockFieldsOptions,
editUrl,
},
}).vm;
});
afterEach(() => {
vi.clearAllMocks();
});
describe('onSubmit()', () => {
it('should call axios.post with the correct parameters in the payload', async () => {
const selectedField = { field: fieldA, component: 'input', attrs: {} };
const newValue = 'Test Value';
vm.selectedField = selectedField;
vm.newValue = newValue;
await vm.onSubmit();
const payload = axios.post.mock.calls[0][1];
expect(axios.post).toHaveBeenCalledWith(editUrl, expect.any(Object));
expect(payload.field).toEqual(fieldA);
expect(payload.newValue).toEqual(newValue);
expect(payload.lines).toEqual(expect.arrayContaining(mockRows));
expect(vm.isLoading).toEqual(false);
});
});
});

View File

@ -84,6 +84,7 @@ const columns = computed(() => [
label: t('Creation date'),
format: ({ created }) => toDateHourMin(created),
cardVisible: true,
style: 'color: var(--vn-label-color)',
},
{
align: 'left',

View File

@ -37,7 +37,6 @@ onMounted(async () => {
:label="t('Latin genus name')"
v-model="data.name"
:required="true"
data-cy="AddGenusInput"
/>
</VnRow>
</template>

View File

@ -37,7 +37,6 @@ onMounted(async () => {
:label="t('Latin species name')"
v-model="data.name"
:required="true"
data-cy="AddSpeciesInput"
/>
</VnRow>
</template>

View File

@ -199,7 +199,6 @@ onMounted(async () => {
dense
outlined
rounded
data-cy="ItemFilterCategorySelect"
>
<template #option="scope">
<QItem v-bind="scope.itemProps">
@ -226,7 +225,6 @@ onMounted(async () => {
dense
outlined
rounded
data-cy="ItemFilterTypeSelect"
>
<template #option="scope">
<QItem v-bind="scope.itemProps">

View File

@ -10,9 +10,7 @@ describe('Item shelving', () => {
it('should throw an error if the barcode exists', () => {
cy.get('[href="#/item/1/barcode"]').click();
cy.get('.q-card > .q-btn > .q-btn__content > .q-icon').click();
cy.get(
':nth-child(4) > div.full-width > .q-field > .q-field__inner > .q-field__control > .q-field__control-container > [data-cy="Code_input"]'
).type('1111111111');
cy.dataCy('Code_input').eq(3).type('1111111111');
cy.dataCy('crudModelDefaultSaveBtn').click();
cy.checkNotification('Codes can not be repeated');
});
@ -20,9 +18,7 @@ describe('Item shelving', () => {
it('should create a new barcode', () => {
cy.get('[href="#/item/1/barcode"]').click();
cy.get('.q-card > .q-btn > .q-btn__content > .q-icon').click();
cy.get(
':nth-child(4) > div.full-width > .q-field > .q-field__inner > .q-field__control > .q-field__control-container > [data-cy="Code_input"]'
).type('1231231231');
cy.dataCy('Code_input').eq(3).type('1231231231');
cy.dataCy('crudModelDefaultSaveBtn').click();
cy.checkNotification('Data saved');
});

View File

@ -20,7 +20,7 @@ describe('Item botanical', () => {
it('should create a new Genus', () => {
cy.get('[href="#/item/1/botanical"]').click();
cy.dataCy('Genus_icon').click();
cy.dataCy('AddGenusInput').type('Test');
cy.dataCy('Latin genus name_input').type('Test');
cy.dataCy('FormModelPopup_save').click();
cy.checkNotification('Data created');
});
@ -28,7 +28,7 @@ describe('Item botanical', () => {
it('should create a new specie', () => {
cy.get('[href="#/item/1/botanical"]').click();
cy.dataCy('Species_icon').click();
cy.dataCy('AddSpeciesInput').type('Test specie');
cy.dataCy('Latin species name_input').type('Test specie');
cy.dataCy('FormModelPopup_save').click();
cy.checkNotification('Data created');
});

View File

@ -9,9 +9,9 @@ describe('Item list', () => {
});
it('should filter the items and redirect to the summary', () => {
cy.dataCy('ItemFilterCategorySelect').type('Plant');
cy.dataCy('Category_select').type('Plant');
cy.get('.q-menu .q-item').contains('Plant').click();
cy.dataCy('ItemFilterTypeSelect').type('Anthurium');
cy.dataCy('Type_select').type('Anthurium');
cy.get('.q-menu .q-item').contains('Anthurium').click();
cy.get('.q-virtual-scroll__content > :nth-child(4) > :nth-child(4)').click();
});

View File

@ -9,9 +9,7 @@ describe('Item tax', () => {
it('should modify the tax for Spain', () => {
cy.get('[href="#/item/1/tax"]').click();
cy.get(
':nth-child(1) > .q-select > .q-field__inner > .q-field__control > .q-field__control-container > .q-field__native > [data-cy="Class_select"]'
).type('General VAT{enter}');
cy.dataCy('Class_select').eq(1).type('General VAT{enter}');
cy.dataCy('crudModelDefaultSaveBtn').click();
cy.checkNotification('Data saved');
});

View File

@ -16,17 +16,17 @@ describe('VnSearchBar', () => {
});
it('should stay on the list page if there are several results or none', () => {
cy.writeSearchbar('salesA{enter}');
cy.typeSearchbar('salesA{enter}');
checkTableLength(2);
cy.clearSearchbar();
cy.writeSearchbar('0{enter}');
cy.typeSearchbar('0{enter}');
checkTableLength(0);
});
const searchAndCheck = (searchTerm, expectedText) => {
cy.clearSearchbar();
cy.writeSearchbar(`${searchTerm}{enter}`);
cy.typeSearchbar(`${searchTerm}{enter}`);
cy.get(idGap).should('have.text', expectedText);
};

View File

@ -280,7 +280,7 @@ Cypress.Commands.add('clearSearchbar', (element) => {
).clear();
});
Cypress.Commands.add('writeSearchbar', (value) => {
Cypress.Commands.add('typeSearchbar', (value) => {
cy.get('#searchbar > form > div:nth-child(1) > label > div:nth-child(1) input').type(
value
);