浏览代码

fix(test): resolve e2e fails

Andelf 3 年之前
父节点
当前提交
f111ec3f8e
共有 3 个文件被更改,包括 23 次插入13 次删除
  1. 15 10
      e2e-tests/context-menu.spec.ts
  2. 5 0
      e2e-tests/fixtures.ts
  3. 3 3
      e2e-tests/page-search.spec.ts

+ 15 - 10
e2e-tests/context-menu.spec.ts

@@ -12,21 +12,21 @@ test('open context menu', async ({ page }) => {
 
 
 test('close context menu on esc', async ({ page }) => {
 test('close context menu on esc', async ({ page }) => {
     await createRandomPage(page)
     await createRandomPage(page)
-  
+
     await page.locator('span.bullet-container >> nth=0').click({button: "right"})
     await page.locator('span.bullet-container >> nth=0').click({button: "right"})
 
 
     await page.keyboard.press('Escape')
     await page.keyboard.press('Escape')
-  
+
     await expect(page.locator('#custom-context-menu')).toHaveCount(0)
     await expect(page.locator('#custom-context-menu')).toHaveCount(0)
 })
 })
 
 
 test('close context menu by left clicking on empty space', async ({ page }) => {
 test('close context menu by left clicking on empty space', async ({ page }) => {
     await createRandomPage(page)
     await createRandomPage(page)
-  
+
     await page.locator('span.bullet-container >> nth=0').click({button: "right"})
     await page.locator('span.bullet-container >> nth=0').click({button: "right"})
 
 
     await page.mouse.click(0, 200, {button: "left"})
     await page.mouse.click(0, 200, {button: "left"})
-  
+
     await expect(page.locator('#custom-context-menu')).toHaveCount(0)
     await expect(page.locator('#custom-context-menu')).toHaveCount(0)
 })
 })
 
 
@@ -35,21 +35,26 @@ test('close context menu by clicking on a menu item', async ({ page }) => {
 
 
     await page.locator('span.bullet-container >> nth=0').click({button: "right"})
     await page.locator('span.bullet-container >> nth=0').click({button: "right"})
 
 
-    await page.locator('#custom-context-menu .menu-link >> nth=0').click()
+    await page.locator('#custom-context-menu .menu-link >> nth=1').click()
 
 
     await expect(page.locator('#custom-context-menu')).toHaveCount(0)
     await expect(page.locator('#custom-context-menu')).toHaveCount(0)
 })
 })
 
 
-test('close context menu by clicking on a block', async ({ page }) => {
+test('close context menu by clicking on a block', async ({ page, block }) => {
     await createRandomPage(page)
     await createRandomPage(page)
 
 
-    await page.locator('span.bullet-container >> nth=0').click({button: "right"})
+    await block.mustType('fist Block')
+    await block.enterNext()
 
 
-    const elementHandle = await page.$('.block-content >> nth=0');
+    await page.locator('span.bullet-container >> nth=-1').click({button: "right"})
 
 
-    const box = await elementHandle.boundingBox();
+    const elementHandle = page.locator('.block-content >> nth=0');
 
 
-    await page.mouse.click(box.x + box.width - 5, box.y + box.height / 2);
+    const box = await elementHandle.boundingBox();
+    expect(box).toBeTruthy()
+    if (box) {
+        await page.mouse.click(box.x + box.width - 5, box.y + box.height / 2);
+    }
 
 
     await expect(page.locator('#custom-context-menu')).toHaveCount(0)
     await expect(page.locator('#custom-context-menu')).toHaveCount(0)
 })
 })

+ 5 - 0
e2e-tests/fixtures.ts

@@ -106,6 +106,11 @@ base.beforeEach(async () => {
   if (page) {
   if (page) {
     await page.keyboard.press('Escape')
     await page.keyboard.press('Escape')
     await page.keyboard.press('Escape')
     await page.keyboard.press('Escape')
+
+    const rightSidebar = page.locator('.cp__right-sidebar-inner')
+    if (await rightSidebar.isVisible()) {
+      await page.click('button.toggle-right-sidebar', {delay: 100})
+    }
   }
   }
 })
 })
 
 

+ 3 - 3
e2e-tests/page-search.spec.ts

@@ -38,7 +38,7 @@ import { IsMac, createRandomPage, newBlock, newInnerBlock, randomString, lastBlo
   await page.fill('[placeholder="Search or create page"]', 'Einführung in die Allgemeine Sprachwissenschaft' + rand)
   await page.fill('[placeholder="Search or create page"]', 'Einführung in die Allgemeine Sprachwissenschaft' + rand)
 
 
   await page.waitForTimeout(500)
   await page.waitForTimeout(500)
-  const results = await page.$$('#ui__ac-inner .block')
+  const results = await page.$$('#ui__ac-inner>div')
   expect(results.length).toEqual(3) // 2 blocks + 1 page
   expect(results.length).toEqual(3) // 2 blocks + 1 page
   await page.keyboard.press("Escape")
   await page.keyboard.press("Escape")
 })
 })
@@ -68,7 +68,7 @@ async function alias_test(page: Page, page_name: string, search_kws: string[]) {
   await page.waitForTimeout(500)
   await page.waitForTimeout(500)
 
 
   // build target Page with alias
   // build target Page with alias
-  // the target page will contains the content in 
+  // the target page will contains the content in
   //   alias_test_content_1,
   //   alias_test_content_1,
   //   alias_test_content_2, and
   //   alias_test_content_2, and
   //   alias_test_content_3 sequentialy, to validate the target page state
   //   alias_test_content_3 sequentialy, to validate the target page state
@@ -127,7 +127,7 @@ async function alias_test(page: Page, page_name: string, search_kws: string[]) {
     await page.fill('[placeholder="Search or create page"]', kw_name)
     await page.fill('[placeholder="Search or create page"]', kw_name)
     await page.waitForTimeout(500)
     await page.waitForTimeout(500)
 
 
-    const results = await page.$$('#ui__ac-inner .block')
+    const results = await page.$$('#ui__ac-inner>div')
     expect(results.length).toEqual(3) // page + block + alias property
     expect(results.length).toEqual(3) // page + block + alias property
 
 
     // test search results
     // test search results