page-search.spec.ts 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. import { expect, Page } from '@playwright/test'
  2. import { test } from './fixtures'
  3. import { IsMac, createRandomPage, newBlock, newInnerBlock, randomString, lastBlock, enterNextBlock } from './utils'
  4. /***
  5. * Test alias features
  6. * Test search refering features
  7. * Consider diacritics
  8. ***/
  9. test('Search page and blocks (diacritics)', async ({ page, block }) => {
  10. let hotkeyOpenLink = 'Control+o'
  11. let hotkeyBack = 'Control+['
  12. if (IsMac) {
  13. hotkeyOpenLink = 'Meta+o'
  14. hotkeyBack = 'Meta+['
  15. }
  16. const rand = randomString(20)
  17. // diacritic opening test
  18. await createRandomPage(page)
  19. await block.mustType('[[Einführung in die Allgemeine Sprachwissenschaft' + rand + ']] diacritic-block-1', { delay: 10 })
  20. await page.keyboard.press(hotkeyOpenLink)
  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. // check if diacritics are indexed
  31. await page.click('#search-button')
  32. await page.waitForSelector('[placeholder="Search or create page"]')
  33. await page.type('[placeholder="Search or create page"]', 'Einführung in die Allgemeine Sprachwissenschaft' + rand, { delay: 10 })
  34. await page.waitForTimeout(2000) // wait longer for search contents to render
  35. // 2 blocks + 1 page + 1 page content
  36. const searchResults = page.locator('#ui__ac-inner>div')
  37. await expect(searchResults).toHaveCount(4)
  38. await page.keyboard.press("Escape") // escape search box typing
  39. await page.waitForTimeout(500)
  40. await page.keyboard.press("Escape") // escape modal
  41. })
  42. async function alias_test(page: Page, page_name: string, search_kws: string[]) {
  43. let hotkeyOpenLink = 'Control+o'
  44. let hotkeyBack = 'Control+['
  45. if (IsMac) {
  46. hotkeyOpenLink = 'Meta+o'
  47. hotkeyBack = 'Meta+['
  48. }
  49. const rand = randomString(10)
  50. let target_name = page_name + ' target ' + rand
  51. let alias_name = page_name + ' alias ' + rand
  52. let alias_test_content_1 = randomString(20)
  53. let alias_test_content_2 = randomString(20)
  54. let alias_test_content_3 = randomString(20)
  55. // shortcut opening test
  56. let parent_title = await createRandomPage(page)
  57. await page.fill('textarea >> nth=0', '[[' + target_name + ']]')
  58. await page.keyboard.press(hotkeyOpenLink)
  59. await lastBlock(page)
  60. // build target Page with alias
  61. // the target page will contains the content in
  62. // alias_test_content_1,
  63. // alias_test_content_2, and
  64. // alias_test_content_3 sequentialy, to validate the target page state
  65. await page.type('textarea >> nth=0', 'alias:: [[' + alias_name)
  66. await page.press('textarea >> nth=0', 'Enter') // Enter for finishing selection
  67. await page.press('textarea >> nth=0', 'Enter') // double Enter for exit property editing
  68. await page.press('textarea >> nth=0', 'Enter') // double Enter for exit property editing
  69. await lastBlock(page)
  70. await page.type('textarea >> nth=0', alias_test_content_1)
  71. await lastBlock(page)
  72. await page.keyboard.press(hotkeyBack)
  73. await page.waitForTimeout(100) // await navigation
  74. // create alias ref in origin Page
  75. await newBlock(page)
  76. await page.type('textarea >> nth=0', '[[' + alias_name)
  77. await page.press('textarea >> nth=0', 'Enter') // Enter for finishing selection
  78. await page.waitForTimeout(100)
  79. await page.keyboard.press(hotkeyOpenLink)
  80. await page.waitForTimeout(100) // await navigation
  81. // shortcut opening test
  82. await lastBlock(page)
  83. expect(await page.inputValue('textarea >> nth=0')).toBe(alias_test_content_1)
  84. await enterNextBlock(page)
  85. await page.type('textarea >> nth=0', alias_test_content_2)
  86. await page.keyboard.press(hotkeyBack)
  87. // pressing enter opening test
  88. await lastBlock(page)
  89. await page.press('textarea >> nth=0', 'ArrowLeft')
  90. await page.press('textarea >> nth=0', 'ArrowLeft')
  91. await page.press('textarea >> nth=0', 'ArrowLeft')
  92. await page.press('textarea >> nth=0', 'Enter')
  93. await lastBlock(page)
  94. expect(await page.inputValue('textarea >> nth=0')).toBe(alias_test_content_2)
  95. await newInnerBlock(page)
  96. await page.type('textarea >> nth=0', alias_test_content_3)
  97. await page.keyboard.press(hotkeyBack)
  98. // clicking opening test
  99. await newBlock(page)
  100. await page.waitForSelector('.page-blocks-inner .ls-block .page-ref >> nth=-1')
  101. await page.click('.page-blocks-inner .ls-block .page-ref >> nth=-1')
  102. await lastBlock(page)
  103. expect(await page.inputValue('textarea >> nth=0')).toBe(alias_test_content_3)
  104. // TODO: test alias from graph clicking
  105. // test alias from search
  106. for (let kw of search_kws) {
  107. let kw_name = kw + ' alias ' + rand
  108. await page.click('#search-button')
  109. await page.waitForSelector('[placeholder="Search or create page"]')
  110. await page.fill('[placeholder="Search or create page"]', kw_name)
  111. await page.waitForTimeout(500)
  112. const results = await page.$$('#ui__ac-inner>div')
  113. expect(results.length).toEqual(3) // page + block + alias property
  114. // test search results
  115. expect(await results[0].innerText()).toContain("Alias -> " + target_name)
  116. expect(await results[0].innerText()).toContain(alias_name)
  117. expect(await results[1].innerText()).toContain(parent_title)
  118. expect(await results[1].innerText()).toContain("[[" + alias_name + "]]")
  119. expect(await results[2].innerText()).toContain(target_name)
  120. expect(await results[2].innerText()).toContain("alias:: [[" + alias_name + "]]")
  121. // test search entering (page)
  122. page.keyboard.press("Enter")
  123. await page.waitForNavigation()
  124. await page.waitForTimeout(100)
  125. await lastBlock(page)
  126. expect(await page.inputValue('textarea >> nth=0')).toBe(alias_test_content_3)
  127. // test search clicking (block)
  128. await page.click('#search-button')
  129. await page.waitForSelector('[placeholder="Search or create page"]')
  130. await page.fill('[placeholder="Search or create page"]', kw_name)
  131. await page.waitForTimeout(500)
  132. page.click(":nth-match(.menu-link, 2)")
  133. await page.waitForNavigation()
  134. await page.waitForTimeout(500)
  135. await lastBlock(page)
  136. expect(await page.inputValue('textarea >> nth=0')).toBe("[[" + alias_name + "]]")
  137. await page.keyboard.press(hotkeyBack)
  138. }
  139. // TODO: search clicking (alias property)
  140. }
  141. test.skip('page diacritic alias', async ({ page }) => {
  142. await alias_test(page, "ü", ["ü", "ü", "Ü"])
  143. })