sprites.test.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. import path from 'path';
  2. import SeleniumHelper from '../helpers/selenium-helper';
  3. const {
  4. clickText,
  5. clickXpath,
  6. elementIsVisible,
  7. findByText,
  8. findByXpath,
  9. getDriver,
  10. getLogs,
  11. loadUri,
  12. rightClickText,
  13. scope
  14. } = new SeleniumHelper();
  15. const uri = path.resolve(__dirname, '../../build/index.html');
  16. let driver;
  17. describe('Working with sprites', () => {
  18. beforeAll(() => {
  19. driver = getDriver();
  20. });
  21. afterAll(async () => {
  22. await driver.quit();
  23. });
  24. test('Adding a sprite through the library', async () => {
  25. await loadUri(uri);
  26. await clickText('Costumes');
  27. await clickXpath('//button[@aria-label="Choose a Sprite"]');
  28. await clickText('Apple', scope.modal); // Closes modal
  29. await rightClickText('Apple', scope.spriteTile); // Make sure it is there
  30. await clickText('Motion'); // Make sure we are back to the code tab
  31. const logs = await getLogs();
  32. await expect(logs).toEqual([]);
  33. });
  34. test('Adding a sprite by surprise button', async () => {
  35. await loadUri(uri);
  36. const el = await findByXpath('//button[@aria-label="Choose a Sprite"]');
  37. await driver.actions().mouseMove(el)
  38. .perform();
  39. await driver.sleep(500); // Wait for thermometer menu to come up
  40. await clickXpath('//button[@aria-label="Surprise"]');
  41. const logs = await getLogs();
  42. await expect(logs).toEqual([]);
  43. });
  44. test('Adding a sprite by paint button', async () => {
  45. await loadUri(uri);
  46. const el = await findByXpath('//button[@aria-label="Choose a Sprite"]');
  47. await driver.actions().mouseMove(el)
  48. .perform();
  49. await driver.sleep(500); // Wait for thermometer menu to come up
  50. await clickXpath('//button[@aria-label="Paint"]');
  51. await findByText('Convert to Bitmap'); // Make sure we are on the paint editor
  52. const logs = await getLogs();
  53. await expect(logs).toEqual([]);
  54. });
  55. test('Deleting only sprite does not crash', async () => {
  56. await loadUri(uri);
  57. await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for scroll animation
  58. await rightClickText('Sprite1', scope.spriteTile);
  59. await clickText('delete', scope.spriteTile);
  60. // Confirm that the stage has been switched to
  61. await findByText('Stage selected: no motion blocks');
  62. const logs = await getLogs();
  63. await expect(logs).toEqual([]);
  64. });
  65. test('Deleting by x button on sprite tile', async () => {
  66. await loadUri(uri);
  67. await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for scroll animation
  68. await clickXpath('//*[@aria-label="Delete"]'); // Only visible close button is on the sprite
  69. // Confirm that the stage has been switched to
  70. await findByText('Stage selected: no motion blocks');
  71. const logs = await getLogs();
  72. await expect(logs).toEqual([]);
  73. });
  74. test('Adding a sprite by uploading a png', async () => {
  75. await loadUri(uri);
  76. const el = await findByXpath('//button[@aria-label="Choose a Sprite"]');
  77. await driver.actions().mouseMove(el)
  78. .perform();
  79. await driver.sleep(500); // Wait for thermometer menu to come up
  80. const input = await findByXpath('//input[@type="file"]');
  81. await input.sendKeys(path.resolve(__dirname, '../fixtures/gh-3582-png.png'));
  82. await clickText('gh-3582-png', scope.spriteTile);
  83. const logs = await getLogs();
  84. await expect(logs).toEqual([]);
  85. });
  86. // This test fails because uploading an SVG as a sprite changes the scaling
  87. // Enable when this is fixed issues/3608
  88. test('Adding a sprite by uploading an svg (gh-3608)', async () => {
  89. await loadUri(uri);
  90. const el = await findByXpath('//button[@aria-label="Choose a Sprite"]');
  91. await driver.actions().mouseMove(el)
  92. .perform();
  93. await driver.sleep(500); // Wait for thermometer menu to come up
  94. const input = await findByXpath('//input[@type="file"]');
  95. await input.sendKeys(path.resolve(__dirname, '../fixtures/100-100.svg'));
  96. await clickText('100-100', scope.spriteTile); // Sprite is named for costume filename
  97. // Check to make sure the size is right
  98. await clickText('Costumes');
  99. await clickText('100-100', scope.costumesTab); // The name of the costume
  100. await clickText('100 x 100', scope.costumesTab); // The size of the costume
  101. const logs = await getLogs();
  102. await expect(logs).toEqual([]);
  103. });
  104. test('Adding a sprite by uploading a gif', async () => {
  105. await loadUri(uri);
  106. const el = await findByXpath('//button[@aria-label="Choose a Sprite"]');
  107. await driver.actions().mouseMove(el)
  108. .perform();
  109. await driver.sleep(500); // Wait for thermometer menu to come up
  110. const input = await findByXpath('//input[@type="file"]');
  111. await input.sendKeys(path.resolve(__dirname, '../fixtures/paddleball.gif'));
  112. await clickText('paddleball', scope.spriteTile); // Sprite is named for costume filename
  113. await clickText('Costumes');
  114. await findByText('paddleball', scope.costumesTab);
  115. await findByText('paddleball2', scope.costumesTab);
  116. await findByText('paddleball3', scope.costumesTab);
  117. await findByText('paddleball4', scope.costumesTab);
  118. await findByText('paddleball5', scope.costumesTab);
  119. await findByText('paddleball6', scope.costumesTab);
  120. const logs = await getLogs();
  121. await expect(logs).toEqual([]);
  122. });
  123. test('Adding a letter sprite through the Letters filter in the library', async () => {
  124. await loadUri(uri);
  125. await driver.manage()
  126. .window()
  127. .setSize(1244, 768); // Letters filter not visible at 1024 width
  128. await clickText('Costumes');
  129. await clickXpath('//button[@aria-label="Choose a Sprite"]');
  130. await clickText('Letters');
  131. await clickText('Block-B', scope.modal); // Closes modal
  132. await rightClickText('Block-B', scope.spriteTile); // Make sure it is there
  133. const logs = await getLogs();
  134. await expect(logs).toEqual([]);
  135. });
  136. test('Use browser back button to close library', async () => {
  137. await driver.get('https://www.google.com');
  138. await loadUri(uri);
  139. await clickText('Costumes');
  140. await clickXpath('//button[@aria-label="Choose a Sprite"]');
  141. const abbyElement = await findByText('Abby'); // Should show editor for new costume
  142. await elementIsVisible(abbyElement);
  143. await driver.navigate().back();
  144. try {
  145. // should throw error because library is no longer visible
  146. await elementIsVisible(abbyElement);
  147. throw 'ShouldNotGetHere'; // eslint-disable-line no-throw-literal
  148. } catch (e) {
  149. expect(e.constructor.name).toEqual('StaleElementReferenceError');
  150. }
  151. const costumesElement = await findByText('Costumes'); // Should show editor for new costume
  152. await elementIsVisible(costumesElement);
  153. const logs = await getLogs();
  154. await expect(logs).toEqual([]);
  155. });
  156. test('Adding multiple sprites at the same time', async () => {
  157. const files = [
  158. path.resolve(__dirname, '../fixtures/gh-3582-png.png'),
  159. path.resolve(__dirname, '../fixtures/100-100.svg')
  160. ];
  161. await loadUri(uri);
  162. const el = await findByXpath('//button[@aria-label="Choose a Sprite"]');
  163. await driver.actions().mouseMove(el)
  164. .perform();
  165. await driver.sleep(500); // Wait for thermometer menu to come up
  166. const input = await findByXpath('//input[@type="file"]');
  167. await input.sendKeys(files.join('\n'));
  168. await findByText('gh-3582-png', scope.spriteTile);
  169. await findByText('100-100', scope.spriteTile);
  170. const logs = await getLogs();
  171. await expect(logs).toEqual([]);
  172. });
  173. });