mobileInputZoom.test.ts 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. shouldResetLexicalEditorAfterSubmit,
  4. shouldSubmitLexicalEnter,
  5. shouldSubmitLexicalModifiedEnter,
  6. } from "@/LexicalChatInput.js";
  7. import {
  8. isPrimaryFollowupModifierPressed,
  9. resolveOppositeFollowupDelivery,
  10. resolveFollowupModifierTooltip,
  11. shouldEnableModifiedEnterSubmit,
  12. shouldReverseFollowupDeliveryForPointer,
  13. } from "@/v4/composer/followupModeSettings.js";
  14. import {
  15. resolveChatEnterShortcut,
  16. resolveChatEnterSubmits,
  17. shouldAvoidIosInputFocusZoom,
  18. } from "@/lib/mobileTextInput.js";
  19. describe("mobile text input zoom guard", () => {
  20. it("keeps modified submit on desktop drafts and Windows coarse-pointer viewports", () => {
  21. expect(
  22. shouldEnableModifiedEnterSubmit({
  23. inputRoutingMode: "startNow",
  24. isMobileTextInputViewport: true,
  25. isWebRemoteControl: false,
  26. }),
  27. ).toBe(true);
  28. expect(
  29. shouldEnableModifiedEnterSubmit({
  30. inputRoutingMode: "enqueue",
  31. isMobileTextInputViewport: true,
  32. isWebRemoteControl: false,
  33. }),
  34. ).toBe(true);
  35. expect(
  36. shouldEnableModifiedEnterSubmit({
  37. inputRoutingMode: "enqueue",
  38. isMobileTextInputViewport: true,
  39. isWebRemoteControl: true,
  40. }),
  41. ).toBe(false);
  42. expect(
  43. shouldEnableModifiedEnterSubmit({
  44. inputRoutingMode: "reject",
  45. isMobileTextInputViewport: false,
  46. isWebRemoteControl: false,
  47. }),
  48. ).toBe(false);
  49. });
  50. it("resolves Cmd/Ctrl+Enter as send-now for queue and queue for guide", () => {
  51. expect(resolveOppositeFollowupDelivery("queue")).toBe("startNow");
  52. expect(resolveOppositeFollowupDelivery("guide")).toBe("queue");
  53. expect(
  54. shouldSubmitLexicalModifiedEnter({
  55. ctrlKey: true,
  56. modifiedEnterSubmits: true,
  57. text: "opposite delivery",
  58. }),
  59. ).toBe(true);
  60. expect(
  61. shouldSubmitLexicalModifiedEnter({
  62. metaKey: true,
  63. modifiedEnterSubmits: true,
  64. text: "opposite delivery",
  65. }),
  66. ).toBe(true);
  67. expect(
  68. shouldSubmitLexicalModifiedEnter({
  69. ctrlKey: true,
  70. isComposing: true,
  71. modifiedEnterSubmits: true,
  72. text: "IME",
  73. }),
  74. ).toBe(false);
  75. expect(
  76. shouldSubmitLexicalModifiedEnter({
  77. ctrlKey: true,
  78. modifiedEnterSubmits: true,
  79. shiftKey: true,
  80. text: "keep newline",
  81. }),
  82. ).toBe(false);
  83. });
  84. it("only clears the Lexical editor when the submit callback accepts the clear", () => {
  85. expect(shouldResetLexicalEditorAfterSubmit()).toBe(true);
  86. expect(shouldResetLexicalEditorAfterSubmit(true)).toBe(true);
  87. expect(shouldResetLexicalEditorAfterSubmit(false)).toBe(false);
  88. });
  89. it("only reverses pointer delivery for an enabled desktop modifier click", () => {
  90. expect(
  91. shouldReverseFollowupDeliveryForPointer({ enabled: true, metaKey: true, ctrlKey: false }),
  92. ).toBe(true);
  93. expect(
  94. shouldReverseFollowupDeliveryForPointer({ enabled: true, metaKey: false, ctrlKey: true }),
  95. ).toBe(true);
  96. expect(
  97. shouldReverseFollowupDeliveryForPointer({ enabled: true, metaKey: false, ctrlKey: false }),
  98. ).toBe(false);
  99. expect(
  100. shouldReverseFollowupDeliveryForPointer({ enabled: false, metaKey: true, ctrlKey: false }),
  101. ).toBe(false);
  102. });
  103. it("resolves the automatic opposite-action tooltip with a platform shortcut", () => {
  104. expect(
  105. resolveFollowupModifierTooltip({
  106. enabled: true,
  107. canSend: true,
  108. modifierPressed: true,
  109. followupMode: "queue",
  110. isApplePlatform: true,
  111. }),
  112. ).toEqual({
  113. delivery: "startNow",
  114. shortcut: "⌘ + Enter",
  115. titleId: "chat.followup.sendNow",
  116. });
  117. expect(
  118. resolveFollowupModifierTooltip({
  119. enabled: true,
  120. canSend: true,
  121. modifierPressed: true,
  122. followupMode: "guide",
  123. isApplePlatform: false,
  124. }),
  125. ).toEqual({
  126. delivery: "queue",
  127. shortcut: "Ctrl + Enter",
  128. titleId: "chat.followup.addToQueue",
  129. });
  130. expect(
  131. resolveFollowupModifierTooltip({
  132. enabled: true,
  133. canSend: false,
  134. modifierPressed: true,
  135. followupMode: "queue",
  136. isApplePlatform: true,
  137. }),
  138. ).toBeNull();
  139. });
  140. it("tracks only the platform primary follow-up modifier", () => {
  141. expect(
  142. isPrimaryFollowupModifierPressed({ isApplePlatform: true, metaKey: true, ctrlKey: false }),
  143. ).toBe(true);
  144. expect(
  145. isPrimaryFollowupModifierPressed({ isApplePlatform: true, metaKey: false, ctrlKey: true }),
  146. ).toBe(false);
  147. expect(
  148. isPrimaryFollowupModifierPressed({ isApplePlatform: false, metaKey: false, ctrlKey: true }),
  149. ).toBe(true);
  150. expect(
  151. isPrimaryFollowupModifierPressed({ isApplePlatform: false, metaKey: true, ctrlKey: false }),
  152. ).toBe(false);
  153. });
  154. it("keeps Enter as newline for mobile web remote control only", () => {
  155. const mobileRemoteEnterSubmits = resolveChatEnterSubmits({
  156. isMobileTextInputViewport: true,
  157. preferEnterNewline: true,
  158. });
  159. expect(mobileRemoteEnterSubmits).toBe(false);
  160. expect(resolveChatEnterShortcut({ enterSubmits: mobileRemoteEnterSubmits })).toBeUndefined();
  161. expect(
  162. shouldSubmitLexicalEnter({
  163. enterSubmits: mobileRemoteEnterSubmits,
  164. text: "first line",
  165. }),
  166. ).toBe(false);
  167. expect(
  168. resolveChatEnterSubmits({
  169. isMobileTextInputViewport: false,
  170. preferEnterNewline: true,
  171. }),
  172. ).toBe(true);
  173. });
  174. it("desktop viewports and non-remote inputs do not enable the zoom guard", () => {
  175. expect(
  176. shouldAvoidIosInputFocusZoom({
  177. isMobileTextInputViewport: false,
  178. isWebRemoteControl: true,
  179. }),
  180. ).toBe(false);
  181. expect(
  182. shouldAvoidIosInputFocusZoom({
  183. isMobileTextInputViewport: true,
  184. isWebRemoteControl: false,
  185. }),
  186. ).toBe(false);
  187. });
  188. it("enables the zoom guard for mobile remote input", () => {
  189. expect(
  190. shouldAvoidIosInputFocusZoom({
  191. isMobileTextInputViewport: true,
  192. isWebRemoteControl: true,
  193. }),
  194. ).toBe(true);
  195. });
  196. });