localization.test.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import path from 'path';
  2. import SeleniumHelper from '../helpers/selenium-helper';
  3. const {
  4. clickText,
  5. clickXpath,
  6. getDriver,
  7. getLogs,
  8. loadUri,
  9. scope,
  10. rightClickText
  11. } = new SeleniumHelper();
  12. const uri = path.resolve(__dirname, '../../build/index.html');
  13. let driver;
  14. describe('Localization', () => {
  15. beforeAll(() => {
  16. driver = getDriver();
  17. });
  18. afterAll(async () => {
  19. await driver.quit();
  20. });
  21. test('Switching languages', async () => {
  22. await driver.quit();
  23. driver = getDriver();
  24. await loadUri(uri);
  25. // Add a sprite to make sure it stays when switching languages
  26. await clickText('Costumes');
  27. await clickXpath('//button[@aria-label="Choose a Sprite"]');
  28. await clickText('Apple', scope.modal); // Closes modal
  29. await clickText('Code');
  30. await clickXpath('//*[@aria-label="language selector"]');
  31. await clickText('Deutsch');
  32. await new Promise(resolve => setTimeout(resolve, 1000)); // wait for blocks refresh
  33. // Make sure the blocks are translating
  34. await clickText('Fühlen'); // Sensing category in German
  35. await new Promise(resolve => setTimeout(resolve, 1000)); // wait for blocks to scroll
  36. await clickText('Antwort'); // Find the "answer" block in German
  37. // Change to the costumes tab to confirm other parts of the GUI are translating
  38. await clickText('Kostüme');
  39. // After switching languages, make sure Apple sprite still exists
  40. await rightClickText('Apple', scope.spriteTile); // Make sure it is there
  41. // Remounting re-attaches the beforeunload callback. Make sure to remove it
  42. driver.executeScript('window.onbeforeunload = undefined;');
  43. const logs = await getLogs();
  44. await expect(logs).toEqual([]);
  45. });
  46. // Regression test for #4476, blocks in wrong language when loaded with locale
  47. test('Loading with locale shows correct blocks', async () => {
  48. await loadUri(`${uri}?locale=de`);
  49. await clickText('Fühlen'); // Sensing category in German
  50. await new Promise(resolve => setTimeout(resolve, 1000)); // wait for blocks to scroll
  51. await clickText('Antwort'); // Find the "answer" block in German
  52. const logs = await getLogs();
  53. await expect(logs).toEqual([]);
  54. });
  55. });