-
Notifications
You must be signed in to change notification settings - Fork 899
feat: integrate backend with idp sync page #14755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
a40ba7d
7ff9a07
6e303f4
310726b
615c8d3
45f4d13
080b032
8e1e021
c863619
41631f0
3db9f48
431beea
f166784
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { expect, fn, userEvent, waitFor, within } from "@storybook/test"; | ||
import { | ||
MockGroupSyncSettings, | ||
MockOrganization, | ||
MockRoleSyncSettings, | ||
} from "testHelpers/entities"; | ||
import { ExportPolicyButton } from "./ExportPolicyButton"; | ||
|
||
const meta: Meta<typeof ExportPolicyButton> = { | ||
title: "modules/resources/ExportPolicyButton", | ||
component: ExportPolicyButton, | ||
args: { | ||
policy: JSON.stringify(MockGroupSyncSettings, null, 2), | ||
type: "groups", | ||
organization: MockOrganization, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof ExportPolicyButton>; | ||
|
||
export const Default: Story = {}; | ||
|
||
export const ClickExportGroupPolicy: Story = { | ||
args: { | ||
policy: JSON.stringify(MockGroupSyncSettings, null, 2), | ||
type: "groups", | ||
organization: MockOrganization, | ||
download: fn(), | ||
}, | ||
play: async ({ canvasElement, args }) => { | ||
const canvas = within(canvasElement); | ||
await userEvent.click( | ||
canvas.getByRole("button", { name: "Export Policy" }), | ||
); | ||
await waitFor(() => | ||
expect(args.download).toHaveBeenCalledWith( | ||
expect.anything(), | ||
`${MockOrganization.name}_groups-policy.json`, | ||
), | ||
); | ||
const blob: Blob = (args.download as jest.Mock).mock.calls[0][0]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh this is so gross (but I don't know what to suggest to make it better) could you add a comment above it to elaborate why this incantation is justified/necessary? I think I understand what it's doing, but clarity is good, and more junior devs might not get it! |
||
await expect(blob.type).toEqual("application/json"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we also assert that the blob contents match the |
||
}, | ||
}; | ||
|
||
export const ClickExportRolePolicy: Story = { | ||
args: { | ||
policy: JSON.stringify(MockRoleSyncSettings, null, 2), | ||
type: "roles", | ||
organization: MockOrganization, | ||
download: fn(), | ||
}, | ||
play: async ({ canvasElement, args }) => { | ||
const canvas = within(canvasElement); | ||
await userEvent.click( | ||
canvas.getByRole("button", { name: "Export Policy" }), | ||
); | ||
await waitFor(() => | ||
expect(args.download).toHaveBeenCalledWith( | ||
expect.anything(), | ||
`${MockOrganization.name}_roles-policy.json`, | ||
), | ||
); | ||
const blob: Blob = (args.download as jest.Mock).mock.calls[0][0]; | ||
await expect(blob.type).toEqual("application/json"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comments for the group story apply here |
||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,12 +9,14 @@ interface DownloadPolicyButtonProps { | |
policy: string | null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any information on how policies are defined? I'm seeing that we're downloading just the policy itself when the user clicks the button There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The policy is meant to be a json representation of |
||
type: "groups" | "roles"; | ||
organization: Organization; | ||
download?: (file: Blob, filename: string) => void; | ||
} | ||
|
||
export const ExportPolicyButton: FC<DownloadPolicyButtonProps> = ({ | ||
policy, | ||
type, | ||
organization, | ||
download = saveAs, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure how big of a deal this is, but the current implementation means that we can't add additional functionality without completely overriding the default How often would we have a use case where we'd want to get rid of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was meant to just support the Storybook test case. Is there a better way to handle this? |
||
}) => { | ||
const [isDownloading, setIsDownloading] = useState(false); | ||
|
||
|
@@ -29,7 +31,7 @@ export const ExportPolicyButton: FC<DownloadPolicyButtonProps> = ({ | |
const file = new Blob([policy], { | ||
type: "application/json", | ||
}); | ||
saveAs(file, `${organization.name}_${type}-policy.json`); | ||
download(file, `${organization.name}_${type}-policy.json`); | ||
} catch (e) { | ||
console.error(e); | ||
displayError("Failed to export policy json"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.