session-tabs-marquee.test.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { afterEach, describe, expect, jest, test } from "bun:test"
  2. import { createRoot } from "solid-js"
  3. import { createMarquee, createTabMarquee } from "../../src/component/session-tabs"
  4. afterEach(() => jest.useRealTimers())
  5. describe("session tab marquee", () => {
  6. test("starts for the hovered width and resets when the next tab fits", () => {
  7. jest.useFakeTimers()
  8. const scope = createRoot((dispose) => ({ marquee: createMarquee(() => false), dispose }))
  9. scope.marquee.enter("first", "opencode", 6)
  10. expect(scope.marquee.active()).toBe("first")
  11. expect(scope.marquee.offset()).toBe(0)
  12. jest.advanceTimersByTime(600)
  13. expect(scope.marquee.offset()).toBe(1)
  14. scope.marquee.enter("second", "short", 6)
  15. expect(scope.marquee.active()).toBeUndefined()
  16. expect(scope.marquee.offset()).toBe(0)
  17. expect(scope.marquee.leading()).toBe(0)
  18. scope.dispose()
  19. })
  20. test("keeps the leading fade through a natural loop boundary", () => {
  21. jest.useFakeTimers()
  22. const scope = createRoot((dispose) => ({ marquee: createMarquee(() => false), dispose }))
  23. scope.marquee.enter("first", "opencode", 6)
  24. jest.advanceTimersByTime(1_400)
  25. expect(scope.marquee.active()).toBe("first")
  26. expect(scope.marquee.offset()).toBe(0)
  27. expect(scope.marquee.leading()).toBe(1)
  28. scope.dispose()
  29. })
  30. test("resets immediately after leaving", () => {
  31. jest.useFakeTimers()
  32. const scope = createRoot((dispose) => ({ marquee: createMarquee(() => false), dispose }))
  33. scope.marquee.enter("first", "opencode", 6)
  34. jest.advanceTimersByTime(700)
  35. scope.marquee.leave("first")
  36. expect(scope.marquee.active()).toBeUndefined()
  37. expect(scope.marquee.offset()).toBe(0)
  38. expect(scope.marquee.leading()).toBe(0)
  39. scope.dispose()
  40. })
  41. test("resets when the pointer leaves the tab rail", () => {
  42. jest.useFakeTimers()
  43. const scope = createRoot((dispose) => ({ marquee: createTabMarquee(() => false), dispose }))
  44. scope.marquee.enter("first", "opencode", 6)
  45. jest.advanceTimersByTime(700)
  46. scope.marquee.leaveHovered()
  47. jest.advanceTimersByTime(0)
  48. expect(scope.marquee.hovered()).toBeUndefined()
  49. expect(scope.marquee.active()).toBeUndefined()
  50. expect(scope.marquee.offset()).toBe(0)
  51. scope.dispose()
  52. })
  53. })