connection-modal.test.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import path from 'path';
  2. import SeleniumHelper from '../helpers/selenium-helper';
  3. const {
  4. clickText,
  5. clickXpath,
  6. findByText,
  7. getDriver,
  8. getLogs,
  9. loadUri
  10. } = new SeleniumHelper();
  11. const uri = path.resolve(__dirname, '../../build/index.html');
  12. let driver;
  13. // The tests below require Scratch Link to be unavailable, so we can trigger
  14. // an error modal. To make sure this is always true, we came up with the idea of
  15. // injecting javascript that overwrites the global Websocket object with one that
  16. // attempts to connect to a fake socket address.
  17. const websocketFakeoutJs = `var RealWebSocket = WebSocket;
  18. WebSocket = function () {
  19. return new RealWebSocket("wss://fake.fake");
  20. }`;
  21. describe('Hardware extension connection modal', () => {
  22. beforeAll(() => {
  23. driver = getDriver();
  24. });
  25. afterAll(async () => {
  26. await driver.quit();
  27. });
  28. test('Message saying Scratch Link is unavailable (BLE)', async () => {
  29. await driver.quit();
  30. driver = getDriver();
  31. await loadUri(uri);
  32. await driver.executeScript(websocketFakeoutJs);
  33. await clickXpath('//button[@title="Add Extension"]');
  34. await clickText('micro:bit');
  35. await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for modal to open
  36. findByText('Scratch Link'); // Scratch Link is mentioned in the error modal
  37. const logs = await getLogs();
  38. await expect(logs).toEqual([]);
  39. });
  40. test('Message saying Scratch Link is unavailable (BT)', async () => {
  41. await loadUri(uri);
  42. await driver.executeScript(websocketFakeoutJs);
  43. await clickXpath('//button[@title="Add Extension"]');
  44. await clickText('EV3');
  45. await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for modal to open
  46. findByText('Scratch Link'); // Scratch Link is mentioned in the error modal
  47. const logs = await getLogs();
  48. await expect(logs).toEqual([]);
  49. });
  50. });