sounds.test.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. import path from 'path';
  2. import SeleniumHelper from '../helpers/selenium-helper';
  3. import {Key} from 'selenium-webdriver';
  4. const {
  5. clickText,
  6. clickXpath,
  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 sounds', () => {
  18. beforeAll(() => {
  19. driver = getDriver();
  20. });
  21. afterAll(async () => {
  22. await driver.quit();
  23. });
  24. test('Adding a sound through the library', async () => {
  25. await loadUri(uri);
  26. await clickText('Sounds');
  27. // Delete the sound
  28. await rightClickText('Meow', scope.soundsTab);
  29. await driver.sleep(500); // Wait a moment for context menu; only needed for local testing
  30. await clickText('delete', scope.soundsTab);
  31. // Add it back
  32. await clickXpath('//button[@aria-label="Choose a Sound"]');
  33. let el = await findByXpath("//input[@placeholder='Search']");
  34. await el.sendKeys('meow');
  35. await clickText('Meow', scope.modal); // Should close the modal
  36. // Add a new sound
  37. await clickXpath('//button[@aria-label="Choose a Sound"]');
  38. el = await findByXpath("//input[@placeholder='Search']");
  39. await el.sendKeys('chom');
  40. await clickText('Chomp'); // Should close the modal, then click the sounds in the selector
  41. await findByXpath("//input[@value='Chomp']"); // Should show editor for new sound
  42. await clickXpath('//button[@title="Play"]');
  43. await clickText('Louder');
  44. await clickText('Softer');
  45. await clickText('Faster');
  46. await clickText('Slower');
  47. await clickText('Robot');
  48. await clickText('Reverse');
  49. const logs = await getLogs();
  50. await expect(logs).toEqual([]);
  51. });
  52. test('Adding a sound by surprise button', async () => {
  53. await loadUri(uri);
  54. await clickText('Sounds');
  55. const el = await findByXpath('//button[@aria-label="Choose a Sound"]');
  56. await driver.actions().mouseMove(el)
  57. .perform();
  58. await driver.sleep(500); // Wait for thermometer menu to come up
  59. await clickXpath('//button[@aria-label="Surprise"]');
  60. const logs = await getLogs();
  61. await expect(logs).toEqual([]);
  62. });
  63. test('Duplicating a sound', async () => {
  64. await loadUri(uri);
  65. await clickText('Sounds');
  66. await rightClickText('Meow', scope.soundsTab);
  67. await clickText('duplicate', scope.soundsTab);
  68. await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for error
  69. // Make sure the duplicated sound is named correctly.
  70. await clickText('Meow2', scope.soundsTab);
  71. const logs = await getLogs();
  72. await expect(logs).toEqual([]);
  73. });
  74. // Regression test for gui issue #1320
  75. test('Switching sprites with different numbers of sounds', async () => {
  76. await loadUri(uri);
  77. // Add a sound so this sprite has 2 sounds.
  78. await clickText('Sounds');
  79. await clickXpath('//button[@aria-label="Choose a Sound"]');
  80. await clickText('A Bass'); // Closes the modal
  81. // Now add a sprite with only one sound.
  82. await clickXpath('//button[@aria-label="Choose a Sprite"]');
  83. await clickText('Abby'); // Doing this used to crash the editor.
  84. await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for error
  85. // Make sure the 'Oops' screen is not visible
  86. const content = await driver.getPageSource();
  87. expect(content.indexOf('Oops')).toEqual(-1);
  88. const logs = await getLogs();
  89. await expect(logs).toEqual([]);
  90. });
  91. test('Adding multiple sounds at the same time', async () => {
  92. const files = [
  93. path.resolve(__dirname, '../fixtures/movie.wav'),
  94. path.resolve(__dirname, '../fixtures/sneaker.wav')
  95. ];
  96. await loadUri(uri);
  97. await clickText('Sounds');
  98. const el = await findByXpath('//button[@aria-label="Choose a Sound"]');
  99. await driver.actions().mouseMove(el)
  100. .perform();
  101. await driver.sleep(500); // Wait for thermometer menu to come up
  102. const input = await findByXpath('//input[@type="file"]');
  103. await input.sendKeys(files.join('\n'));
  104. await findByText('movie', scope.soundsTab);
  105. await findByText('sneaker', scope.soundsTab);
  106. const logs = await getLogs();
  107. await expect(logs).toEqual([]);
  108. });
  109. test('Copy to new button adds a new sound', async () => {
  110. await loadUri(uri);
  111. await clickText('Sounds');
  112. await clickText('Copy to New', scope.soundsTab);
  113. await clickText('Meow2', scope.soundsTab);
  114. const logs = await getLogs();
  115. await expect(logs).toEqual([]);
  116. });
  117. test('Copy and pasting within a sound changes its duration', async () => {
  118. await loadUri(uri);
  119. await clickText('Sounds');
  120. await findByText('0.85', scope.soundsTab); // Original meow sound duration
  121. await clickText('Copy', scope.soundsTab);
  122. await clickText('Paste', scope.soundsTab);
  123. await findByText('1.70', scope.soundsTab); // Sound has doubled in duration
  124. const logs = await getLogs();
  125. await expect(logs).toEqual([]);
  126. });
  127. test('Can copy a sound from a sprite and paste into a sound on the stage', async () => {
  128. await loadUri(uri);
  129. await clickText('Sounds');
  130. await clickText('Copy', scope.soundsTab); // Copy the meow sound
  131. await clickXpath('//span[text()="Stage"]');
  132. await findByText('0.02', scope.soundsTab); // Original pop sound duration
  133. await clickText('Paste', scope.soundsTab);
  134. await findByText('0.87', scope.soundsTab); // Duration of pop + meow sound
  135. const logs = await getLogs();
  136. await expect(logs).toEqual([]);
  137. });
  138. test('Keyboard shortcuts', async () => {
  139. await loadUri(uri);
  140. await clickText('Sounds');
  141. const el = await findByXpath('//button[@aria-label="Choose a Sound"]');
  142. await el.sendKeys(Key.chord(Key.COMMAND, 'a')); // Select all
  143. await findByText('0.85', scope.soundsTab); // Meow sound duration
  144. await el.sendKeys(Key.DELETE);
  145. await findByText('0.00', scope.soundsTab); // Sound is now empty
  146. await el.sendKeys(Key.chord(Key.COMMAND, 'z')); // undo
  147. await findByText('0.85', scope.soundsTab); // Meow sound is back
  148. await el.sendKeys(Key.chord(Key.COMMAND, Key.SHIFT, 'z')); // redo
  149. await findByText('0.00', scope.soundsTab); // Sound is empty again
  150. const logs = await getLogs();
  151. await expect(logs).toEqual([]);
  152. });
  153. });