/* globals Promise */

import path from 'path';
import SeleniumHelper from '../helpers/selenium-helper';

const {
    clickXpath,
    getDriver,
    getLogs
} = new SeleniumHelper();

const errorWhitelist = [
    'The play() request was interrupted by a call to pause()'
];

let driver;

describe('player example', () => {
    const uri = path.resolve(__dirname, '../../build/player.html');

    beforeAll(() => {
        driver = getDriver();
    });

    afterAll(async () => {
        await driver.quit();
    });

    test('Load a project by ID', async () => {
        const projectId = '96708228';
        await driver.get(`file://${uri}#${projectId}`);
        await new Promise(resolve => setTimeout(resolve, 2000));
        await clickXpath('//img[@title="Go"]');
        await new Promise(resolve => setTimeout(resolve, 2000));
        await clickXpath('//img[@title="Stop"]');
        const logs = await getLogs(errorWhitelist);
        await expect(logs).toEqual([]);
    });
});

describe('blocks example', () => {
    const uri = path.resolve(__dirname, '../../build/blocks-only.html');

    beforeAll(() => {
        driver = getDriver();
    });

    afterAll(async () => {
        await driver.quit();
    });

    test('Load a project by ID', async () => {
        const projectId = '96708228';
        await driver.get(`file://${uri}#${projectId}`);
        await new Promise(resolve => setTimeout(resolve, 2000));
        await clickXpath('//img[@title="Go"]');
        await new Promise(resolve => setTimeout(resolve, 2000));
        await clickXpath('//img[@title="Stop"]');
        const logs = await getLogs(errorWhitelist);
        await expect(logs).toEqual([]);
    });
});

@@ -112,24 +112,73 @@
  %7B%0A    click
+Button,%0A    clickText,%0A    clickXpath,%0A    findBy
 Xpath,%0A    g
@@ -1721,29 +1721,861 @@
 gs).toEqual(%5B%5D);%0A    %7D);
+%0A%0A    test('Change categories', async () =%3E %7B%0A        await driver.get(%60file://$%7Buri%7D%60);%0A        await clickText('Looks');%0A        await clickText('Sound');%0A        await clickText('Pen');%0A        await clickText('Events');%0A        await clickText('Control');%0A        await clickText('Sensing');%0A        await clickText('Operators');%0A        await clickText('Data');%0A        await clickText('Create variable...');%0A        let el = await findByXpath(%22//input%5B@placeholder=''%5D%22);%0A        await el.sendKeys('score');%0A        await clickButton('OK');%0A        await clickText('Create variable...');%0A        el = await findByXpath(%22//input%5B@placeholder=''%5D%22);%0A        await el.sendKeys('second variable');%0A        await clickButton('OK');%0A        const logs = await getLogs(errorWhitelist);%0A        await expect(logs).toEqual(%5B%5D);%0A    %7D);
 %0A%7D);%0A

Test that blocks-only can use the blocks palette