Skip to content

Commit fa89016

Browse files
authored
Merge branch 'develop' into MAT-9993
2 parents 08e483d + 8dd770c commit fa89016

2 files changed

Lines changed: 58 additions & 8 deletions

File tree

src/components/measureActions/dialogs/shareDialog/ShareDialog.test.tsx

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,10 +1564,50 @@ describe("UnshareFromMe Confirmation Dialog component", () => {
15641564
/>
15651565
);
15661566

1567-
expect(screen.getByTestId("share-confirmation-dialog")).toBeInTheDocument();
1567+
expect(
1568+
await screen.findByTestId("share-confirmation-dialog")
1569+
).toBeInTheDocument();
15681570
expect(screen.queryByTestId("share-dialog")).toBeNull();
15691571
});
15701572

1573+
it("should unshare the passed unshareFromUser (not the logged-in user) and show the measure name", async () => {
1574+
const mockOnSave = jest.fn();
1575+
mockMeasureServiceApi.unshareMeasures = mockUnshareMeasures;
1576+
render(
1577+
<ShareDialog
1578+
measures={[mockMeasure1, mockMeasure2]}
1579+
open={true}
1580+
option="UnshareFromMe"
1581+
onClose={jest.fn()}
1582+
onSave={mockOnSave}
1583+
unshareFromUser="userId1"
1584+
/>
1585+
);
1586+
1587+
const dialog = await screen.findByTestId("share-confirmation-dialog");
1588+
expect(dialog).toHaveTextContent(mockMeasure1.measureName);
1589+
expect(dialog).toHaveTextContent(mockMeasure2.measureName);
1590+
1591+
// The target user is the passed profile user, not the logged-in "test user".
1592+
expect(dialog).toHaveTextContent("userId1");
1593+
expect(dialog).not.toHaveTextContent("test user");
1594+
1595+
await userEvent.click(
1596+
await screen.findByTestId("share-confirmation-dialog-accept-button")
1597+
);
1598+
1599+
await waitFor(() => {
1600+
expect(mockUnshareMeasures).toHaveBeenCalledWith(expect.any(Map));
1601+
});
1602+
const requestMap = mockUnshareMeasures.mock.calls[0][0] as Map<
1603+
string,
1604+
string[]
1605+
>;
1606+
1607+
expect(requestMap.get(mockMeasure1.id)).toEqual(["userId1"]);
1608+
expect(requestMap.get(mockMeasure2.id)).toEqual(["userId1"]);
1609+
});
1610+
15711611
it("should close Share dialog and call onClose when option is 'Share With'", async () => {
15721612
const onCloseMock = jest.fn();
15731613

@@ -1627,7 +1667,9 @@ describe("UnshareFromMe Confirmation Dialog component", () => {
16271667
/>
16281668
);
16291669

1630-
expect(screen.getByTestId("share-confirmation-dialog")).toBeInTheDocument();
1670+
expect(
1671+
await screen.findByTestId("share-confirmation-dialog")
1672+
).toBeInTheDocument();
16311673
expect(screen.queryByTestId("share-dialog")).toBeNull();
16321674

16331675
const cancelButton = screen.getByTestId(

src/components/measureActions/dialogs/shareDialog/ShareDialog.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ interface ShareDialogProps {
5555
onClose: Function;
5656
onSave: Function;
5757
isAdmin?: boolean;
58+
// HARP id to unshare from on the "UnshareFromMe" path. Defaults to the
59+
// logged-in user in the Measures workspace while the Admin User Profile passes the
60+
// profile user being viewed.
61+
unshareFromUser?: string;
5862
}
5963

6064
interface SharedMeasure {
@@ -116,9 +120,13 @@ const ShareDialog = ({
116120
onClose,
117121
onSave,
118122
isAdmin,
123+
unshareFromUser,
119124
}: ShareDialogProps) => {
120125
const { getUserName } = useOktaTokens();
121126
const userName = getUserName();
127+
// User whose access is removed on the "UnshareFromMe" path: the profile user
128+
// in the Admin User Profile or defaults to the logged-in user if no unshareFromUser provided.
129+
const unshareTargetUser = unshareFromUser ?? userName;
122130

123131
const showShareDialog = option === "Share With" || option === "Unshare";
124132

@@ -626,19 +634,19 @@ const ShareDialog = ({
626634
}, [rowSelection]);
627635

628636
useEffect(() => {
629-
// Only trigger when dialog is open and the option is UnshareFromMe
630-
if (option === "UnshareFromMe" && open) {
631-
// Prepare the unshare request
637+
// Only trigger once the dialog is open, the option is UnshareFromMe, and the
638+
// shared measures have loaded.
639+
if (option === "UnshareFromMe" && open && sharedMeasures.length) {
632640
const directUnshareRequest = new Map<string, string[]>();
633-
measures.forEach((measure) => {
634-
directUnshareRequest.set(measure.id, [userName]);
641+
sharedMeasures.forEach((sharedMeasure) => {
642+
directUnshareRequest.set(sharedMeasure.measureId, [unshareTargetUser]);
635643
});
636644
setUnshareMeasuresRequest(directUnshareRequest);
637645

638646
// Open the confirmation dialog
639647
setConfirmationDialogOpen(true);
640648
}
641-
}, [option, open, measures, userName]);
649+
}, [option, open, sharedMeasures, unshareTargetUser]);
642650

643651
// export user list in Excel format for admin users
644652
const handleExportUserList = async (e) => {

0 commit comments

Comments
 (0)