backdrops.test.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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('Working with backdrops', () => {
  16. beforeAll(() => {
  17. driver = getDriver();
  18. });
  19. afterAll(async () => {
  20. await driver.quit();
  21. });
  22. test('Adding a backdrop from the library should not switch to stage', async () => {
  23. await loadUri(uri);
  24. // Start on the sounds tab of sprite1 to test switching behavior
  25. await clickText('Sounds');
  26. // Add a backdrop without selecting the stage first to test switching
  27. await clickXpath('//button[@aria-label="Choose a Backdrop"]');
  28. const el = await findByXpath("//input[@placeholder='Search']");
  29. await el.sendKeys('blue');
  30. await clickText('Blue Sky'); // Adds the backdrop
  31. // Make sure the sprite is still selected, and that the tab has not changed
  32. await clickText('Meow', scope.soundsTab);
  33. // Make sure the backdrop was actually added by going to the backdrops tab
  34. await clickXpath('//span[text()="Stage"]');
  35. await clickText('Backdrops');
  36. await clickText('Blue Sky', scope.costumesTab);
  37. const logs = await getLogs();
  38. await expect(logs).toEqual([]);
  39. });
  40. test('Adding backdrop via paint should switch to stage', async () => {
  41. await loadUri(uri);
  42. const buttonXpath = '//button[@aria-label="Choose a Backdrop"]';
  43. const paintXpath = `${buttonXpath}/following-sibling::div//button[@aria-label="Paint"]`;
  44. const el = await findByXpath(buttonXpath);
  45. await driver.actions().mouseMove(el)
  46. .perform();
  47. await driver.sleep(500); // Wait for thermometer menu to come up
  48. await clickXpath(paintXpath);
  49. // Stage should become selected and costume tab activated
  50. await findByText('backdrop2', scope.costumesTab);
  51. const logs = await getLogs();
  52. await expect(logs).toEqual([]);
  53. });
  54. test('Adding backdrop via surprise should not switch to stage', async () => {
  55. await loadUri(uri);
  56. // Start on the sounds tab of sprite1 to test switching behavior
  57. await clickText('Sounds');
  58. const buttonXpath = '//button[@aria-label="Choose a Backdrop"]';
  59. const surpriseXpath = `${buttonXpath}/following-sibling::div//button[@aria-label="Surprise"]`;
  60. const el = await findByXpath(buttonXpath);
  61. await driver.actions().mouseMove(el)
  62. .perform();
  63. await driver.sleep(500); // Wait for thermometer menu to come up
  64. await clickXpath(surpriseXpath);
  65. // Make sure the sprite is still selected, and that the tab has not changed
  66. await clickText('Meow', scope.soundsTab);
  67. const logs = await getLogs();
  68. await expect(logs).toEqual([]);
  69. });
  70. test('Adding multiple backdrops from file should switch to stage', async () => {
  71. const files = [
  72. path.resolve(__dirname, '../fixtures/gh-3582-png.png'),
  73. path.resolve(__dirname, '../fixtures/100-100.svg')
  74. ];
  75. await loadUri(uri);
  76. const buttonXpath = '//button[@aria-label="Choose a Backdrop"]';
  77. const fileXpath = `${buttonXpath}/following-sibling::div//input[@type="file"]`;
  78. const el = await findByXpath(buttonXpath);
  79. await driver.actions().mouseMove(el)
  80. .perform();
  81. await driver.sleep(500); // Wait for thermometer menu to come up
  82. const input = await findByXpath(fileXpath);
  83. await input.sendKeys(files.join('\n'));
  84. // Should have been switched to stage/costume tab already
  85. await findByText('gh-3582-png', scope.costumesTab);
  86. await findByText('100-100', scope.costumesTab);
  87. const logs = await getLogs();
  88. await expect(logs).toEqual([]);
  89. });
  90. });