sidebar.spec.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { expect } from '@playwright/test'
  2. import { test } from './fixtures'
  3. import { createRandomPage, searchAndJumpToPage } from './utils'
  4. /***
  5. * Test side bar features
  6. ***/
  7. test('favorite item and recent item test', async ({ page }) => {
  8. // add page to fav
  9. const fav_page_name = await createRandomPage(page)
  10. let favs = await page.$$('.favorite-item a')
  11. let previous_fav_count = favs.length
  12. await page.click('.ui__dropdown-trigger')
  13. await page.click(':nth-match(.ui__dropdown-trigger .dropdown-wrapper a, 1)')
  14. // click from another page
  15. const another_page_name = await createRandomPage(page)
  16. expect(await page.innerText(':nth-match(.favorite-item a, 1)')).toBe('◦' + fav_page_name)
  17. await page.click(":nth-match(.favorite-item, 1)")
  18. expect(await page.innerText('.page-title .title')).toBe(fav_page_name)
  19. expect(await page.innerText(':nth-match(.recent-item a, 1)')).toBe('◦' + fav_page_name)
  20. expect(await page.innerText(':nth-match(.recent-item a, 2)')).toBe('◦' + another_page_name)
  21. // remove fav
  22. await page.click('.ui__dropdown-trigger')
  23. await page.click(':nth-match(.ui__dropdown-trigger .dropdown-wrapper a, 1)')
  24. await page.waitForTimeout(1000)
  25. favs = await page.$$('.favorite-item a')
  26. expect(favs.length).toEqual(previous_fav_count)
  27. // click from fav page
  28. await page.click(':nth-match(.recent-item a, 2)')
  29. expect(await page.innerText('.page-title .title')).toBe(another_page_name)
  30. })
  31. test('recent is updated #4320', async ({ page }) => {
  32. const page1 = await createRandomPage(page)
  33. await page.fill(':nth-match(textarea, 1)', 'Random Thought')
  34. const page2 = await createRandomPage(page)
  35. await page.fill(':nth-match(textarea, 1)', 'Another Random Thought')
  36. const firstRecent = page.locator('.nav-content-item.recent li >> nth=0')
  37. expect(await firstRecent.textContent()).toContain(page2)
  38. const secondRecent = page.locator('.nav-content-item.recent li >> nth=1')
  39. expect(await secondRecent.textContent()).toContain(page1)
  40. // then jump back
  41. await searchAndJumpToPage(page, page1)
  42. expect(await firstRecent.textContent()).toContain(page1)
  43. expect(await secondRecent.textContent()).toContain(page2)
  44. })