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

const {
    clickText,
    clickXpath,
    findByText,
    getDriver,
    getLogs,
    loadUri,
    rightClickText,
    scope
} = new SeleniumHelper();

const uri = path.resolve(__dirname, '../../build/index.html');

let driver;

describe('Working with sprites', () => {
    beforeAll(() => {
        driver = getDriver();
    });

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

    test('Deleting only sprite does not crash', async () => {
        await loadUri(uri);
        await clickXpath('//button[@title="tryit"]');
        await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for scroll animation
        await rightClickText('Sprite1', scope.spriteTile);
        await clickText('delete', scope.spriteTile);
        await driver.switchTo().alert()
            .accept();
        // Confirm that the stage has been switched to
        await findByText('Stage selected: no motion blocks');
        const logs = await getLogs();
        await expect(logs).toEqual([]);
    });
});

@@ -127,24 +127,41 @@
 findByText,%0A
+    findByXpath,%0A
     getDrive
@@ -486,24 +486,1021 @@
 );%0A    %7D);%0A%0A
+    test('Adding a sprite through the library', async () =%3E %7B%0A        await loadUri(uri);%0A        await clickXpath('//button%5B@title=%22tryit%22%5D');%0A        await clickText('Costumes');%0A        await clickXpath('//button%5B@aria-label=%22Choose a Sprite%22%5D');%0A        await clickText('Apple', scope.modal); // Closes modal%0A        await rightClickText('Apple', scope.spriteTile); // Make sure it is there%0A        const logs = await getLogs();%0A        await expect(logs).toEqual(%5B%5D);%0A    %7D);%0A%0A    test('Adding a sprite by surprise button', async () =%3E %7B%0A        await loadUri(uri);%0A        await clickXpath('//button%5B@title=%22tryit%22%5D');%0A        const el = await findByXpath('//button%5B@aria-label=%22Choose a Sprite%22%5D');%0A        await driver.actions().mouseMove(el)%0A            .perform();%0A        await driver.sleep(500); // Wait for thermometer menu to come up%0A        await clickXpath('//button%5B@aria-label=%22Surprise%22%5D');%0A        const logs = await getLogs();%0A        await expect(logs).toEqual(%5B%5D);%0A    %7D);%0A%0A
     test('De

Add an integration test for surprise and empty sprites