salix/e2e/paths/client-module/05_add_address.spec.js

105 lines
4.4 KiB
JavaScript
Raw Normal View History

import selectors from '../../helpers/selectors.js';
import createNightmare from '../../helpers/nightmare';
2018-11-20 13:22:00 +00:00
describe('Client Add address path', () => {
const nightmare = createNightmare();
beforeAll(() => {
nightmare
.loginAndModule('employee', 'client')
.accessToSearchResult('Bruce Banner')
.accessToSection('client.card.address.index');
2018-11-20 13:22:00 +00:00
});
it(`should click on the add new address button to access to the new address form`, async () => {
const url = await nightmare
.waitToClick(selectors.clientAddresses.createAddress)
.waitForURL('address/create')
.parsedUrl();
2018-11-20 13:22:00 +00:00
expect(url.hash).toContain('address/create');
2018-11-20 13:22:00 +00:00
});
it(`should return to the addreses section by clicking the cancel button`, async () => {
const url = await nightmare
.waitToClick(selectors.clientAddresses.cancelButton)
.waitForURL('address/index')
.parsedUrl();
2018-11-20 13:22:00 +00:00
expect(url.hash).toContain('address/index');
2018-11-20 13:22:00 +00:00
});
it(`should now click on the add new address button to access to the new address form`, async () => {
const url = await nightmare
.waitToClick(selectors.clientAddresses.createAddress)
.waitForURL('address/create')
.parsedUrl();
2018-11-20 13:22:00 +00:00
expect(url.hash).toContain('address/create');
2018-11-20 13:22:00 +00:00
});
it('should receive an error after clicking save button as consignee, street and town fields are empty', async () => {
const result = await nightmare
.waitToClick(selectors.clientAddresses.defaultCheckboxInput)
.clearInput(selectors.clientAddresses.streetAddressInput)
.type(selectors.clientAddresses.postcodeInput, '10022')
.waitToClick(selectors.clientAddresses.provinceInput)
.waitToClick(selectors.clientAddresses.provinceSecondOption)
.waitToClick(selectors.clientAddresses.agencyInput)
.waitToClick(selectors.clientAddresses.agenctySecondOption)
.type(selectors.clientAddresses.phoneInput, '999887744')
.type(selectors.clientAddresses.mobileInput, '999887744')
.waitToClick(selectors.clientFiscalData.saveButton)
.waitForLastSnackbar();
expect(result).toEqual('Some fields are invalid');
});
it(`should create a new address with all it's data`, async () => {
const result = await nightmare
.type(selectors.clientAddresses.consigneeInput, 'Bruce Bunner')
.type(selectors.clientAddresses.streetAddressInput, '320 Park Avenue New York')
.type(selectors.clientAddresses.cityInput, 'New York')
.click(selectors.clientAddresses.saveButton)
.waitForLastSnackbar();
expect(result).toEqual('Data saved!');
});
it(`should click on the addresses button confirm the new address exists and it's the default one`, async () => {
const result = await nightmare
.waitToClick(selectors.clientAddresses.addressesButton)
.waitToGetProperty(selectors.clientAddresses.defaultAddress, 'innerText');
2018-11-20 13:22:00 +00:00
expect(result).toContain('320 Park Avenue New York');
});
it(`should click on the make default icon of the second address then confirm it is the default one now`, async () => {
const result = await nightmare
.waitToClick(selectors.clientAddresses.secondMakeDefaultStar)
.waitForTextInElement(selectors.clientAddresses.defaultAddress, 'Somewhere in Thailand')
.waitToGetProperty(selectors.clientAddresses.defaultAddress, 'innerText');
2018-11-20 13:22:00 +00:00
expect(result).toContain('Somewhere in Thailand');
});
it(`should click on the edit icon of the default address`, async () => {
const url = await nightmare
.waitForTextInElement(selectors.clientAddresses.defaultAddress, 'Somewhere in Thailand')
.waitToClick(selectors.clientAddresses.firstEditButton)
.waitForURL('/edit')
.parsedUrl();
2018-11-20 13:22:00 +00:00
expect(url.hash).toContain('/edit');
2018-11-20 13:22:00 +00:00
});
it(`should click on the active checkbox and receive an error to save it because it is the default address`, async () => {
const result = await nightmare
.waitToClick(selectors.clientAddresses.activeCheckbox)
.waitToClick(selectors.clientAddresses.saveButton)
.waitForLastSnackbar();
expect(result).toEqual('The default consignee can not be unchecked');
});
});