Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 775486f

Browse files
committedSep 13, 2024
fix: ensure that mock query cache key and component key are properly synced for storybook
1 parent 17a9e8c commit 775486f

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed
 

‎site/src/api/queries/workspaceQuota.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const getWorkspaceQuotaQueryKey = (
44
organizationName: string,
55
username: string,
66
) => {
7-
return [organizationName, username, "workspaceQuota"];
7+
return ["workspaceQuota", organizationName, username];
88
};
99

1010
export const workspaceQuota = (organizationName: string, username: string) => {

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

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Meta, StoryObj } from "@storybook/react";
22
import { expect, screen, userEvent, waitFor, within } from "@storybook/test";
33
import { getWorkspaceQuotaQueryKey } from "api/queries/workspaceQuota";
4+
import type { Workspace, WorkspaceQuota } from "api/typesGenerated";
45
import { addHours, addMinutes } from "date-fns";
56
import {
67
MockOrganization,
@@ -12,9 +13,12 @@ import {
1213
import { withDashboardProvider } from "testHelpers/storybook";
1314
import { WorkspaceTopbar } from "./WorkspaceTopbar";
1415

15-
// We want a workspace without a deadline to not pollute the screenshot
16-
const baseWorkspace = {
16+
// We want a workspace without a deadline to not pollute the screenshot. Also
17+
// want to make sure that the workspace is synced to our other mock values
18+
const baseWorkspace: Workspace = {
1719
...MockWorkspace,
20+
organization_name: MockOrganization.name,
21+
organization_id: MockOrganization.id,
1822
latest_build: {
1923
...MockWorkspace.latest_build,
2024
deadline: undefined,
@@ -263,8 +267,9 @@ export const WithFarAwayDeadlineRequiredByTemplate: Story = {
263267
},
264268
};
265269

266-
export const WithQuota: Story = {
270+
export const WithQuotaNoOrgs: Story = {
267271
parameters: {
272+
showOrganizations: false,
268273
queries: [
269274
{
270275
key: getWorkspaceQuotaQueryKey(
@@ -274,7 +279,25 @@ export const WithQuota: Story = {
274279
data: {
275280
credits_consumed: 2,
276281
budget: 40,
277-
},
282+
} satisfies WorkspaceQuota,
283+
},
284+
],
285+
},
286+
};
287+
288+
export const WithQuotaWithOrgs: Story = {
289+
parameters: {
290+
showOrganizations: true,
291+
queries: [
292+
{
293+
key: getWorkspaceQuotaQueryKey(
294+
MockOrganization.name,
295+
MockUser.username,
296+
),
297+
data: {
298+
credits_consumed: 2,
299+
budget: 40,
300+
} satisfies WorkspaceQuota,
278301
},
279302
],
280303
},

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export const WorkspaceTopbar: FC<WorkspaceProps> = ({
116116
(org) => org.id === workspace.organization_id,
117117
);
118118

119-
const orgDisplayName = activeOrg?.display_name ?? workspace.organization_name;
119+
const orgDisplayName = activeOrg?.display_name || workspace.organization_name;
120120

121121
const isImmutable =
122122
workspace.latest_build.status === "deleted" ||

0 commit comments

Comments
 (0)
Failed to load comments.