sidebar.spec.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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.waitForTimeout(500);
  19. await page.click(":nth-match(.favorite-item, 1)")
  20. await page.waitForTimeout(500);
  21. expect(await page.innerText('.page-title .title')).toBe(fav_page_name)
  22. expect(await page.innerText(':nth-match(.recent-item a, 1)')).toBe(fav_page_name)
  23. expect(await page.innerText(':nth-match(.recent-item a, 2)')).toBe(another_page_name)
  24. // remove fav
  25. await page.click('.ui__dropdown-trigger .toolbar-dots-btn')
  26. await page.locator("text=Unfavorite page").click()
  27. await expect(page.locator('.favorite-item a')).toHaveCount(previous_fav_count)
  28. // click from fav page
  29. await page.click(':nth-match(.recent-item a, 2)')
  30. await expect(page.locator('.page-title .title')).toHaveText(another_page_name)
  31. })
  32. test('recent is updated #4320', async ({ page }) => {
  33. const page1 = await createRandomPage(page)
  34. await page.fill('textarea >> nth=0', 'Random Thought')
  35. const page2 = await createRandomPage(page)
  36. await page.fill('textarea >> nth=0', 'Another Random Thought')
  37. const firstRecent = page.locator('.nav-content-item.recent li >> nth=0')
  38. expect(await firstRecent.textContent()).toContain(page2)
  39. const secondRecent = page.locator('.nav-content-item.recent li >> nth=1')
  40. expect(await secondRecent.textContent()).toContain(page1)
  41. // then jump back
  42. await searchAndJumpToPage(page, page1)
  43. await page.waitForTimeout(500)
  44. expect(await firstRecent.textContent()).toContain(page1)
  45. expect(await secondRecent.textContent()).toContain(page2)
  46. })
  47. test('recent file name is displayed correctly #6297', async ({ page }) => {
  48. const pageName = randomString(5) + "_@#$%^&*()_" + randomString(5)
  49. await createPage(page, pageName)
  50. await page.fill('textarea >> nth=0', 'Random Content')
  51. const firstRecent = page.locator('.nav-content-item.recent li >> nth=0')
  52. expect(await firstRecent.textContent()).toContain(pageName)
  53. })