sticky-features.spec.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { expect, test } from '@playwright/test';
  2. test.describe('Sticky features', () => {
  3. test.beforeEach(async ({ page }) => {
  4. await page.goto('/');
  5. });
  6. test('Subnavigation displays changes on scroll down and up', async ({
  7. page,
  8. }) => {
  9. // Scroll down to trigger sticky effect
  10. await page.evaluate(() => window.scrollTo(0, 250));
  11. await expect(page.locator('.sticky-outer-wrapper').first()).toHaveClass(
  12. /active/,
  13. );
  14. // Scroll back to top
  15. await page.evaluate(() => window.scrollTo(0, 0));
  16. await expect(page.locator('.sticky-outer-wrapper').first()).not.toHaveClass(
  17. /active/,
  18. );
  19. });
  20. test('Subnavigation is not displayed when move to other pages', async ({
  21. page,
  22. }) => {
  23. // Scroll down to trigger sticky effect
  24. await page.evaluate(() => window.scrollTo(0, 250));
  25. await expect(page.locator('.sticky-outer-wrapper').first()).toHaveClass(
  26. /active/,
  27. );
  28. // Move to /Sandbox page
  29. await page.goto('/Sandbox');
  30. await expect(page.locator('.sticky-outer-wrapper').first()).not.toHaveClass(
  31. /active/,
  32. );
  33. });
  34. test('Able to click buttons on subnavigation switcher when sticky', async ({
  35. page,
  36. }) => {
  37. // Scroll down to trigger sticky effect
  38. await page.evaluate(() => window.scrollTo(0, 250));
  39. await expect(page.locator('.sticky-outer-wrapper').first()).toHaveClass(
  40. /active/,
  41. );
  42. // Click editor button
  43. await page.getByTestId('editor-button').click();
  44. await expect(page.locator('.layout-root')).toHaveClass(/editing/);
  45. });
  46. test('Subnavigation is sticky when on small window', async ({ page }) => {
  47. // Scroll down to trigger sticky effect
  48. await page.evaluate(() => window.scrollTo(0, 500));
  49. await expect(page.locator('.sticky-outer-wrapper').first()).toHaveClass(
  50. /active/,
  51. );
  52. // Set viewport to small size
  53. await page.setViewportSize({ width: 600, height: 1024 });
  54. await expect(
  55. page
  56. .getByTestId('grw-contextual-sub-nav')
  57. .getByTestId('grw-page-editor-mode-manager'),
  58. ).toBeVisible();
  59. });
  60. });