sidebar.spec.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { expect } from '@playwright/test'
  2. import { test } from './fixtures'
  3. import { createPage, createRandomPage, openLeftSidebar, randomString, searchAndJumpToPage } from './utils'
  4. /***
  5. * Test side bar features
  6. ***/
  7. test('favorite item and recent item test', async ({ page }) => {
  8. await openLeftSidebar(page)
  9. // add page to fav
  10. const fav_page_name = await createRandomPage(page)
  11. let favs = await page.$$('.favorite-item a')
  12. let previous_fav_count = favs.length
  13. await page.click('.ui__dropdown-trigger .toolbar-dots-btn')
  14. await page.locator("text=Add to Favorites").click()
  15. // click from another page
  16. const another_page_name = await createRandomPage(page)
  17. expect(await page.innerText(':nth-match(.favorite-item a, 1)')).toBe(fav_page_name)
  18. await page.click(":nth-match(.favorite-item, 1)")
  19. expect(await page.innerText('.page-title .title')).toBe(fav_page_name)
  20. expect(await page.innerText(':nth-match(.recent-item a, 1)')).toBe(fav_page_name)
  21. expect(await page.innerText(':nth-match(.recent-item a, 2)')).toBe(another_page_name)
  22. // remove fav
  23. await page.click('.ui__dropdown-trigger .toolbar-dots-btn')
  24. await page.locator("text=Unfavorite page").click()
  25. await expect(page.locator('.favorite-item a')).toHaveCount(previous_fav_count)
  26. // click from fav page
  27. await page.click(':nth-match(.recent-item a, 2)')
  28. await expect(page.locator('.page-title .title')).toHaveText(another_page_name)
  29. })
  30. test('recent is updated #4320', async ({ page }) => {
  31. const page1 = await createRandomPage(page)
  32. await page.fill('textarea >> nth=0', 'Random Thought')
  33. const page2 = await createRandomPage(page)
  34. await page.fill('textarea >> nth=0', 'Another Random Thought')
  35. const firstRecent = page.locator('.nav-content-item.recent li >> nth=0')
  36. expect(await firstRecent.textContent()).toContain(page2)
  37. const secondRecent = page.locator('.nav-content-item.recent li >> nth=1')
  38. expect(await secondRecent.textContent()).toContain(page1)
  39. // then jump back
  40. await searchAndJumpToPage(page, page1)
  41. await page.waitForTimeout(500)
  42. expect(await firstRecent.textContent()).toContain(page1)
  43. expect(await secondRecent.textContent()).toContain(page2)
  44. })
  45. test('recent file name is displayed correctly #6297', async ({ page }) => {
  46. const pageName = randomString(5) + "_@#$%^&*()_" + randomString(5)
  47. await createPage(page, pageName)
  48. await page.fill('textarea >> nth=0', 'Random Content')
  49. const firstRecent = page.locator('.nav-content-item.recent li >> nth=0')
  50. expect(await firstRecent.textContent()).toContain(pageName)
  51. })