language-selector.spec.ts 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { test, expect } from '@playwright/test';
  2. test.beforeEach(async ({ page }) => {
  3. await page.goto('/');
  4. });
  5. test('Clicking on Nav bar language selector icon should open the language selector menu', async ({
  6. page,
  7. }) => {
  8. // 1. make sure the language selector items are not visible
  9. await expect(page.locator('div[role="menuitem"]:has-text("English")')).not.toBeVisible();
  10. // 2. Click on the language selector nav bar trigger
  11. await page.locator('[aria-label="Select Language"]').click();
  12. // 3. Make sure the language selector items are visible
  13. await expect(page.locator('div[role="menuitem"]:has-text("English")')).toBeVisible();
  14. await expect(page.locator('div[role="menuitem"]:has-text("العربية")')).toBeVisible();
  15. await expect(page.locator('div[role="menuitem"]:has-text("বাংলা")')).toBeVisible();
  16. await expect(page.locator('div[role="menuitem"]:has-text("فارسی")')).toBeVisible();
  17. await expect(page.locator('div[role="menuitem"]:has-text("Français")')).toBeVisible();
  18. await expect(page.locator('div[role="menuitem"]:has-text("Italiano")')).toBeVisible();
  19. await expect(page.locator('div[role="menuitem"]:has-text("Dutch")')).toBeVisible();
  20. await expect(page.locator('div[role="menuitem"]:has-text("Português")')).toBeVisible();
  21. await expect(page.locator('div[role="menuitem"]:has-text("русский")')).toBeVisible();
  22. await expect(page.locator('div[role="menuitem"]:has-text("Shqip")')).toBeVisible();
  23. await expect(page.locator('div[role="menuitem"]:has-text("ภาษาไทย")')).toBeVisible();
  24. await expect(page.locator('div[role="menuitem"]:has-text("Türkçe")')).toBeVisible();
  25. await expect(page.locator('div[role="menuitem"]:has-text("اردو")')).toBeVisible();
  26. await expect(page.locator('div[role="menuitem"]:has-text("简体中文")')).toBeVisible();
  27. await expect(page.locator('div[role="menuitem"]:has-text("Melayu")')).toBeVisible();
  28. });
  29. test('Choosing a language should navigate the user to the localized page of that language', async ({
  30. page,
  31. }) => {
  32. // 1. Make sure we are on the English version
  33. await expect(page).toHaveURL('/');
  34. // 2. Open the language selector menu
  35. await page.locator('[aria-label="Select Language"]').click();
  36. // 3. select the Bengali language and make sure we are navigated to /bn
  37. await Promise.all([page.waitForNavigation({ url: '/bn' }), page.locator('text=বাংলা').click()]);
  38. });
  39. test('Choosing a language should persist', async ({ page, baseURL }) => {
  40. // 1. Open the language selector menu
  41. await page.locator('[aria-label="Select Language"]').click();
  42. // 2. select the Arabic language and make sure we are navigated to /ar
  43. await Promise.all([page.waitForNavigation({ url: '/ar' }), page.locator('text=العربية').click()]);
  44. // 3. Navigate again to /
  45. await page.goto('/');
  46. const currentUrl = page.url();
  47. // 4. Make sure the user is redirected to /ar
  48. expect(currentUrl).toBe(`${baseURL}/ar`);
  49. });