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

describe('Claim Add note path', () => {
    let browser;
    let page;
    beforeAll(async() => {
        browser = await getBrowser();
        page = browser.page;
        await page.loginAndModule('salesPerson', 'claim');
        await page.accessToSearchResult('2');
        await page.accessToSection('claim.card.note.index');
    });

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

    it(`should reach the claim note index`, async() => {
        await page.waitForState('claim.card.note.index');
    });

    it(`should click on the add new note button`, async() => {
        await page.waitToClick(selectors.claimNote.addNoteFloatButton);
        await page.waitForState('claim.card.note.create');
    });

    it(`should create a new note`, async() => {
        await page.waitForSelector(selectors.claimNote.note);
        await page.type(`${selectors.claimNote.note} textarea`, 'The delivery was unsuccessful');
        await page.waitToClick(selectors.claimNote.saveButton);
        const message = await page.waitForSnackbar();

        expect(message.text).toContain('Data saved!');
    });

    it(`should redirect back to the claim notes page`, async() => {
        await page.waitForState('claim.card.note.index');
    });

    it('should confirm the note was created', async() => {
        const result = await page.waitToGetProperty(selectors.claimNote.firstNoteText, 'innerText');

        expect(result).toEqual('The delivery was unsuccessful');
    });
});