diff --git a/package.json b/package.json index 520d091e8d6b281ffe34c66cd30eb261e3cec110..fd00337f1c8206bcebe4c40d8e37c1ba6fbcb561 100644 --- a/package.json +++ b/package.json @@ -106,7 +106,7 @@ "scratch-render": "0.1.0-prerelease.20181029125804", "scratch-storage": "1.1.0", "scratch-svg-renderer": "0.2.0-prerelease.20181024192149", - "scratch-vm": "0.2.0-prerelease.20181106161946", + "scratch-vm": "0.2.0-prerelease.20181107153250", "selenium-webdriver": "3.6.0", "startaudiocontext": "1.2.1", "style-loader": "^0.23.0", diff --git a/test/integration/connection-modal.test.js b/test/integration/connection-modal.test.js new file mode 100644 index 0000000000000000000000000000000000000000..117be5ce5ed7031092fb40b8a120b68074d9cfcc --- /dev/null +++ b/test/integration/connection-modal.test.js @@ -0,0 +1,66 @@ +import path from 'path'; +import SeleniumHelper from '../helpers/selenium-helper'; + +const { + clickText, + clickXpath, + findByText, + getDriver, + getLogs, + loadUri +} = new SeleniumHelper(); + +const uri = path.resolve(__dirname, '../../build/index.html'); + +let driver; + +// The tests below require Scratch Link to be unavailable, so we can trigger +// an error modal. To make sure this is always true, we came up with the idea of +// injecting javascript that overwrites the global Websocket object with one that +// attempts to connect to a fake socket address. +const websocketFakeoutJs = `var RealWebSocket = WebSocket; + WebSocket = function () { + return new RealWebSocket("wss://fake.fake"); + }`; + +describe('Hardware extension connection modal', () => { + beforeAll(() => { + driver = getDriver(); + }); + + afterAll(async () => { + await driver.quit(); + }); + + test('Message saying Scratch Link is unavailable (BLE)', async () => { + await loadUri(uri); + await clickXpath('//button[@title="Try It"]'); + + await driver.executeScript(websocketFakeoutJs); + + await clickXpath('//button[@title="Add Extension"]'); + + await clickText('micro:bit'); + await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for modal to open + findByText('Scratch Link'); // Scratch Link is mentioned in the error modal + + const logs = await getLogs(); + await expect(logs).toEqual([]); + }); + + test('Message saying Scratch Link is unavailable (BT)', async () => { + await loadUri(uri); + await clickXpath('//button[@title="Try It"]'); + + await driver.executeScript(websocketFakeoutJs); + + await clickXpath('//button[@title="Add Extension"]'); + + await clickText('EV3'); + await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for modal to open + findByText('Scratch Link'); // Scratch Link is mentioned in the error modal + + const logs = await getLogs(); + await expect(logs).toEqual([]); + }); +});