import selectors from '../../helpers/selectors.js'; import createNightmare from '../../helpers/helpers'; describe('Client', () => { describe('Add credit path', () => { const nightmare = createNightmare(); beforeAll(() => { return nightmare .waitForLogin('developer'); }); it('should click on the Clients button of the top bar menu', () => { 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'); }); }); it('should search for the user Ororo Munroe', () => { 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); }); }); it(`should click on the search result to access to the client's credit`, () => { 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'); }); }); it(`should click on the add credit button`, () => { return nightmare .waitToClick(selectors.clientCredit.addCreditFloatButton) .waitForURL('/credit/create') .url() .then(url => { expect(url).toContain('/credit/create'); }); }); it(`should edit the credit`, () => { return nightmare .clearInput(selectors.clientCredit.creditInput) .type(selectors.clientCredit.creditInput, 999) .click(selectors.clientCredit.saveButton) .waitForLastSnackbar() .then(result => { expect(result).toEqual('Data saved!'); }); }); it('should confirm the credit was updated', () => { return nightmare .wait(selectors.clientCredit.firstCreditText) .getInnerText(selectors.clientCredit.firstCreditText) .then(value => { expect(value).toContain(999); expect(value).toContain('developer'); }); }); }); });