@remit/ui 0.0.196 → 0.0.197

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remit/ui",
3
- "version": "0.0.196",
3
+ "version": "0.0.197",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src"
@@ -4,7 +4,7 @@ import { describe, it } from "node:test";
4
4
  import { createElement } from "react";
5
5
  import { renderToString } from "react-dom/server";
6
6
  import type { CalendarDescriptor, EventDraft } from "./calendar-types.js";
7
- import { EventEditor } from "./event-editor.js";
7
+ import { EventEditor, withAllDay } from "./event-editor.js";
8
8
 
9
9
  const calendars: CalendarDescriptor[] = [
10
10
  {
@@ -170,4 +170,27 @@ describe("EventEditor", () => {
170
170
  assert.equal(alertText(dom), "");
171
171
  assert.equal(saveControl(dom)?.disabled, false);
172
172
  });
173
+
174
+ it("restores the overnight end when all day is ticked then unticked", () => {
175
+ const overnight: EventDraft = {
176
+ ...draft,
177
+ startTime: "22:00",
178
+ endDate: "2026-06-13",
179
+ endTime: "01:00",
180
+ };
181
+
182
+ const ticked = withAllDay(overnight, true);
183
+ assert.equal(ticked.allDay, true);
184
+ assert.equal(ticked.endDate, overnight.date);
185
+
186
+ const unticked = withAllDay(ticked, false);
187
+ assert.equal(unticked.allDay, false);
188
+ assert.equal(unticked.endDate, overnight.endDate);
189
+ assert.equal(unticked.startTime, overnight.startTime);
190
+ assert.equal(unticked.endTime, overnight.endTime);
191
+
192
+ const dom = parse({ draft: unticked });
193
+ assert.equal(alertText(dom), "");
194
+ assert.equal(saveControl(dom)?.disabled, false);
195
+ });
173
196
  });
@@ -1,5 +1,6 @@
1
1
  import type { Meta, StoryObj } from "@storybook/react-vite";
2
2
  import { useState } from "react";
3
+ import { expect, userEvent, within } from "storybook/test";
3
4
  import type { CalendarDescriptor, EventDraft } from "./calendar-types.js";
4
5
  import { EventEditor } from "./event-editor.js";
5
6
 
@@ -157,6 +158,28 @@ export const AllDay: Story = {
157
158
  ),
158
159
  };
159
160
 
161
+ /**
162
+ * Ticking All day on a night, then unticking it, gives the night back rather
163
+ * than collapsing the end onto the start day.
164
+ */
165
+ export const AllDayRoundTrip: Story = {
166
+ render: () => <Live startExpanded={false} seed={overnight} />,
167
+ play: async ({ canvasElement }) => {
168
+ const canvas = within(canvasElement);
169
+ const allDay = canvas.getByLabelText("All day");
170
+
171
+ await userEvent.click(allDay);
172
+ await expect(canvas.getByLabelText("End date")).toHaveValue("2026-06-12");
173
+
174
+ await userEvent.click(allDay);
175
+ await expect(canvas.getByLabelText("End date")).toHaveValue("2026-06-13");
176
+ await expect(canvas.getByLabelText("End time")).toHaveValue("01:00");
177
+ await expect(
178
+ canvas.queryByText(/Ends before it starts/),
179
+ ).not.toBeInTheDocument();
180
+ },
181
+ };
182
+
160
183
  /** The same form sized for a bottom sheet: every control a thumb target. */
161
184
  export const Touch: Story = {
162
185
  render: () => {
@@ -106,6 +106,16 @@ export function withAllDay(draft: EventDraft, allDay: boolean): EventDraft {
106
106
  draft.endTime !== "" &&
107
107
  draft.endTime < draft.startTime;
108
108
  if (allDay && overnight) return { ...draft, allDay, endDate: draft.date };
109
+ const collapsedOvernight =
110
+ !allDay &&
111
+ draft.date !== "" &&
112
+ draft.endDate === draft.date &&
113
+ draft.startTime !== "" &&
114
+ draft.endTime !== "" &&
115
+ draft.endTime < draft.startTime;
116
+ if (collapsedOvernight) {
117
+ return { ...draft, allDay, endDate: addDays(draft.date, 1) };
118
+ }
109
119
  return { ...draft, allDay };
110
120
  }
111
121