Spaces:
Running
Running
File size: 2,010 Bytes
f2bee8a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
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 driver.quit();
driver = getDriver();
await loadUri(uri);
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 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([]);
});
});
|