animatedSidePanePanelLayout.test.ts 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. MIN_PREVIEW_PANE_HEAVY_CONTENT_VISIBLE_INLINE_SIZE_PX,
  4. resolveAnimatedSidePanePanelLayout,
  5. resolveOpenTabLauncherItemIds,
  6. shouldOfferSelectionSideConversation,
  7. shouldRenderPreviewPaneHeavyContent,
  8. } from "@/app-shell/animatedSidePanePanelModel.js";
  9. describe("AnimatedSidePanePanel layout", () => {
  10. it("uses full panel size for mobile overlay instead of the collapsed desktop default", () => {
  11. expect(resolveAnimatedSidePanePanelLayout({ mobileOverlay: true })).toMatchObject({
  12. collapsedSize: "0px",
  13. defaultSize: "100%",
  14. maxSize: "100%",
  15. minSize: "0px",
  16. useResizablePanel: false,
  17. });
  18. });
  19. it("keeps the desktop side pane collapsed by default", () => {
  20. expect(resolveAnimatedSidePanePanelLayout({ mobileOverlay: false })).toMatchObject({
  21. collapsedSize: "0px",
  22. defaultSize: "0px",
  23. maxSize: "65%",
  24. minSize: "240px",
  25. useResizablePanel: true,
  26. });
  27. });
  28. it("defers heavy PreviewPane content while the active code tab is only a narrow viewport sliver", () => {
  29. expect(
  30. shouldRenderPreviewPaneHeavyContent({
  31. isActiveTab: true,
  32. isSidePaneVisible: true,
  33. visibleInlineSizePx: MIN_PREVIEW_PANE_HEAVY_CONTENT_VISIBLE_INLINE_SIZE_PX - 1,
  34. }),
  35. ).toBe(false);
  36. expect(
  37. shouldRenderPreviewPaneHeavyContent({
  38. isActiveTab: true,
  39. isSidePaneVisible: true,
  40. visibleInlineSizePx: MIN_PREVIEW_PANE_HEAVY_CONTENT_VISIBLE_INLINE_SIZE_PX,
  41. }),
  42. ).toBe(true);
  43. });
  44. it("defers heavy PreviewPane content while the side pane is settling after resize", () => {
  45. expect(
  46. shouldRenderPreviewPaneHeavyContent({
  47. isActiveTab: true,
  48. isResizeSettling: true,
  49. isSidePaneVisible: true,
  50. visibleInlineSizePx: 480,
  51. }),
  52. ).toBe(false);
  53. });
  54. it("keeps active media mounted while the side pane is settling after resize", () => {
  55. expect(
  56. shouldRenderPreviewPaneHeavyContent({
  57. isActiveTab: true,
  58. isMediaPreview: true,
  59. isResizeSettling: true,
  60. isSidePaneVisible: true,
  61. visibleInlineSizePx: 480,
  62. }),
  63. ).toBe(true);
  64. });
  65. it("keeps audio media mounted while the side pane is settling after resize", () => {
  66. expect(
  67. shouldRenderPreviewPaneHeavyContent({
  68. isActiveTab: true,
  69. isMediaPreview: true,
  70. isResizeSettling: true,
  71. isSidePaneVisible: true,
  72. visibleInlineSizePx: 480,
  73. }),
  74. ).toBe(true);
  75. });
  76. it("still defers inactive or hidden media and media in a narrow pane after settling", () => {
  77. expect(
  78. shouldRenderPreviewPaneHeavyContent({
  79. isActiveTab: false,
  80. isMediaPreview: true,
  81. isResizeSettling: true,
  82. isSidePaneVisible: true,
  83. visibleInlineSizePx: 480,
  84. }),
  85. ).toBe(false);
  86. expect(
  87. shouldRenderPreviewPaneHeavyContent({
  88. isActiveTab: true,
  89. isMediaPreview: true,
  90. isSidePaneVisible: false,
  91. visibleInlineSizePx: 480,
  92. }),
  93. ).toBe(false);
  94. expect(
  95. shouldRenderPreviewPaneHeavyContent({
  96. isActiveTab: true,
  97. isMediaPreview: true,
  98. isSidePaneVisible: true,
  99. visibleInlineSizePx: MIN_PREVIEW_PANE_HEAVY_CONTENT_VISIBLE_INLINE_SIZE_PX - 1,
  100. }),
  101. ).toBe(false);
  102. });
  103. it("keeps PreviewPane heavy content mounted when visibility measurement is unavailable", () => {
  104. expect(
  105. shouldRenderPreviewPaneHeavyContent({
  106. isActiveTab: true,
  107. isSidePaneVisible: true,
  108. visibleInlineSizePx: null,
  109. }),
  110. ).toBe(true);
  111. expect(
  112. shouldRenderPreviewPaneHeavyContent({
  113. isActiveTab: false,
  114. isSidePaneVisible: true,
  115. visibleInlineSizePx: 480,
  116. }),
  117. ).toBe(false);
  118. expect(
  119. shouldRenderPreviewPaneHeavyContent({
  120. isActiveTab: true,
  121. isSidePaneVisible: false,
  122. visibleInlineSizePx: 480,
  123. }),
  124. ).toBe(false);
  125. });
  126. it("keeps PreviewPane heavy content mounted inside the mobile overlay drawer", () => {
  127. expect(
  128. shouldRenderPreviewPaneHeavyContent({
  129. isActiveTab: true,
  130. isMobileOverlay: true,
  131. isResizeSettling: true,
  132. isSidePaneVisible: true,
  133. visibleInlineSizePx: 0,
  134. }),
  135. ).toBe(true);
  136. });
  137. it("omits the browser launcher item when embedded browser tabs are unsupported", () => {
  138. expect(
  139. resolveOpenTabLauncherItemIds({
  140. developerToolsEnabled: false,
  141. hasReviewTab: false,
  142. supportsEmbeddedBrowser: false,
  143. }),
  144. ).toEqual(["review", "terminal"]);
  145. expect(
  146. resolveOpenTabLauncherItemIds({
  147. developerToolsEnabled: false,
  148. hasReviewTab: false,
  149. supportsEmbeddedBrowser: true,
  150. }),
  151. ).toEqual(["review", "terminal", "browser"]);
  152. });
  153. it("adds the side conversation launcher only when a desktop parent task is available", () => {
  154. expect(
  155. resolveOpenTabLauncherItemIds({
  156. canOpenSelectionSideConversation: true,
  157. developerToolsEnabled: false,
  158. hasReviewTab: false,
  159. }),
  160. ).toEqual(["selection-side-conversation", "review", "terminal", "browser"]);
  161. expect(
  162. resolveOpenTabLauncherItemIds({
  163. canOpenSelectionSideConversation: false,
  164. developerToolsEnabled: false,
  165. hasReviewTab: false,
  166. }),
  167. ).toEqual(["review", "terminal", "browser"]);
  168. });
  169. it("hides the side conversation entry without an active task and on mobile", () => {
  170. expect(
  171. shouldOfferSelectionSideConversation({
  172. activeTaskId: "parent-running-or-blocked",
  173. isMobileTextInputViewport: false,
  174. mobileOverlay: false,
  175. }),
  176. ).toBe(true);
  177. expect(
  178. shouldOfferSelectionSideConversation({
  179. activeTaskId: null,
  180. isMobileTextInputViewport: false,
  181. mobileOverlay: false,
  182. }),
  183. ).toBe(false);
  184. expect(
  185. shouldOfferSelectionSideConversation({
  186. activeTaskId: "parent-mobile",
  187. isMobileTextInputViewport: true,
  188. mobileOverlay: true,
  189. }),
  190. ).toBe(false);
  191. });
  192. });