Просмотр исходного кода

Merge branch 'master' into support/prevent-ssrf-for-slack-integration

Yuki Takei 10 месяцев назад
Родитель
Сommit
f6963d12d4

+ 4 - 1
apps/app/playwright/20-basic-features/presentation.spec.ts

@@ -19,7 +19,10 @@ test('Presentation', async({ page }) => {
     .toHaveText(/What can you do with GROWI?/);
 
   // forward the slide with button
-  await page.getByRole('application').getByLabel('next slide').click();
+  const nextSlideButton = await page.getByRole('application').getByLabel('next slide');
+  await expect(nextSlideButton).toBeVisible();
+  await expect(nextSlideButton).toBeEnabled();
+  await nextSlideButton.click();
 
   // check the content of the h2
   await expect(page.getByRole('application').getByRole('heading', { level: 2 }))

+ 6 - 8
apps/app/playwright/20-basic-features/use-tools.spec.ts

@@ -1,5 +1,7 @@
 import { test, expect, type Page } from '@playwright/test';
 
+import { scrollToTop } from '../utils/scroll';
+
 const openPageItemControl = async(page: Page): Promise<void> => {
   const nav = page.getByTestId('grw-contextual-sub-nav');
   const button = nav.getByTestId('open-page-item-control-btn');
@@ -32,14 +34,10 @@ const openPutBackPageModal = async(page: Page): Promise<void> => {
   await expect(button).toBeEnabled();
   await button.waitFor({ state: 'visible' });
 
-  // Scroll to the top of the page to prevent the subnav hide the button
-  await page.evaluate(() => {
-    document.documentElement.scrollTop = 0;
-    document.body.scrollTop = 0; // For Safari and older browsers
-  });
-
-  // Add a small delay to ensure scrolling is complete and the button is interactive
-  await page.waitForTimeout(200); // Increased delay
+  // Scroll to the top and ensure the button is visible
+  await scrollToTop(page);
+  await expect(button).toBeInViewport();
+  await button.waitFor({ state: 'attached' });
 
   await button.click();
   await expect(page.getByTestId('put-back-page-modal')).toBeVisible();

+ 34 - 0
apps/app/playwright/utils/scroll.ts

@@ -0,0 +1,34 @@
+import type { Page } from '@playwright/test';
+
+/**
+ * Scrolls the page to the top and waits for the scroll animation to complete
+ * @param page Playwright page object
+ */
+export const scrollToTop = async(page: Page): Promise<void> => {
+  await page.evaluate(async() => {
+    const waitForScrollComplete = async(): Promise<void> => {
+      document.documentElement.scrollTop = 0;
+      document.body.scrollTop = 0; // For Safari and older browsers
+
+      // Promise that resolves when scroll animation is complete
+      return new Promise<void>((resolve) => {
+        if (document.documentElement.scrollTop === 0) {
+          resolve();
+          return;
+        }
+
+        const checkScroll = () => {
+          if (document.documentElement.scrollTop === 0) {
+            resolve();
+          }
+          else {
+            requestAnimationFrame(checkScroll);
+          }
+        };
+        requestAnimationFrame(checkScroll);
+      });
+    };
+
+    await waitForScrollComplete();
+  });
+};