menu-bar.test.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. loadUri,
  10. rightClickText,
  11. scope
  12. } = new SeleniumHelper();
  13. const uri = path.resolve(__dirname, '../../build/index.html');
  14. let driver;
  15. describe('Menu bar settings', () => {
  16. beforeAll(() => {
  17. driver = getDriver();
  18. });
  19. afterAll(async () => {
  20. await driver.quit();
  21. });
  22. test('File->New should be enabled', async () => {
  23. await loadUri(uri);
  24. await clickXpath(
  25. '//div[contains(@class, "menu-bar_menu-bar-item") and ' +
  26. 'contains(@class, "menu-bar_hoverable")][span[text()="File"]]'
  27. );
  28. await findByXpath('//*[li[span[text()="New"]] and not(@data-tip="tooltip")]');
  29. });
  30. test('File->Load should be enabled', async () => {
  31. await loadUri(uri);
  32. await clickXpath(
  33. '//div[contains(@class, "menu-bar_menu-bar-item") and ' +
  34. 'contains(@class, "menu-bar_hoverable")][span[text()="File"]]'
  35. );
  36. await findByXpath('//*[li[text()="Load from your computer"] and not(@data-tip="tooltip")]');
  37. });
  38. test('File->Save should be enabled', async () => {
  39. await loadUri(uri);
  40. await clickXpath(
  41. '//div[contains(@class, "menu-bar_menu-bar-item") and ' +
  42. 'contains(@class, "menu-bar_hoverable")][span[text()="File"]]'
  43. );
  44. await findByXpath('//*[li[span[text()="Save to your computer"]] and not(@data-tip="tooltip")]');
  45. });
  46. test('Share button should NOT be enabled', async () => {
  47. await loadUri(uri);
  48. await findByXpath('//div[span[div[span[text()="Share"]]] and @data-tip="tooltip"]');
  49. });
  50. test('Logo should be clickable', async () => {
  51. await loadUri(uri);
  52. await clickXpath('//img[@alt="Scratch"]');
  53. const currentUrl = await driver.getCurrentUrl();
  54. await expect(currentUrl).toEqual('https://scratch.mit.edu/');
  55. });
  56. test('(GH#4064) Project name should be editable', async () => {
  57. await loadUri(uri);
  58. const el = await findByXpath('//input[@value="Scratch Project"]');
  59. await el.sendKeys(' - Personalized');
  60. await clickText('Costumes'); // just to blur the input
  61. await clickXpath('//input[@value="Scratch Project - Personalized"]');
  62. });
  63. test('User is not warned before uploading project file over a fresh project', async () => {
  64. await loadUri(uri);
  65. await clickText('File');
  66. await clickText('Load from your computer');
  67. const input = await findByXpath('//input[@accept=".sb,.sb2,.sb3"]');
  68. await input.sendKeys(path.resolve(__dirname, '../fixtures/project1.sb3'));
  69. // No replace alert since no changes were made
  70. await findByText('project1-sprite');
  71. });
  72. test('User is warned before uploading project file over an edited project', async () => {
  73. await loadUri(uri);
  74. // Change the project by deleting a sprite
  75. await rightClickText('Sprite1', scope.spriteTile);
  76. await clickText('delete', scope.spriteTile);
  77. await clickText('File');
  78. await clickText('Load from your computer');
  79. const input = await findByXpath('//input[@accept=".sb,.sb2,.sb3"]');
  80. await input.sendKeys(path.resolve(__dirname, '../fixtures/project1.sb3'));
  81. await driver.switchTo().alert()
  82. .accept();
  83. await findByText('project1-sprite');
  84. });
  85. });