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

describe('Item fixed prices path', () => {
    let browser;
    let page;
    beforeAll(async() => {
        browser = await getBrowser();
        page = browser.page;
        await page.loginAndModule('buyer', 'item');
        await page.accessToSection('item.fixedPrice');
    });

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

    it('should click on the add new foxed price button', async() => {
        await page.doSearch();
        await page.waitToClick(selectors.itemFixedPrice.add);
        await page.waitForSelector(selectors.itemFixedPrice.fourthFixedPrice);
    });

    it('should fill the fixed price data', async() => {
        const now = new Date();
        await page.autocompleteSearch(selectors.itemFixedPrice.fourthWarehouse, 'Warehouse one');
        await page.writeOnEditableTD(selectors.itemFixedPrice.fourthGroupingPrice, '1');
        await page.writeOnEditableTD(selectors.itemFixedPrice.fourthPackingPrice, '1');
        await page.write(selectors.itemFixedPrice.fourthMinPrice, '1');
        await page.pickDate(selectors.itemFixedPrice.fourthStarted, now);
        await page.pickDate(selectors.itemFixedPrice.fourthEnded, now);
        const message = await page.waitForSnackbar();

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

    it('should reload the section and check the created price has the expected ID', async() => {
        await page.accessToSection('item.index');
        await page.accessToSection('item.fixedPrice');
        await page.doSearch();

        const result = await page.waitToGetProperty(selectors.itemFixedPrice.fourthItemID, 'value');

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