import selectors from '../../helpers/selectors.js'; import createNightmare from '../../helpers/nightmare'; describe('Client', () => { describe('Add credit path', () => { const nightmare = createNightmare(); beforeAll(() => { return nightmare .waitForLogin('salesAssistant'); }); it('should click on the Clients button of the top bar menu', done => { return nightmare .waitToClick(selectors.globalItems.applicationsMenuButton) .wait(selectors.globalItems.applicationsMenuVisible) .waitToClick(selectors.globalItems.clientsButton) .wait(selectors.clientsIndex.createClientButton) .parsedUrl() .then(url => { expect(url.hash).toEqual('#!/client/index'); done(); }).catch(done.fail); }); it('should search for the user Ororo Munroe', done => { return nightmare .wait(selectors.clientsIndex.searchResult) .type(selectors.clientsIndex.searchClientInput, 'Ororo Munroe') .click(selectors.clientsIndex.searchButton) .waitForNumberOfElements(selectors.clientsIndex.searchResult, 1) .countElement(selectors.clientsIndex.searchResult) .then(result => { expect(result).toEqual(1); done(); }).catch(done.fail); }); it(`should click on the search result to access to the client's credit`, done => { return nightmare .waitForTextInElement(selectors.clientsIndex.searchResult, 'Ororo Munroe') .waitToClick(selectors.clientsIndex.searchResult) .waitToClick(selectors.clientCredit.creditButton) .waitForURL('credit/index') .url() .then(url => { expect(url).toContain('credit/index'); done(); }).catch(done.fail); }); it(`should click on the add credit button`, done => { return nightmare .waitToClick(selectors.clientCredit.addCreditFloatButton) .waitForURL('/credit/create') .url() .then(url => { expect(url).toContain('/credit/create'); done(); }).catch(done.fail); }); it(`should edit the credit`, done => { return nightmare .clearInput(selectors.clientCredit.creditInput) .type(selectors.clientCredit.creditInput, 999) .click(selectors.clientCredit.saveButton) .waitForLastSnackbar() .then(result => { expect(result).toEqual('Data saved!'); done(); }).catch(done.fail); }); it('should confirm the credit was updated', done => { return nightmare .wait(selectors.clientCredit.firstCreditText) .getInnerText(selectors.clientCredit.firstCreditText) .then(value => { expect(value).toContain(999); expect(value).toContain('salesAssistant'); done(); }).catch(done.fail); }); }); });