page-search.spec.ts 5.9 KB

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