import selectors from '../../helpers/selectors.js';
import getBrowser from '../../helpers/puppeteer';

describe('Client summary path', () => {
    let browser;
    let page;

    beforeAll(async() => {
        browser = await getBrowser();
        page = browser.page;
        await page.loginAndModule('employee', 'client');
        await page.accessToSearchResult('Petter Parker');
    });

    afterAll(async() => {
        await browser.close();
    });

    it('should reach the first route summary section', async() => {
        await page.waitForState('client.card.summary');
    });

    it('should display details from the client on the header', async() => {
        await page.waitForTextInElement(selectors.clientSummary.header, 'Petter Parker');
        const result = await page.waitToGetProperty(selectors.clientSummary.header, 'innerText');

        expect(result).toContain('Petter Parker');
    });

    it('should display some basic data', async() => {
        const result = await page.waitToGetProperty(selectors.clientSummary.email, 'innerText');

        expect(result).toContain('PetterParker@mydomain.com');
    });

    it('should display fiscal address details', async() => {
        const result = await page.waitToGetProperty(selectors.clientSummary.street, 'innerText');

        expect(result).toContain('20 Ingram Street');
    });

    it('should display some fiscal data', async() => {
        await page.waitForClassPresent(selectors.clientSummary.verifiedData, 'checked');
        const result = await page.waitToGetProperty(selectors.clientSummary.verifiedData, 'innerText');

        expect(result).toContain('Verified data');
    });

    it('should display pay method details', async() => {
        const result = await page.waitToGetProperty(selectors.clientSummary.payMethod, 'innerText');

        expect(result).toContain('PayMethod five');
    });

    it('should display default address details', async() => {
        const result = await page.waitToGetProperty(selectors.clientSummary.defaultAdressName, 'innerText');

        expect(result).toContain('Petter Parker');
    });

    it('should display web access details', async() => {
        const result = await page.waitToGetProperty(selectors.clientSummary.userName, 'innerText');

        expect(result).toContain('PetterParker');
    });

    it('should display business data', async() => {
        const result = await page.waitToGetProperty(selectors.clientSummary.rate, 'innerText');

        expect(result).toContain('%');
    });

    it('should display financial information', async() => {
        const result = await page.waitToGetProperty(selectors.clientSummary.credit, 'innerText');

        expect(result).toContain('€300.00');
    });
});