page-search.spec.ts 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. import { expect, Page } from '@playwright/test'
  2. import { test } 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.waitForTimeout(500)
  30. await page.keyboard.press(hotkeyBack)
  31. // check if diacritics are indexed
  32. const results = await searchPage(page, 'Einführung in die Allgemeine Sprachwissenschaft' + rand)
  33. // await expect(results.length).toEqual(5) // 2 block + 1 current page
  34. await closeSearchBox(page)
  35. })
  36. test('Search CJK', async ({ page, block }) => {
  37. const rand = randomString(20)
  38. // diacritic opening test
  39. await createRandomPage(page)
  40. await block.mustType('[[今日daytime进度条' + rand + ']] diacritic-block-1', { delay: 10 })
  41. await page.waitForTimeout(500)
  42. await page.keyboard.press(hotkeyOpenLink, { delay: 10 })
  43. await page.waitForTimeout(500)
  44. const pageTitle = page.locator('.page-title').first()
  45. expect(await pageTitle.innerText()).toEqual('今日daytime进度条' + rand)
  46. await page.waitForTimeout(500)
  47. // check if CJK are indexed
  48. const results = await searchPage(page, '进度')
  49. // await expect(results.length).toEqual(4) // 1 page + 1 block + new whiteboard
  50. await closeSearchBox(page)
  51. })
  52. async function alias_test(block: Block, page: Page, page_name: string, search_kws: string[]) {
  53. await createRandomPage(page)
  54. const rand = randomString(10)
  55. let target_name = page_name + ' target ' + rand
  56. let alias_name = page_name + ' alias ' + rand
  57. let alias_test_content_1 = randomString(20)
  58. let alias_test_content_2 = randomString(20)
  59. let alias_test_content_3 = randomString(20)
  60. await page.type('textarea >> nth=0', '[[' + target_name)
  61. await page.keyboard.press(hotkeyOpenLink)
  62. await lastBlock(page)
  63. // build target Page with alias
  64. // the target page will contains the content in
  65. // alias_test_content_1,
  66. // alias_test_content_2, and
  67. // alias_test_content_3 sequentially, to validate the target page state
  68. await page.type('textarea >> nth=0', 'alias:: [[' + alias_name, { delay: 10 })
  69. await page.keyboard.press('Enter', { delay: 200 }) // Enter for finishing selection
  70. await page.keyboard.press('Enter', { delay: 200 })
  71. await page.keyboard.press('Escape')
  72. await page.waitForTimeout(100)
  73. await block.clickNext()
  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.waitForTimeout(100)
  94. await page.type('textarea >> nth=0', alias_test_content_2)
  95. await page.waitForTimeout(100)
  96. page.keyboard.press(hotkeyBack)
  97. await page.waitForNavigation()
  98. await block.escapeEditing()
  99. // pressing enter on alias opening test
  100. await block.activeEditing(1)
  101. await page.press('textarea >> nth=0', 'ArrowLeft')
  102. await page.press('textarea >> nth=0', 'ArrowLeft')
  103. await page.press('textarea >> nth=0', 'ArrowLeft')
  104. page.press('textarea >> nth=0', 'Enter')
  105. await page.waitForNavigation()
  106. await block.escapeEditing()
  107. await block.activeEditing(2)
  108. expect(await page.inputValue('textarea >> nth=0')).toBe(alias_test_content_2)
  109. await newInnerBlock(page)
  110. await page.waitForTimeout(100)
  111. await page.type('textarea >> nth=0', alias_test_content_3)
  112. await page.waitForTimeout(100)
  113. page.keyboard.press(hotkeyBack)
  114. await page.waitForNavigation()
  115. await block.escapeEditing()
  116. // clicking alias ref opening test
  117. await block.activeEditing(1)
  118. await block.enterNext()
  119. await page.waitForSelector('.page-blocks-inner .ls-block .page-ref >> nth=-1')
  120. await page.click('.page-blocks-inner .ls-block .page-ref >> nth=-1')
  121. await lastBlock(page)
  122. expect(await page.inputValue('textarea >> nth=0')).toBe(alias_test_content_3)
  123. // TODO: test alias from graph clicking
  124. // test alias from search
  125. for (let kw of search_kws) {
  126. let kw_name = kw + ' alias ' + rand
  127. const results = await searchPage(page, kw_name)
  128. // test search results
  129. expect(await results[0].innerText()).toContain(alias_name.normalize('NFKC'))
  130. // test search entering (page)
  131. page.keyboard.press("Enter")
  132. await page.waitForNavigation()
  133. await page.waitForSelector('.ls-block span.inline')
  134. // test search clicking (block)
  135. await searchPage(page, kw_name)
  136. }
  137. }
  138. test.skip('page diacritic alias', async ({ block, page }) => {
  139. await alias_test(block, page, "ü", ["ü", "ü", "Ü"])
  140. })