Skip to content

Commit 75ed4f7

Browse files
committed
🧹
1 parent 5e48e1a commit 75ed4f7

File tree

4 files changed

+45
-27
lines changed

4 files changed

+45
-27
lines changed

site/src/pages/WorkspacePage/WorkspaceScheduleControls.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ test("add 3 hours to deadline", async () => {
9494
);
9595
});
9696

97-
test("remove 3 hours to deadline", async () => {
97+
test("remove 2 hours to deadline", async () => {
9898
const user = userEvent.setup();
9999
const updateDeadlineSpy = jest
100100
.spyOn(API, "putWorkspaceExtension")

site/src/pages/WorkspacePage/WorkspaceScheduleControls.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,12 @@ export const WorkspaceScheduleContainer: FC<
5252
<TopbarData>
5353
<Tooltip title="Schedule">
5454
{onClickIcon ? (
55-
<span
55+
<button
56+
data-testid="schedule-icon-button"
5657
onClick={onClickIcon}
5758
css={{
59+
display: "flex",
60+
alignItems: "center",
5861
background: "transparent",
5962
border: 0,
6063
padding: 0,
@@ -63,7 +66,7 @@ export const WorkspaceScheduleContainer: FC<
6366
}}
6467
>
6568
{icon}
66-
</span>
69+
</button>
6770
) : (
6871
icon
6972
)}

site/src/pages/WorkspacePage/WorkspaceTopbar.stories.tsx

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,34 +50,12 @@ export const Outdated: Story = {
5050
},
5151
};
5252

53-
export const Ready: Story = {
54-
args: {
55-
workspace: {
56-
...baseWorkspace,
57-
get last_used_at() {
58-
return new Date().toISOString();
59-
},
60-
latest_build: {
61-
...baseWorkspace.latest_build,
62-
get created_at() {
63-
return new Date().toISOString();
64-
},
65-
},
66-
},
67-
},
68-
};
6953
export const ReadyWithDeadline: Story = {
7054
args: {
7155
workspace: {
7256
...MockWorkspace,
73-
get last_used_at() {
74-
return new Date().toISOString();
75-
},
7657
latest_build: {
7758
...MockWorkspace.latest_build,
78-
get created_at() {
79-
return new Date().toISOString();
80-
},
8159
get deadline() {
8260
return addHours(new Date(), 8).toISOString();
8361
},
@@ -111,6 +89,24 @@ export const ConnectedWithDeadline: Story = {
11189
},
11290
},
11391
},
92+
play: async ({ canvasElement, step }) => {
93+
const screen = within(canvasElement);
94+
const autostopText = "Stop in 8 hours";
95+
96+
await step("show controls", async () => {
97+
await userEvent.click(screen.getByTestId("schedule-icon-button"));
98+
await waitFor(() =>
99+
expect(screen.getByText(autostopText)).toBeInTheDocument(),
100+
);
101+
});
102+
103+
await step("hide controls", async () => {
104+
await userEvent.click(screen.getByTestId("schedule-icon-button"));
105+
await waitFor(() =>
106+
expect(screen.queryByText(autostopText)).not.toBeInTheDocument(),
107+
);
108+
});
109+
},
114110
};
115111
export const ConnectedWithMaxDeadline: Story = {
116112
args: {
@@ -130,6 +126,24 @@ export const ConnectedWithMaxDeadline: Story = {
130126
},
131127
},
132128
},
129+
play: async ({ canvasElement, step }) => {
130+
const screen = within(canvasElement);
131+
const autostopText = "Stop in an hour";
132+
133+
await step("show controls", async () => {
134+
await userEvent.click(screen.getByTestId("schedule-icon-button"));
135+
await waitFor(() =>
136+
expect(screen.getByText(autostopText)).toBeInTheDocument(),
137+
);
138+
});
139+
140+
await step("hide controls", async () => {
141+
await userEvent.click(screen.getByTestId("schedule-icon-button"));
142+
await waitFor(() =>
143+
expect(screen.queryByText(autostopText)).not.toBeInTheDocument(),
144+
);
145+
});
146+
},
133147
};
134148
export const ConnectedWithMaxDeadlineSoon: Story = {
135149
args: {

site/src/utils/schedule.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,12 @@ export const autostopDisplay = (
114114
const deadline = dayjs(workspace.latest_build.deadline).tz(
115115
dayjs.tz.guess(),
116116
);
117-
const maxDeadline = dayjs(workspace.latest_build.max_deadline);
118117
const now = dayjs(workspace.latest_build.deadline);
119118

120119
if (activityStatus === "connected") {
121-
if (maxDeadline.isBefore(now.add(2, "hour"))) {
120+
const hasMaxDeadline = Boolean(workspace.latest_build.max_deadline);
121+
const maxDeadline = dayjs(workspace.latest_build.max_deadline);
122+
if (hasMaxDeadline && maxDeadline.isBefore(now.add(2, "hour"))) {
122123
return {
123124
message: `Required to stop soon`,
124125
tooltip: (

0 commit comments

Comments
 (0)