0
0
Fork 0

test: #5926 Mock API REquest

This commit is contained in:
Javier Segarra 2024-06-03 12:18:42 +02:00
parent 035a3cd0ae
commit 6c91fee139
2 changed files with 122 additions and 32 deletions

View File

@ -17,7 +17,7 @@ import VnInput from 'src/components/common/VnInput.vue';
const { t } = useI18n();
const { notify } = useNotify();
const loadingDocuware = ref(true);
const paginate = ref();
const dialog = ref();
const route = useRoute();
@ -94,6 +94,27 @@ const handleDownloadDocuware = async (row) => {
console.error('Error removing department');
}
};
async function fetchDocuware(deviceProductions) {
let promises = deviceProductions.map(({ deviceProductionFk }) =>
axios.post(`Docuwares/${deviceProductionFk}/checkFile`, {
fileCabinet: 'hr',
signed: true,
})
);
promises = await Promise.all(promises);
promises.forEach((promise) => {
const id = +promise.config.url.match(/\d+/)[0];
const deviceProduction = deviceProductions.find(
({ deviceProductionFk }) => deviceProductionFk === id
);
if (!deviceProduction) return;
if (promise.data) deviceProduction.isSigned = promise.data;
deviceProduction.isDocuware = promise.data;
});
loadingDocuware.value = false;
}
</script>
<template>
@ -103,11 +124,7 @@ const handleDownloadDocuware = async (row) => {
@on-fetch="(data) => (deviceProductions = data)"
auto-load
/>
<FetchData
:url="`docuwares/checkFile`"
@on-fetch="(data) => (deviceProductions = data)"
auto-load
/>
<VnPaginate
ref="paginate"
data-key="WorkerPda"
@ -115,6 +132,7 @@ const handleDownloadDocuware = async (row) => {
:filter="{ where: { userFk: routeId } }"
order="id"
auto-load
@on-fetch="fetchDocuware"
>
<template #body="{ rows }">
<QCard
@ -163,19 +181,30 @@ const handleDownloadDocuware = async (row) => {
{{ t('worker.pda.removePDA') }}
</QTooltip>
</QBtn>
<QBtn
v-if="row.isSigned"
icon="cloud_download"
:loading="loadingDocuware"
v-if="!row.isDocuware"
icon="vn:client"
flat
class="btn-delete"
color="primary"
@click="handleDownloadDocuware(row)"
@click="
openConfirmationModal(
t('Sign PDA'),
t('Are you sure you want to send it?'),
() => handleSendToTablet(row)
)
"
>
<QTooltip>
{{ t('worker.pda.download') }}
{{ t('worker.pda.sendToTablet') }}
</QTooltip>
</QBtn>
<QBtn
:loading="loadingDocuware"
v-if="row.isDocuware && !row.isSigned"
icon="refresh"
flat
@ -185,25 +214,18 @@ const handleDownloadDocuware = async (row) => {
>
<QTooltip>
{{ t('worker.pda.refresh') }}
</QTooltip>
</QBtn>
<QBtn
v-if="!row.isDocuware"
icon="vn:client"
</QTooltip> </QBtn
><QBtn
:loading="loadingDocuware"
v-if="row.isSigned"
icon="cloud_download"
flat
class="btn-delete"
color="primary"
@click="
openConfirmationModal(
t('Are you sure you want to send it?'),
t('Sign PDA'),
() => handleSendToTablet(row)
)
"
@click="handleDownloadDocuware(row)"
>
<QTooltip>
{{ t('worker.pda.sendToTablet') }}
{{ t('worker.pda.download') }}
</QTooltip>
</QBtn>
</VnRow>

View File

@ -1,10 +1,11 @@
describe('WorkerPda', () => {
describe.only('WorkerPda', () => {
const deviceProductionField =
'.vn-row > .q-field > .q-field__inner > .q-field__control > .q-field__control-container';
beforeEach(() => {
cy.viewport(1920, 1080);
cy.login('developer');
cy.visit(`/#/worker/1110/pda`);
cy.waitForElement('.q-page', { timeout: 7000 });
});
it('assign pda', () => {
@ -13,12 +14,79 @@ describe('WorkerPda', () => {
cy.get('.vn-row > #simSerialNumber').type('123{enter}');
cy.get('.q-notification__message').should('have.text', 'Data created');
});
it('delete pda', () => {
cy.get('.btn-delete').click();
cy.get(
'.q-card__actions > .q-btn--unelevated > .q-btn__content > .block'
).click();
cy.get('.q-notification__message').should('have.text', 'PDA deallocated');
describe.only(' Row Actions', () => {
it.skip('delete pda', () => {
cy.get(
':nth-child(1) > .vn-row > :nth-child(5) > .q-btn__content > .q-icon'
).click();
cy.get(
'.q-card__actions > .q-btn--unelevated > .q-btn__content > .block'
).click();
cy.get('.q-notification__message').should('have.text', 'PDA deallocated');
});
describe.only(' Docuware Flow ', () => {
describe.skip(' NOT Signed ', () => {
beforeEach(() => {
cy.intercept(
'POST',
'**/checkFile',
'false' // and force the response to be: []
).as('not_signed'); // and assign an alias
});
it('docuware', () => {
// Btn icon-client is present
cy.get(
':nth-child(1) > .vn-row > :nth-child(6) > .q-btn__content > .q-icon'
).should('have.class', 'icon-client');
// Btn icon-client is clicked
cy.get(
':nth-child(1) > .vn-row > :nth-child(6) > .q-btn__content > .q-icon'
).click();
// Btn confirm is clicked
cy.get(
'.q-card__actions > .q-btn--unelevated > .q-btn__content > .block'
).click();
// Btn refresh is present
cy.get(
':nth-child(1) > .vn-row > :nth-child(6) > .q-btn__content > .q-icon'
).should('have.text', 'refresh');
// Btn refresh is clicked
cy.get(
':nth-child(1) > .vn-row > :nth-child(6) > .q-btn__content > .q-icon'
).click();
// Btn confirm is clicked
// cy.get(
// '.q-card__actions > .q-btn--unelevated > .q-btn__content > .block'
// ).click();
// Btn cloud_download is present
cy.get(
':nth-child(1) > .vn-row > :nth-child(6) > .q-btn__content > .q-icon'
).should('have.text', 'cloud_download');
// Btn cloud_download is clicked
cy.get(
':nth-child(1) > .vn-row > :nth-child(6) > .q-btn__content > .q-icon'
).click();
});
});
describe.only(' Is Signed ', () => {
beforeEach(() => {
cy.intercept(
'POST',
'**/checkFile',
'true' // and force the response to be: []
).as('signed'); // and assign an alias
});
it('docuware', () => {
// Btn cloud_download is present
cy.get(
':nth-child(1) > .vn-row > :nth-child(6) > .q-btn__content > .q-icon'
).should('have.text', 'cloud_download');
// Btn cloud_download is clicked
cy.get(
':nth-child(1) > .vn-row > :nth-child(6) > .q-btn__content > .q-icon'
).click();
});
});
});
});
});