page-search.spec.ts 6.3 KB

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