0
0
Fork 0

refs #5056 working on tests

This commit is contained in:
Alexandre Riera 2023-03-21 13:21:05 +01:00
parent 42511dc5bd
commit c8416ad42d
3 changed files with 115 additions and 70 deletions

View File

@ -30,6 +30,66 @@ let wagonConfig;
let wagonTypeColors;
let currentTrayColorPicked;
async function fetch() {
try {
await axios.get('WagonConfigs').then(async (res) => {
if (res.data) {
wagonConfig = res.data[0];
}
});
await axios.get(`WagonTypeColors`).then(async (res) => {
if (res.data) {
wagonTypeColors = res.data;
if (!entityId.value)
wagon.value.push({
id: 0,
position: 0,
color: { ...wagonTypeColors[0] },
action: 'add',
});
else {
await axios
.get(`WagonTypeTrays`, {
params: { filter: { where: { typeFk: entityId.value } } },
})
.then(async (res) => {
if (res.data) {
for (let i = 0; i < res.data.length; i++) {
const tray = res.data[i];
wagon.value.push({
id: res.data.length - i - 1,
position: tray.height,
color: {
...wagonTypeColors.find((color) => {
return color.id === tray.colorFk;
}),
},
action: tray.height == 0 ? 'add' : 'delete',
});
}
wagon.value.forEach((value) => {
originalData.trays.push({ ...value });
});
}
});
}
}
});
if (entityId.value) {
await axios.get(`WagonTypes/${entityId.value}`).then((res) => {
if (res.data) {
originalData.name = name.value = res.data.name;
originalData.divisible = divisible.value = res.data.divisible;
}
});
}
} catch (e) {
//
}
}
function addTray() {
if (
wagon.value.find((tray) => {
@ -105,62 +165,6 @@ async function onReset() {
];
}
async function fetch() {
await axios.get(`WagonConfigs`).then(async (res) => {
if (res.data) {
wagonConfig = res.data[0];
}
});
await axios.get(`WagonTypeColors`).then(async (res) => {
if (res.data) {
wagonTypeColors = res.data;
if (!entityId.value)
wagon.value.push({
id: 0,
position: 0,
color: { ...wagonTypeColors[0] },
action: 'add',
});
else {
await axios
.get(`WagonTypeTrays`, {
params: { filter: { where: { typeFk: entityId.value } } },
})
.then(async (res) => {
if (res.data) {
for (let i = 0; i < res.data.length; i++) {
const tray = res.data[i];
wagon.value.push({
id: res.data.length - i - 1,
position: tray.height,
color: {
...wagonTypeColors.find((color) => {
return color.id === tray.colorFk;
}),
},
action: tray.height == 0 ? 'add' : 'delete',
});
}
wagon.value.forEach((value) => {
originalData.trays.push({ ...value });
});
}
});
}
}
});
if (entityId.value) {
await axios.get(`WagonTypes/${entityId.value}`).then((res) => {
if (res.data) {
originalData.name = name.value = res.data.name;
originalData.divisible = divisible.value = res.data.divisible;
}
});
}
}
function doAction(tray) {
if (tray.action == 'add') {
addTray();

View File

@ -50,22 +50,26 @@ async function onReset() {
}
async function fetch() {
await axios.get(`WagonTypes`).then(async (res) => {
if (res.data) {
filteredWagonTypes.value = wagonTypes = res.data;
}
});
if (entityId.value) {
await axios.get(`Wagons/${entityId.value}`).then(async (res) => {
const data = res.data;
if (data) {
wagon.value.label = data.label;
wagon.value.plate = data.plate;
wagon.value.volume = data.volume;
wagon.value.typeFk = data.typeFk;
originalData = { ...wagon.value };
try {
await axios.get('WagonTypes').then(async (res) => {
if (res.data) {
filteredWagonTypes.value = wagonTypes = res.data;
}
});
if (entityId.value) {
await axios.get(`Wagons/${entityId.value}`).then(async (res) => {
const data = res.data;
if (data) {
wagon.value.label = data.label;
wagon.value.plate = data.plate;
wagon.value.volume = data.volume;
wagon.value.typeFk = data.typeFk;
originalData = { ...wagon.value };
}
});
}
} catch (e) {
//
}
}

View File

@ -0,0 +1,37 @@
import { createWrapper } from 'app/test/vitest/helper';
import WagonTypeCreate from 'pages/Wagon/Type/WagonTypeCreate.vue';
import { afterEach, beforeAll, describe, expect, it, vi } from 'vitest';
describe('WagonTypeCreate', () => {
let vm;
beforeAll(() => {
vm = createWrapper(WagonTypeCreate, {propsData: {
id: 1,
}}).vm;
});
afterEach(() => {
vi.clearAllMocks();
});
describe('addTray()', () => {
it('should throw message if there are uncompleteTrays', async () => {
vi.spyOn(vm.quasar, 'notify');
vm.wagon = [{
id: 1,
position: null,
color: {id: 1, color:'white', rgb:'#000000'}
}];
await vm.addTray();
expect(vm.quasar.notify).toHaveBeenCalledWith(
expect.objectContaining({ type: 'warning' })
);
});
it('should create a new tray if the limit has not been reached', async () => {
//
});
});
});