refs #5673 fix: crudModel and finish e2e
gitea/salix-front/pipeline/head There was a failure building this commit Details

This commit is contained in:
Alex Moreno 2023-08-24 15:05:31 +02:00
parent 169e4863b2
commit c365682e3c
9 changed files with 53 additions and 51 deletions

View File

@ -98,8 +98,7 @@ async function fetch(data) {
} }
function reset() { function reset() {
state.set($props.model, originalData.value); fetch(originalData.value);
watch(formData.value, () => (hasChanges.value = true));
hasChanges.value = false; hasChanges.value = false;
} }
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
@ -317,7 +316,7 @@ function isEmpty(obj) {
</Teleport> </Teleport>
<QInnerLoading <QInnerLoading
:showing="isLoading" :showing="isLoading"
:label="t('globals.pleaseWait')" :label="t && t('globals.pleaseWait')"
color="primary" color="primary"
/> />
</template> </template>

View File

@ -89,7 +89,11 @@ async function save() {
function reset() { function reset() {
state.set($props.model, originalData.value); state.set($props.model, originalData.value);
originalData.value = JSON.parse(JSON.stringify(originalData.value));
watch(formData.value, () => (hasChanges.value = true)); watch(formData.value, () => (hasChanges.value = true));
emit('onFetch', state.get($props.model));
hasChanges.value = false; hasChanges.value = false;
} }
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
@ -123,7 +127,7 @@ watch(formUrl, async () => {
</QForm> </QForm>
<Teleport to="#st-actions" v-if="stateStore?.isSubToolbarShown()"> <Teleport to="#st-actions" v-if="stateStore?.isSubToolbarShown()">
<div v-if="$props.defaultActions"> <div v-if="$props.defaultActions">
<QBtnGoup push class="q-gutter-x-sm"> <QBtnGroup push class="q-gutter-x-sm">
<slot name="moreActions" /> <slot name="moreActions" />
<QBtn <QBtn
:label="tMobile('globals.reset')" :label="tMobile('globals.reset')"
@ -142,7 +146,7 @@ watch(formUrl, async () => {
:disable="!hasChanges" :disable="!hasChanges"
:title="t('globals.save')" :title="t('globals.save')"
/> />
</QBtnGoup> </QBtnGroup>
</div> </div>
</Teleport> </Teleport>
<SkeletonForm v-if="!formData" /> <SkeletonForm v-if="!formData" />

View File

@ -1,5 +1,5 @@
<script setup> <script setup>
import { ref, toRefs, computed } from 'vue'; import { ref, toRefs, watch } from 'vue';
const emit = defineEmits(['update:modelValue', 'update:options']); const emit = defineEmits(['update:modelValue', 'update:options']);
const $props = defineProps({ const $props = defineProps({
@ -16,10 +16,15 @@ const $props = defineProps({
default: '', default: '',
}, },
}); });
const myOptions = computed(() => $props.options);
const updateValue = (newValue) => emit('update:modelValue', newValue); const updateValue = (newValue) => emit('update:modelValue', newValue);
const { modelValue, optionLabel, options } = toRefs($props); const { modelValue, optionLabel, options } = toRefs($props);
const myOptionsOriginal = ref(JSON.parse(JSON.stringify(options.value))); const myOptions = ref([]);
const myOptionsOriginal = ref([]);
function setOptions(data) {
myOptions.value = JSON.parse(JSON.stringify(data));
myOptionsOriginal.value = JSON.parse(JSON.stringify(data));
}
setOptions(options.value);
const filter = (val, options) => { const filter = (val, options) => {
const search = val.toLowerCase(); const search = val.toLowerCase();
@ -41,6 +46,10 @@ const filterHandler = (val, update) => {
myOptions.value = filter(val, myOptionsOriginal.value); myOptions.value = filter(val, myOptionsOriginal.value);
}); });
}; };
watch(options, (newValue) => {
setOptions(newValue);
});
</script> </script>
<template> <template>

View File

@ -53,6 +53,7 @@ const props = defineProps({
}); });
const emit = defineEmits(['onFetch', 'onPaginate']); const emit = defineEmits(['onFetch', 'onPaginate']);
defineExpose({ fetch });
const isLoading = ref(false); const isLoading = ref(false);
const pagination = ref({ const pagination = ref({
sortBy: props.order, sortBy: props.order,

View File

@ -3,15 +3,13 @@ import { useI18n } from 'vue-i18n';
import axios from 'axios'; import axios from 'axios';
import validator from 'validator'; import validator from 'validator';
const models = ref(null); const models = ref(null);
export function useValidator() { export function useValidator() {
if (!models.value) fetch(); if (!models.value) fetch();
function fetch() { function fetch() {
axios.get('Schemas/ModelInfo') axios.get('Schemas/ModelInfo').then((response) => (models.value = response.data));
.then(response => models.value = response.data)
} }
function validate(propertyRule) { function validate(propertyRule) {
@ -38,19 +36,18 @@ export function useValidator() {
const { t } = useI18n(); const { t } = useI18n();
const validations = function (validation) { const validations = function (validation) {
return { return {
presence: (value) => { presence: (value) => {
let message = `Value can't be empty`; let message = `Value can't be empty`;
if (validation.message) if (validation.message)
message = t(validation.message) || validation.message message = t(validation.message) || validation.message;
return !validator.isEmpty(value ? String(value) : '') || message return !validator.isEmpty(value ? String(value) : '') || message;
}, },
length: (value) => { length: (value) => {
const options = { const options = {
min: validation.min || validation.is, min: validation.min || validation.is,
max: validation.max || validation.is max: validation.max || validation.is,
}; };
value = String(value); value = String(value);
@ -69,14 +66,14 @@ export function useValidator() {
}, },
numericality: (value) => { numericality: (value) => {
if (validation.int) if (validation.int)
return validator.isInt(value) || 'Value should be integer' return validator.isInt(value) || 'Value should be integer';
return validator.isNumeric(value) || 'Value should be a number' return validator.isNumeric(value) || 'Value should be a number';
}, },
custom: (value) => validation.bindedFunction(value) || 'Invalid value' custom: (value) => validation.bindedFunction(value) || 'Invalid value',
}; };
}; };
return { return {
validate validate,
}; };
} }

View File

@ -8,7 +8,6 @@ import { useArrayData } from 'composables/useArrayData';
import { useStateStore } from 'stores/useStateStore'; import { useStateStore } from 'stores/useStateStore';
import CrudModel from 'components/CrudModel.vue'; import CrudModel from 'components/CrudModel.vue';
import FetchData from 'components/FetchData.vue'; import FetchData from 'components/FetchData.vue';
import VnConfirm from 'components/ui/VnConfirm.vue';
import { toDate, toCurrency, toPercentage } from 'filters/index'; import { toDate, toCurrency, toPercentage } from 'filters/index';
import VnDiscount from 'components/common/vnDiscount.vue'; import VnDiscount from 'components/common/vnDiscount.vue';
@ -17,6 +16,7 @@ import ClaimLinesImport from './ClaimLinesImport.vue';
const quasar = useQuasar(); const quasar = useQuasar();
const route = useRoute(); const route = useRoute();
const { t } = useI18n(); const { t } = useI18n();
console.log(t);
const stateStore = useStateStore(); const stateStore = useStateStore();
const arrayData = useArrayData('ClaimLines'); const arrayData = useArrayData('ClaimLines');
const store = arrayData.store; const store = arrayData.store;

View File

@ -50,18 +50,4 @@ describe('ClaimDevelopment', () => {
cy.reload(); cy.reload();
cy.get(thirdRow).should('not.exist'); cy.get(thirdRow).should('not.exist');
}); });
// it('should remove third and fourth file', () => {
// cy.get(
// '.multimediaParent > :nth-child(3) > .q-btn > .q-btn__content > .q-icon'
// ).click();
// cy.get('.q-btn--unelevated > .q-btn__content > .block').click();
// cy.get('.q-notification__message').should('have.text', 'Data deleted');
// cy.get(
// '.multimediaParent > :nth-child(3) > .q-btn > .q-btn__content > .q-icon'
// ).click();
// cy.get('.q-btn--unelevated > .q-btn__content > .block').click();
// cy.get('.q-notification__message').should('have.text', 'Data deleted');
// });
}); });

View File

@ -1,15 +1,23 @@
import { createWrapper, axios } from 'app/test/vitest/helper'; import { createWrapper, axios } from 'app/test/vitest/helper';
import CrudModel from 'components/CrudModel.vue'; import CrudModel from 'components/CrudModel.vue';
import { vi, afterEach, beforeAll, beforeEach, describe, expect, it } from 'vitest'; import { vi, afterEach, beforeAll, beforeEach, describe, expect, it } from 'vitest';
import { onMounted, ref } from 'vue';
describe.only('CrudModel', () => { describe.only('CrudModel', () => {
let vm; let vm;
beforeAll(() => { beforeAll(() => {
vm = createWrapper(CrudModel, { vm = createWrapper(CrudModel, {
global: { global: {
stubs: ['vnPaginate', 'useState', 'arrayData', 'useStateStore'], stubs: [
'vnPaginate',
'useState',
'arrayData',
'useStateStore',
'useValidator',
],
mocks: { mocks: {
fetch: vi.fn(), fetch: vi.fn(),
validate: vi.fn(),
}, },
}, },
propsData: { propsData: {
@ -19,7 +27,6 @@ describe.only('CrudModel', () => {
autoLoad: true, autoLoad: true,
}, },
dataKey: 'crudModelKey', dataKey: 'crudModelKey',
model: 'crudModel',
url: 'crudModelUrl', url: 'crudModelUrl',
}, },
attrs: { attrs: {
@ -37,20 +44,16 @@ describe.only('CrudModel', () => {
describe('insert()', () => { describe('insert()', () => {
it('should new element in list with index 0 if formData not has data', () => { it('should new element in list with index 0 if formData not has data', () => {
vi.mock('src/composables/useValidator', () => ({ // vi.spyOn(axios, 'get').mockResolvedValue({
default: () => {}, // data: [
fetch: () => { // { id: 1, name: 'Tony Stark' },
vi.fn(); // { id: 2, name: 'Jessica Jones' },
}, // { id: 3, name: 'Bruce Wayne' },
})); // ],
vi.spyOn(axios, 'get').mockResolvedValue({ // });
data: [ // vm.state.set('crudModel', []);
{ id: 1, name: 'Tony Stark' }, vm.formData = ref([]);
{ id: 2, name: 'Jessica Jones' },
{ id: 3, name: 'Bruce Wayne' },
],
});
vm.state.set('crudModel', []);
vm.insert(); vm.insert();
expect(vm.formData.length).toEqual(1); expect(vm.formData.length).toEqual(1);

View File

@ -14,6 +14,9 @@ describe('ClaimLines', () => {
}, },
}, },
}).vm; }).vm;
vi.mock('src/composables/useValidator', () => ({
fetch: () => vi.fn(),
}));
}); });
beforeEach(() => { beforeEach(() => {