page-search.spec.ts 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. import { expect, Page } from '@playwright/test'
  2. import { test, traceAll } from './fixtures'
  3. import { Block } from './types'
  4. import { modKey, createRandomPage, newInnerBlock, randomString, lastBlock, enterNextBlock } from './utils'
  5. import { searchPage, closeSearchBox } from './util/search-modal'
  6. /***
  7. * Test alias features
  8. * Test search referring features
  9. * Consider diacritics
  10. ***/
  11. let hotkeyOpenLink = modKey + '+o'
  12. let hotkeyBack = modKey + '+['
  13. test('Search page and blocks (diacritics)', async ({ page, block }) => {
  14. const rand = randomString(20)
  15. // diacritic opening test
  16. await createRandomPage(page)
  17. await block.mustType('[[Einführung in die Allgemeine Sprachwissenschaft' + rand + ']] diacritic-block-1', { delay: 10 })
  18. await page.waitForTimeout(500)
  19. await page.keyboard.press(hotkeyOpenLink, { delay: 10 })
  20. await page.waitForTimeout(500)
  21. const pageTitle = page.locator('.page-title').first()
  22. expect(await pageTitle.innerText()).toEqual('Einführung in die Allgemeine Sprachwissenschaft' + rand)
  23. await page.waitForTimeout(500)
  24. // build target Page with diacritics
  25. await block.activeEditing(0)
  26. await block.mustType('Diacritic title test content', { delay: 10 })
  27. await block.enterNext()
  28. await block.mustType('[[Einführung in die Allgemeine Sprachwissenschaft' + rand + ']] diacritic-block-2', { delay: 10 })
  29. await page.keyboard.press(hotkeyBack)
  30. await page.waitForTimeout(1000) // wait longer for db update
  31. // check if diacritics are indexed
  32. const results = await searchPage(page, 'Einführung in die Allgemeine Sprachwissenschaft' + rand)
  33. await page.pause();
  34. await expect(results.length).toEqual(5) // 1 page + 2 block + 2 page content
  35. await closeSearchBox(page)
  36. })
  37. test('Search CJK', async ({ page, block }) => {
  38. const rand = randomString(20)
  39. // diacritic opening test
  40. await createRandomPage(page)
  41. await block.mustType('[[今日daytime进度条' + rand + ']] diacritic-block-1', { delay: 10 })
  42. await page.waitForTimeout(500)
  43. await page.keyboard.press(hotkeyOpenLink, { delay: 10 })
  44. await page.waitForTimeout(500)
  45. const pageTitle = page.locator('.page-title').first()
  46. expect(await pageTitle.innerText()).toEqual('今日daytime进度条' + rand)
  47. await page.waitForTimeout(500)
  48. // check if CJK are indexed
  49. const results = await searchPage(page, '进度')
  50. await expect(results.length).toEqual(5) // 1 page + 1 block + 1 page content + new whiteboard
  51. await closeSearchBox(page)
  52. })
  53. async function alias_test(block: Block, page: Page, page_name: string, search_kws: string[]) {
  54. await createRandomPage(page)
  55. const rand = randomString(10)
  56. let target_name = page_name + ' target ' + rand
  57. let alias_name = page_name + ' alias ' + rand
  58. let alias_test_content_1 = randomString(20)
  59. let alias_test_content_2 = randomString(20)
  60. let alias_test_content_3 = randomString(20)
  61. await page.type('textarea >> nth=0', '[[' + target_name)
  62. await page.keyboard.press(hotkeyOpenLink)
  63. await lastBlock(page)
  64. // build target Page with alias
  65. // the target page will contains the content in
  66. // alias_test_content_1,
  67. // alias_test_content_2, and
  68. // alias_test_content_3 sequentially, to validate the target page state
  69. await page.type('textarea >> nth=0', 'alias:: [[' + alias_name, { delay: 10 })
  70. await page.keyboard.press('Enter', { delay: 200 }) // Enter for finishing selection
  71. await page.keyboard.press('Enter', { delay: 200 }) // double Enter for exit property editing
  72. await page.keyboard.press('Enter', { delay: 200 }) // double Enter for exit property editing
  73. await page.waitForTimeout(200)
  74. await block.activeEditing(1)
  75. await page.type('textarea >> nth=0', alias_test_content_1)
  76. await lastBlock(page)
  77. page.keyboard.press(hotkeyBack)
  78. await page.waitForNavigation()
  79. await block.escapeEditing()
  80. // create alias ref in origin Page
  81. await block.activeEditing(0)
  82. await block.enterNext()
  83. await page.type('textarea >> nth=0', '[[' + alias_name, { delay: 20 })
  84. await page.keyboard.press('Enter') // Enter for finishing selection
  85. await page.waitForTimeout(100)
  86. page.keyboard.press(hotkeyOpenLink)
  87. await page.waitForNavigation()
  88. await block.escapeEditing()
  89. // shortcut opening test
  90. await block.activeEditing(1)
  91. expect(await page.inputValue('textarea >> nth=0')).toBe(alias_test_content_1)
  92. await enterNextBlock(page)
  93. await page.type('textarea >> nth=0', alias_test_content_2)
  94. page.keyboard.press(hotkeyBack)
  95. await page.waitForNavigation()
  96. await block.escapeEditing()
  97. // pressing enter on alias opening test
  98. await block.activeEditing(1)
  99. await page.press('textarea >> nth=0', 'ArrowLeft')
  100. await page.press('textarea >> nth=0', 'ArrowLeft')
  101. await page.press('textarea >> nth=0', 'ArrowLeft')
  102. page.press('textarea >> nth=0', 'Enter')
  103. await page.waitForNavigation()
  104. await block.escapeEditing()
  105. await block.activeEditing(2)
  106. expect(await page.inputValue('textarea >> nth=0')).toBe(alias_test_content_2)
  107. await newInnerBlock(page)
  108. await page.type('textarea >> nth=0', alias_test_content_3)
  109. page.keyboard.press(hotkeyBack)
  110. await page.waitForNavigation()
  111. await block.escapeEditing()
  112. // clicking alias ref opening test
  113. await block.activeEditing(1)
  114. await block.enterNext()
  115. await page.waitForSelector('.page-blocks-inner .ls-block .page-ref >> nth=-1')
  116. await page.click('.page-blocks-inner .ls-block .page-ref >> nth=-1')
  117. await lastBlock(page)
  118. expect(await page.inputValue('textarea >> nth=0')).toBe(alias_test_content_3)
  119. // TODO: test alias from graph clicking
  120. // test alias from search
  121. for (let kw of search_kws) {
  122. let kw_name = kw + ' alias ' + rand
  123. const results = await searchPage(page, kw_name)
  124. await expect(results.length).toEqual(5) // page + block + alias property + page content
  125. // test search results
  126. expect(await results[0].innerText()).toContain("Alias -> " + target_name)
  127. expect(await results[0].innerText()).toContain(alias_name)
  128. expect(await results[1].innerText()).toContain("[[" + alias_name + "]]")
  129. expect(await results[2].innerText()).toContain("[[" + alias_name + "]]")
  130. // test search entering (page)
  131. page.keyboard.press("Enter")
  132. await page.waitForNavigation()
  133. await page.waitForSelector('.ls-block span.inline')
  134. expect(await page.locator('.ls-block span.inline >> nth=2').innerHTML()).toBe(alias_test_content_3)
  135. // test search clicking (block)
  136. await searchPage(page, kw_name)
  137. page.click(":nth-match(.search-result, 3)")
  138. await page.waitForNavigation()
  139. await page.waitForSelector('.selected a.page-ref')
  140. expect(await page.locator('.selected a.page-ref').innerHTML()).toBe(alias_name)
  141. await page.keyboard.press(hotkeyBack)
  142. }
  143. // TODO: search clicking (alias property)
  144. }
  145. test('page diacritic alias', async ({ block, page }) => {
  146. await alias_test(block, page, "ü", ["ü", "ü", "Ü"])
  147. })
  148. traceAll()