page-search.spec.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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>div')
  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. // build target Page with alias
  55. // the target page will contains the content in
  56. // alias_test_content_1,
  57. // alias_test_content_2, and
  58. // alias_test_content_3 sequentialy, to validate the target page state
  59. await page.type('textarea >> nth=0', 'alias:: [[' + alias_name)
  60. await page.press('textarea >> nth=0', 'Enter') // Enter for finishing selection
  61. await page.press('textarea >> nth=0', 'Enter') // double Enter for exit property editing
  62. await page.press('textarea >> nth=0', 'Enter') // double Enter for exit property editing
  63. await lastBlock(page)
  64. await page.type('textarea >> nth=0', alias_test_content_1)
  65. await lastBlock(page)
  66. await page.keyboard.press(hotkeyBack)
  67. await page.waitForTimeout(100) // await navigation
  68. // create alias ref in origin Page
  69. await newBlock(page)
  70. await page.type('textarea >> nth=0', '[[' + alias_name)
  71. await page.press('textarea >> nth=0', 'Enter') // Enter for finishing selection
  72. await page.waitForTimeout(100)
  73. await page.keyboard.press(hotkeyOpenLink)
  74. await page.waitForTimeout(100) // await navigation
  75. // shortcut opening test
  76. await lastBlock(page)
  77. expect(await page.inputValue('textarea >> nth=0')).toBe(alias_test_content_1)
  78. await enterNextBlock(page)
  79. await page.type('textarea >> nth=0', alias_test_content_2)
  80. await page.keyboard.press(hotkeyBack)
  81. // pressing enter opening test
  82. await lastBlock(page)
  83. await page.press('textarea >> nth=0', 'ArrowLeft')
  84. await page.press('textarea >> nth=0', 'ArrowLeft')
  85. await page.press('textarea >> nth=0', 'ArrowLeft')
  86. await page.press('textarea >> nth=0', 'Enter')
  87. await lastBlock(page)
  88. expect(await page.inputValue('textarea >> nth=0')).toBe(alias_test_content_2)
  89. await newInnerBlock(page)
  90. await page.type('textarea >> nth=0', alias_test_content_3)
  91. await page.keyboard.press(hotkeyBack)
  92. // clicking opening test
  93. await newBlock(page)
  94. await page.waitForSelector('.page-blocks-inner .ls-block .page-ref >> nth=-1')
  95. await page.click('.page-blocks-inner .ls-block .page-ref >> nth=-1')
  96. await lastBlock(page)
  97. expect(await page.inputValue('textarea >> nth=0')).toBe(alias_test_content_3)
  98. // TODO: test alias from graph clicking
  99. // test alias from search
  100. for (let kw of search_kws) {
  101. let kw_name = kw + ' alias ' + rand
  102. await page.click('#search-button')
  103. await page.waitForSelector('[placeholder="Search or create page"]')
  104. await page.fill('[placeholder="Search or create page"]', kw_name)
  105. await page.waitForTimeout(500)
  106. const results = await page.$$('#ui__ac-inner>div')
  107. expect(results.length).toEqual(3) // page + block + alias property
  108. // test search results
  109. expect(await results[0].innerText()).toContain("Alias -> " + target_name)
  110. expect(await results[0].innerText()).toContain(alias_name)
  111. expect(await results[1].innerText()).toContain(parent_title)
  112. expect(await results[1].innerText()).toContain("[[" + alias_name + "]]")
  113. expect(await results[2].innerText()).toContain(target_name)
  114. expect(await results[2].innerText()).toContain("alias:: [[" + alias_name + "]]")
  115. // test search entering (page)
  116. page.keyboard.press("Enter")
  117. await page.waitForNavigation()
  118. await page.waitForTimeout(100)
  119. await lastBlock(page)
  120. expect(await page.inputValue('textarea >> nth=0')).toBe(alias_test_content_3)
  121. // test search clicking (block)
  122. await page.click('#search-button')
  123. await page.waitForSelector('[placeholder="Search or create page"]')
  124. await page.fill('[placeholder="Search or create page"]', kw_name)
  125. await page.waitForTimeout(500)
  126. page.click(":nth-match(.menu-link, 2)")
  127. await page.waitForNavigation()
  128. await page.waitForTimeout(500)
  129. await lastBlock(page)
  130. expect(await page.inputValue('textarea >> nth=0')).toBe("[[" + alias_name + "]]")
  131. await page.keyboard.press(hotkeyBack)
  132. }
  133. // TODO: search clicking (alias property)
  134. }
  135. test.skip('page diacritic alias', async ({ page }) => {
  136. await alias_test(page, "ü", ["ü", "ü", "Ü"])
  137. })