import selectors from '../../helpers/selectors'; import getBrowser from '../../helpers/puppeteer'; describe('Client balance path', () => { let browser; let page; beforeAll(async() => { browser = await getBrowser(); page = browser.page; await page.loginAndModule('administrative', 'client'); await page.accessToSearchResult('Petter Parker'); }); afterAll(async() => { await browser.close(); }); it('should now edit the local user config data', async() => { await page.waitToClick(selectors.globalItems.userMenuButton); await page.autocompleteSearch(selectors.globalItems.userLocalCompany, 'CCs'); const message = await page.waitForSnackbar(); expect(message.text).toContain('Data saved!'); }); it('should access to the balance section to check the data shown matches the local settings', async() => { await page.accessToSection('client.card.balance.index'); let result = await page.waitToGetProperty(selectors.clientBalance.company, 'value'); expect(result).toEqual('CCs'); }); it('should now clear the user local settings', async() => { await page.waitToClick(selectors.globalItems.userMenuButton); await page.clearInput(selectors.globalItems.userConfigThirdAutocomplete); const message = await page.waitForSnackbar(); expect(message.text).toContain('Data saved!'); }); it('should click the new payment button', async() => { await page.closePopup(); await page.reloadSection('client.card.balance.index'); }); it('should create a new payment that clears the debt', async() => { await page.closePopup(); await page.waitToClick(selectors.clientBalance.newPaymentButton); await page.autocompleteSearch(selectors.clientBalance.newPaymentBank, 'Pay on receipt'); await page.write(selectors.clientBalance.newDescription, 'Description'); await page.waitToClick(selectors.clientBalance.saveButton); const message = await page.waitForSnackbar(); expect(message.text).toContain('Data saved!'); }); it('should edit the 1st line reference', async() => { await page.waitToClick(selectors.clientBalance.firstLineReference); await page.write(selectors.clientBalance.firstLineReferenceInput, 'Miscellaneous payment'); await page.keyboard.press('Enter'); const message = await page.waitForSnackbar(); expect(message.text).toContain('Data saved!'); }); it('should check balance is now 0, the reference was saved and the company is now VNL becouse the user local settings were removed', async() => { await page.waitForSpinnerLoad(); let company = await page .waitToGetProperty(selectors.clientBalance.company, 'value'); let reference = await page .waitToGetProperty(selectors.clientBalance.firstLineReference, 'innerText'); let firstBalanceLine = await page .waitToGetProperty(selectors.clientBalance.firstLineBalance, 'innerText'); expect(company).toEqual('VNL'); expect(reference).toEqual('Miscellaneous payment'); expect(firstBalanceLine).toContain('0.00'); }); it('should create a new payment that sets the balance to positive value', async() => { await page.waitToClick(selectors.clientBalance.newPaymentButton); await page.overwrite(selectors.clientBalance.newPaymentAmount, '100'); await page.waitToClick(selectors.clientBalance.saveButton); const message = await page.waitForSnackbar(); expect(message.text).toContain('Data saved!'); }); it('should check balance is now -100', async() => { let result = await page .waitToGetProperty(selectors.clientBalance.firstLineBalance, 'innerText'); expect(result).toContain('-€100.00'); }); it('should create a new payment that sets the balance back to the original negative value', async() => { await page.waitToClick(selectors.clientBalance.newPaymentButton); await page.autocompleteSearch(selectors.clientBalance.newPaymentBank, 'Pay on receipt'); await page.overwrite(selectors.clientBalance.newPaymentAmount, '-150'); await page.write(selectors.clientBalance.newDescription, 'Description'); await page.waitToClick(selectors.clientBalance.saveButton); const message = await page.waitForSnackbar(); expect(message.text).toContain('Data saved!'); }); it('should check balance is now 50', async() => { let result = await page .waitToGetProperty(selectors.clientBalance.firstLineBalance, 'innerText'); expect(result).toEqual('€50.00'); }); it('should now click on the Clients button of the top bar menu', async() => { await page.login('employee'); await page.waitToClick(selectors.globalItems.applicationsMenuButton); await page.waitForSelector(selectors.globalItems.applicationsMenuVisible); await page.waitToClick(selectors.globalItems.clientsButton); await page.waitForSelector(selectors.clientsIndex.createClientButton); await page.waitForState('client.index'); }); it('should now search for the user Petter Parker', async() => { await page.accessToSearchResult('Petter Parker'); await page.accessToSection('client.card.balance.index'); }); it('should not be able to click the new payment button as it isnt present', async() => { await page.waitForSelector(selectors.clientBalance.newPaymentButton, {hidden: true}); }); });