shareHeaderLayout.test.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import { describe, expect, it } from "vitest";
  2. import { resolveShareHeaderView } from "../src/share/shareHeaderLayout.js";
  3. describe("share header continuous layout", () => {
  4. const base = {
  5. shellWidth: 1200,
  6. railContentLeft: 220,
  7. railContentRight: 220,
  8. brandWidth: 50,
  9. titleContentWidth: 500,
  10. continueWidth: 153,
  11. gap: 16,
  12. };
  13. it("keeps the wide anchors while both gutters have enough room", () => {
  14. const view = resolveShareHeaderView(base);
  15. expect(view.progress).toBe(1);
  16. expect(view.brandLeft).toBe(24);
  17. expect(view.titleLeft).toBe(220);
  18. expect(view.continueRight).toBe(24);
  19. expect(view.continueVisible).toBe(true);
  20. expect(view.titleWidth).toBe(760);
  21. expect(view.titleTruncated).toBe(false);
  22. });
  23. it("only starts left-side compression after the left gutter is insufficient", () => {
  24. const wide = resolveShareHeaderView({ ...base, railContentLeft: 220, railContentRight: 220 });
  25. const insufficient = resolveShareHeaderView({
  26. ...base,
  27. railContentLeft: 45,
  28. railContentRight: 220,
  29. });
  30. const narrow = resolveShareHeaderView({ ...base, railContentLeft: 20, railContentRight: 220 });
  31. expect(wide.brandLeft).toBe(24);
  32. expect(insufficient.brandLeft).toBeGreaterThan(wide.brandLeft);
  33. expect(insufficient.brandLeft).toBeGreaterThan(narrow.brandLeft);
  34. expect(insufficient.continueRight).toBe(wide.continueRight);
  35. });
  36. it("only starts right-side compression after the right gutter is insufficient", () => {
  37. const wide = resolveShareHeaderView({ ...base, railContentLeft: 220, railContentRight: 220 });
  38. const insufficient = resolveShareHeaderView({
  39. ...base,
  40. railContentLeft: 220,
  41. railContentRight: 96,
  42. });
  43. const narrow = resolveShareHeaderView({ ...base, railContentLeft: 220, railContentRight: 20 });
  44. expect(wide.continueRight).toBe(24);
  45. expect(insufficient.continueRight).toBeGreaterThan(wide.continueRight);
  46. expect(insufficient.continueRight).toBeGreaterThan(narrow.continueRight);
  47. expect(insufficient.brandLeft).toBe(wide.brandLeft);
  48. });
  49. it("does not reserve a CTA when the share is readonly", () => {
  50. const view = resolveShareHeaderView({
  51. ...base,
  52. continueWidth: 0,
  53. railContentLeft: 220,
  54. railContentRight: 220,
  55. });
  56. expect(view.progress).toBe(1);
  57. expect(view.continueVisible).toBe(false);
  58. expect(view.continueRight).toBe(24);
  59. expect(view.titleWidth).toBe(760);
  60. });
  61. it("keeps the title and CTA separated at every progress value", () => {
  62. for (let gutter = 0; gutter <= 700; gutter += 1) {
  63. const view = resolveShareHeaderView({
  64. ...base,
  65. railContentLeft: gutter,
  66. railContentRight: gutter,
  67. });
  68. const continueLeft = base.shellWidth - view.continueRight - base.continueWidth;
  69. expect(view.titleLeft + view.titleWidth).toBeLessThanOrEqual(continueLeft - base.gap + 1e-8);
  70. expect(view.titleWidth).toBeGreaterThanOrEqual(0);
  71. }
  72. });
  73. it("accounts for locale-dependent CTA width without a fixed breakpoint", () => {
  74. const chinese = resolveShareHeaderView({
  75. ...base,
  76. continueWidth: 153,
  77. railContentLeft: 250,
  78. railContentRight: 250,
  79. });
  80. const english = resolveShareHeaderView({
  81. ...base,
  82. continueWidth: 260,
  83. railContentLeft: 250,
  84. railContentRight: 250,
  85. });
  86. expect(chinese.progress).toBeGreaterThan(english.progress);
  87. expect(chinese.continueVisible).toBe(true);
  88. expect(english.continueVisible).toBe(true);
  89. });
  90. it("compacts the CTA before a narrow shell collapses the share title", () => {
  91. const view = resolveShareHeaderView({
  92. ...base,
  93. shellWidth: 320,
  94. railContentLeft: 16,
  95. railContentRight: 16,
  96. continueWidth: 201,
  97. compactContinueWidth: 76,
  98. hasContinueAction: true,
  99. });
  100. expect(view.continueVisible).toBe(true);
  101. expect(view.continueCompact).toBe(true);
  102. expect(view.titleWidth).toBeGreaterThanOrEqual(80);
  103. });
  104. it("does not mark the theme-only readonly trailing slot as a compact CTA", () => {
  105. const view = resolveShareHeaderView({
  106. ...base,
  107. continueWidth: 32,
  108. compactContinueWidth: 32,
  109. hasContinueAction: false,
  110. });
  111. expect(view.continueVisible).toBe(false);
  112. expect(view.continueCompact).toBe(false);
  113. });
  114. });