import config from '../helpers/config.js'; import createNightmare from '../helpers/nightmare'; import selectors from '../helpers/selectors.js'; import {catchErrors} from '../../services/utils/jasmineHelpers'; const nightmare = createNightmare(); const moduleAccessViewHashURL = '#!/'; jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; describe('Clients path', () => { it('should log in', done => { nightmare .login() .waitForURL(moduleAccessViewHashURL) .url() .then(url => { expect(url).toBe(config.url + moduleAccessViewHashURL); done(); }) .catch(catchErrors(done)); }); it('should access to the clients index by clicking the clients button', done => { nightmare .click(selectors.moduleAccessView.clientsSectionButton) .wait(selectors.clientsView.createClientButton) .url() .then(url => { expect(url).toBe(config.url + '#!/clients'); done(); }) .catch(catchErrors(done)); }); it(`should search for the user Bruce Wayne to confirm it isn't created yet`, done => { nightmare .wait(selectors.clientsView.searchResult) .type(selectors.clientsView.searchClientInput, 'Bruce Wayne') .click(selectors.clientsView.searchButton) .waitForNumberOfElements(selectors.clientsView.searchResult, 0) .countSearchResults(selectors.clientsView.searchResult) .then(result => { expect(result).toBe(0); done(); }) .catch(catchErrors(done)); }); it('should access to the create client view by clicking the create-client floating button', done => { nightmare .click(selectors.clientsView.createClientButton) .wait(selectors.createClientView.createButton) .url() .then(url => { expect(url).toBe(config.url + '#!/create'); done(); }) .catch(catchErrors(done)); }); it('should receive an error when clicking the create button having all the form fields empty', done => { nightmare .click(selectors.createClientView.createButton) .wait(selectors.globalItems.snackbarIsActive) .getInnerText(selectors.globalItems.snackbarIsActive) .then(result => { expect(result).toBe('No hay cambios que guardar'); done(); }) .catch(catchErrors(done)); }); it('should receive an error when clicking the create button having all the form fields empty but name', done => { nightmare .waitForSnackbarReset() .type(selectors.createClientView.name, 'Bruce Wayne') .click(selectors.createClientView.createButton) .wait(selectors.globalItems.snackbarIsActive) .getInnerText(selectors.globalItems.snackbarIsActive) .then(result => { expect(result).toContain(`Error:`); done(); }) .catch(catchErrors(done)); }); it('should receive an error when clicking the create button having all the form fields empty but Tax Number', done => { nightmare .waitForSnackbarReset() .clearInput(selectors.createClientView.name) .type(selectors.createClientView.taxNumber, 'Wayne Industries Tax Number') .click(selectors.createClientView.createButton) .wait(selectors.globalItems.snackbarIsActive) .getInnerText(selectors.globalItems.snackbarIsActive) .then(result => { expect(result).toContain(`Error:`); done(); }) .catch(catchErrors(done)); }); it('should receive an error when clicking the create button having all the form fields empty but Business Name', done => { nightmare .waitForSnackbarReset() .clearInput(selectors.createClientView.taxNumber) .type(selectors.createClientView.businessName, 'Wayne Industries') .click(selectors.createClientView.createButton) .wait(selectors.globalItems.snackbarIsActive) .getInnerText(selectors.globalItems.snackbarIsActive) .then(result => { expect(result).toContain(`Error:`); done(); }) .catch(catchErrors(done)); }); it('should receive an error when clicking the create button having all the form fields empty but User Name', done => { nightmare .waitForSnackbarReset() .clearInput(selectors.createClientView.businessName) .type(selectors.createClientView.userName, 'Batman') .click(selectors.createClientView.createButton) .wait(selectors.globalItems.snackbarIsActive) .getInnerText(selectors.globalItems.snackbarIsActive) .then(result => { expect(result).toContain(`Error:`); done(); }) .catch(catchErrors(done)); }); it('should receive an error when clicking the create button having all the form fields empty but email while email have incorrect format', done => { nightmare .waitForSnackbarReset() .clearInput(selectors.createClientView.userName) .type(selectors.createClientView.email, 'I will save Gotham!') .click(selectors.createClientView.createButton) .wait(selectors.globalItems.snackbarIsActive) .getInnerText(selectors.globalItems.snackbarIsActive) .then(result => { expect(result).toBe(`Algunos campos no son vĂ¡lidos`); done(); }) .catch(catchErrors(done)); }); it('should receive an error when clicking the create button having all the form fields empty but email', done => { nightmare .waitForSnackbarReset() .clearInput(selectors.createClientView.email) .type(selectors.createClientView.email, 'IAmBatman@WayneIndustries.gotham') .click(selectors.createClientView.createButton) .wait(selectors.globalItems.snackbarIsActive) .getInnerText(selectors.globalItems.snackbarIsActive) .then(result => { expect(result).toContain(`Error:`); done(); }) .catch(catchErrors(done)); }); // this test should remain commented until the fixtures are implemented to avoid chainned failures. // it(`should create a new user with all it's data`, done => { // nightmare // .wait(longWait) // .clearInput(selectors.createClientView.email) // .type(selectors.createClientView.name, 'Bruce Wayne') // .type(selectors.createClientView.taxNumber, 'Wayne Industries Tax Number') // .type(selectors.createClientView.businessName, 'Wayne Industries') // .type(selectors.createClientView.userName, 'Batman') // .type(selectors.createClientView.email, 'IAmBatman@WayneIndustries.gotham') // .click(selectors.createClientView.createButton) // .wait(6000) // .wait(selectors.globalItems.snackbarIsActive) // .getInnerText(selectors.globalItems.snackbarIsActive) // .then(result => { // expect(result).toContain(`some validation message`); // done(); // }) // .catch(catchErrors(done)); // }); });