diff --git a/e2e/helpers/extensions.js b/e2e/helpers/extensions.js index 186e0dddd..26d95998f 100644 --- a/e2e/helpers/extensions.js +++ b/e2e/helpers/extensions.js @@ -329,6 +329,36 @@ let actions = { .catch(() => { done(new Error(`.autocompleteSearch() for ${autocompleteSelector}, timed out`)); }); + }, + + datePicker: function(datePickerSelector, changeMonth, done) { + this.wait(datePickerSelector) + .mousedown(datePickerSelector) + .wait('div.flatpickr-calendar.open'); + if (changeMonth > 0) + this.mousedown('body > div > div.flatpickr-months > span.flatpickr-next-month > svg'); + + + if (changeMonth < 0) + this.mousedown('body > div > div.flatpickr-months > span.flatpickr-prev-month > svg'); + + const daySelector = 'div.flatpickr-calendar.open span.flatpickr-day:nth-child(16)'; + + this.wait(selector => { + return document.querySelector(selector); + }, daySelector) + .evaluate(selector => { + let event = new MouseEvent('mousedown', { + bubbles: true, + cancelable: true, + view: window + }); + document.querySelector(selector).dispatchEvent(event); + }, daySelector) + .then(done) + .catch(() => { + done(new Error(`.datePicker(), for ${daySelector} timed out`)); + }); } }; diff --git a/e2e/paths/ticket-module/14_create_ticket.spec.js b/e2e/paths/ticket-module/14_create_ticket.spec.js new file mode 100644 index 000000000..b308cabf4 --- /dev/null +++ b/e2e/paths/ticket-module/14_create_ticket.spec.js @@ -0,0 +1,54 @@ +import selectors from '../../helpers/selectors.js'; +import createNightmare from '../../helpers/nightmare'; + +describe('Ticket create path', () => { + const nightmare = createNightmare(); + + beforeAll(() => { + nightmare + .loginAndModule('employee', 'ticket'); + }); + + it('should open the new ticket form', async() => { + const url = await nightmare + .waitToClick(selectors.ticketsIndex.newTicketButton) + .wait(selectors.createTicketView.clientAutocomplete) + .parsedUrl(); + + expect(url.hash).toEqual('#!/ticket/create'); + }); + + it('should atempt to create a ticket for a frozen client but fail', async() => { + const result = await nightmare + .autocompleteSearch(selectors.createTicketView.clientAutocomplete, 'Bruce Banner') + .autocompleteSearch(selectors.createTicketView.addressAutocomplete, 'Bruce Banner') + .datePicker(selectors.createTicketView.deliveryDateInput, 1) + .autocompleteSearch(selectors.createTicketView.warehouseAutocomplete, 'Warehouse One') + .autocompleteSearch(selectors.createTicketView.agencyAutocomplete, 'inhouse pickup') + .waitToClick(selectors.createTicketView.createButton) + .waitForLastSnackbar(); + + expect(result).toEqual(`You can't create a ticket for a inactive client`); + }); + + it('should suceed to create a ticket for a valid client', async() => { + const result = await nightmare + .autocompleteSearch(selectors.createTicketView.clientAutocomplete, 'Tony Stark') + .autocompleteSearch(selectors.createTicketView.addressAutocomplete, 'Tony Stark') + .datePicker(selectors.createTicketView.deliveryDateInput, 1) + .autocompleteSearch(selectors.createTicketView.warehouseAutocomplete, 'Warehouse One') + .autocompleteSearch(selectors.createTicketView.agencyAutocomplete, 'inhouse pickup') + .waitToClick(selectors.createTicketView.createButton) + .waitForLastSnackbar(); + + expect(result).toEqual('Data saved!'); + }); + + it('should check the url is now the summary of the ticket', async() => { + const url = await nightmare + .waitForURL('/summary') + .parsedUrl(); + + expect(url.hash).toContain('/summary'); + }); +}); diff --git a/modules/ticket/front/create/card.html b/modules/ticket/front/create/card.html index 984e6c6fd..7007de94f 100644 --- a/modules/ticket/front/create/card.html +++ b/modules/ticket/front/create/card.html @@ -21,13 +21,12 @@ label="Address"> {{nickname}}: {{street}}, {{city}} -