project-loading.test.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import path from 'path';
  2. import SeleniumHelper from '../helpers/selenium-helper';
  3. const {
  4. clickText,
  5. clickXpath,
  6. findByText,
  7. findByXpath,
  8. getDriver,
  9. getLogs,
  10. loadUri,
  11. scope
  12. } = new SeleniumHelper();
  13. const uri = path.resolve(__dirname, '../../build/index.html');
  14. let driver;
  15. describe('Loading scratch gui', () => {
  16. beforeAll(() => {
  17. driver = getDriver();
  18. });
  19. afterAll(async () => {
  20. await driver.quit();
  21. });
  22. describe('Loading projects by ID', () => {
  23. test('Nonexistent projects show error screen', async () => {
  24. await loadUri(`${uri}#999999999999999999999`);
  25. await clickText('Oops! Something went wrong.');
  26. });
  27. // skipping because it relies on network speed, and tests a method
  28. // of loading projects that we are not actively using anymore
  29. test.skip('Load a project by ID directly through url', async () => {
  30. await driver.quit(); // Reset driver to test hitting # url directly
  31. driver = getDriver();
  32. const projectId = '96708228';
  33. await loadUri(`${uri}#${projectId}`);
  34. await clickXpath('//img[@title="Go"]');
  35. await new Promise(resolve => setTimeout(resolve, 2000));
  36. await clickXpath('//img[@title="Stop"]');
  37. const logs = await getLogs();
  38. await expect(logs).toEqual([]);
  39. });
  40. // skipping because it relies on network speed, and tests a method
  41. // of loading projects that we are not actively using anymore
  42. test.skip('Load a project by ID (fullscreen)', async () => {
  43. await driver.quit(); // Reset driver to test hitting # url directly
  44. driver = getDriver();
  45. const prevSize = driver.manage()
  46. .window()
  47. .getSize();
  48. await new Promise(resolve => setTimeout(resolve, 2000));
  49. driver.manage()
  50. .window()
  51. .setSize(1920, 1080);
  52. const projectId = '96708228';
  53. await loadUri(`${uri}#${projectId}`);
  54. await clickXpath('//img[@title="Full Screen Control"]');
  55. await new Promise(resolve => setTimeout(resolve, 500));
  56. await clickXpath('//img[@title="Go"]');
  57. await new Promise(resolve => setTimeout(resolve, 1000));
  58. await clickXpath('//img[@title="Stop"]');
  59. prevSize.then(value => {
  60. driver.manage()
  61. .window()
  62. .setSize(value.width, value.height);
  63. });
  64. const logs = await getLogs();
  65. await expect(logs).toEqual([]);
  66. });
  67. test('Creating new project resets active tab to Code tab', async () => {
  68. await loadUri(uri);
  69. await findByXpath('//*[span[text()="Costumes"]]');
  70. await clickText('Costumes');
  71. await clickXpath(
  72. '//div[contains(@class, "menu-bar_menu-bar-item") and ' +
  73. 'contains(@class, "menu-bar_hoverable")][span[text()="File"]]'
  74. );
  75. await clickXpath('//li[span[text()="New"]]');
  76. await findByXpath('//div[@class="scratchCategoryMenu"]');
  77. await clickText('Operators', scope.blocksTab);
  78. });
  79. test('Not logged in->made no changes to project->create new project should not show alert', async () => {
  80. await loadUri(uri);
  81. await clickXpath(
  82. '//div[contains(@class, "menu-bar_menu-bar-item") and ' +
  83. 'contains(@class, "menu-bar_hoverable")][span[text()="File"]]'
  84. );
  85. await clickXpath('//li[span[text()="New"]]');
  86. await findByXpath('//*[div[@class="scratchCategoryMenu"]]');
  87. await clickText('Operators', scope.blocksTab);
  88. });
  89. test('Not logged in->made a change to project->create new project should show alert', async () => {
  90. await loadUri(uri);
  91. await clickText('Sounds');
  92. await clickXpath('//button[@aria-label="Choose a Sound"]');
  93. await clickText('A Bass', scope.modal); // Should close the modal
  94. await findByText('1.28'); // length of A Bass sound
  95. await clickXpath(
  96. '//div[contains(@class, "menu-bar_menu-bar-item") and ' +
  97. 'contains(@class, "menu-bar_hoverable")][span[text()="File"]]'
  98. );
  99. await clickXpath('//li[span[text()="New"]]');
  100. driver.switchTo()
  101. .alert()
  102. .accept();
  103. await findByXpath('//*[div[@class="scratchCategoryMenu"]]');
  104. await clickText('Operators', scope.blocksTab);
  105. });
  106. });
  107. });