E2E fixes

This commit is contained in:
Juan Ferrer 2020-03-24 17:27:21 +01:00
parent a52fcb587a
commit 8eb6590285
7 changed files with 40 additions and 34 deletions

View File

@ -545,7 +545,7 @@ let actions = {
return dialogs.length;
}, response);
this.waitForFunction(firstCount => {
await this.waitForFunction(firstCount => {
const dialogs = document.querySelectorAll('.vn-dialog');
return dialogs.length < firstCount;
}, {}, firstCount);
@ -559,7 +559,14 @@ let actions = {
export function extendPage(page) {
for (let name in actions) {
page[name] = async(...args) => {
return await actions[name].call(page, ...args);
try {
return await actions[name].apply(page, args);
} catch (err) {
let stringArgs = args
.map(i => typeof i == 'function' ? 'Function' : i)
.join(', ');
throw new Error(`.${name}(${stringArgs}): ${err.message}`);
}
};
}

View File

@ -12,7 +12,7 @@ export async function getBrowser() {
if (process.env.DEBUG)
args.push('--auto-open-devtools-for-tabs');
const headless = !process.env.E2E_SHOW;
const headless = !(process.env.E2E_SHOW || process.env.DEBUG);
const browser = await Puppeteer.launch({
args,
defaultViewport: null,

View File

@ -260,7 +260,6 @@ export default {
secondRequestDecline: 'vn-item-request vn-tbody > vn-tr:nth-child(1) vn-icon-button[icon="thumb_down"]',
declineReason: 'vn-textarea[ng-model="$ctrl.denyObservation"]',
acceptDeclineReason: 'button[response="accept"]',
},
itemBasicData: {
basicDataButton: 'vn-left-menu a[ui-sref="item.card.basicData"]',

View File

@ -38,9 +38,8 @@ describe('Item request path', () => {
it('should now click on the second declain request icon then type the reason', async() => {
await page.waitToClick(selectors.itemRequest.secondRequestDecline);
await page.write(selectors.itemRequest.declineReason, 'not quite as expected');
await page.waitToClick(selectors.itemRequest.acceptDeclineReason);
await page.waitForContentLoaded();
await page.write(selectors.itemRequest.declineReason, 'Not quite as expected');
await page.respondToDialog('accept');
let status = await page.waitToGetProperty(selectors.itemRequest.firstRequestStatus, 'innerText');
expect(status).toContain('Denegada');

View File

@ -91,7 +91,7 @@
<vn-icon-button
ng-if="request.isOk != 0"
icon="thumb_down"
ng-click="$ctrl.showDenyReason($event, request)"
ng-click="denyDialog.show(request)"
translate-attr="{title: 'Discard'}"
tabindex="-1">
</vn-icon-button>
@ -111,8 +111,9 @@
vn-id="itemDescriptor">
</vn-item-descriptor-popover>
<vn-dialog
vn-id="denyReason"
on-response="$ctrl.denyRequest($response)">
vn-id="deny-dialog"
on-accept="$ctrl.onDenyAccept($data)"
on-close="$ctrl.onDenyClose()">
<tpl-body>
<h5 class="vn-pa-md" translate>Specify the reasons to deny this request</h5>
<vn-horizontal class="vn-pa-md">

View File

@ -1,8 +1,8 @@
import ngModule from '../module';
import Component from 'core/lib/component';
import Section from 'salix/components/section';
import './style.scss';
export default class Controller extends Component {
export default class Controller extends Section {
constructor($element, $) {
super($element, $);
@ -33,7 +33,7 @@ export default class Controller extends Component {
getState(isOk) {
if (isOk === null)
return 'Nueva';
else if (isOk === -1 || isOk)
else if (isOk)
return 'Aceptada';
else
return 'Denegada';
@ -102,25 +102,26 @@ export default class Controller extends Component {
delete this.denyRequestId;
}
denyRequest(response) {
if (response !== 'accept') return;
onDenyAccept(request) {
let params = {
observation: this.denyObservation
};
let query = `TicketRequests/${this.selectedRequest.id}/deny`;
this.$http.post(query, params).then(res => {
const request = res.data;
this.selectedRequest.isOk = request.isOk;
this.selectedRequest.attenderFk = request.attenderFk;
this.selectedRequest.response = request.response;
let query = `TicketRequests/${request.id}/deny`;
return this.$http.post(query, params).then(res => {
const newRequest = res.data;
request.isOk = newRequest.isOk;
request.attenderFk = newRequest.attenderFk;
request.response = newRequest.response;
this.vnApp.showSuccess(this.$t('Data saved!'));
this.denyObservation = null;
});
}
onDenyClose() {
this.denyObservation = null;
}
showTicketDescriptor(event, ticketFk) {
this.$.ticketDescriptor.ticketFk = ticketFk;
this.$.ticketDescriptor.parent = event.target;

View File

@ -84,7 +84,6 @@ describe('Item', () => {
let request = {saleFk: 1, saleQuantity: 1};
jest.spyOn(controller.vnApp, 'showSuccess');
$httpBackend.when('PATCH', `Sales/${request.saleFk}/`).respond();
$httpBackend.expect('PATCH', `Sales/${request.saleFk}/`).respond();
controller.changeQuantity(request);
@ -112,20 +111,20 @@ describe('Item', () => {
});
});
describe('denyRequest()', () => {
it(`should perform a query and call vnApp.showSuccess(), refresh(), hide() and set denyObservation to null in the controller`, () => {
jest.spyOn(controller.vnApp, 'showSuccess');
describe('onDenyAccept()', () => {
it(`should deny the request`, () => {
const request = {
id: 1,
response: 'new'
};
const request = {id: 1};
const expectedResult = {isOk: false, attenderFk: 106, response: 'Denied!'};
controller.selectedRequest = request;
const url = `TicketRequests/:id/deny`;
$httpBackend.expectRoute('POST', url).respond({response: 'denied'});
$httpBackend.when('POST', `TicketRequests/${request.id}/deny`).respond(expectedResult);
$httpBackend.expect('POST', `TicketRequests/${request.id}/deny`).respond(expectedResult);
controller.denyRequest('accept');
controller.onDenyAccept(request);
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(request.response).toBe('denied');
});
});
});