animatedSidePanePanelLayout.test.ts 5.1 KB

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