Skip to content

Commit 9d31b23

Browse files
feat(REGISTRY-2839): Account type label on all screens for a logged in user (#843)
2 parents 876edad + 7352d09 commit 9d31b23

3 files changed

Lines changed: 95 additions & 5 deletions

File tree

cypress/e2e/user-journeys/admin/emails.cy.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,30 @@ import { dataCy, getModalByHeader, logout } from "cypress/support/utils/common";
77

88
const dataInviteUser = mockedInvitedUser();
99

10+
const refreshUntilFirstRowMatches = (
11+
predicate: (firstRowText: string) => boolean,
12+
maxAttempts = 5,
13+
attempts = 0
14+
) => {
15+
cy.get(dataCy("emails-list"))
16+
.find("tbody tr")
17+
.should("have.length.greaterThan", 0)
18+
.first()
19+
.then($row => {
20+
if (predicate($row.text())) {
21+
return;
22+
}
23+
24+
if (attempts >= maxAttempts) {
25+
throw new Error("Timed out waiting for first row to match condition");
26+
}
27+
28+
cy.contains("button", "Update").click();
29+
cy.wait(1000);
30+
refreshUntilFirstRowMatches(predicate, maxAttempts, attempts + 1);
31+
});
32+
};
33+
1034
describe("Resend invite", () => {
1135
before(() => {
1236
loginAdmin();
@@ -29,8 +53,7 @@ describe("Resend invite", () => {
2953
});
3054

3155
it("Shows a list of emails", () => {
32-
cy.contains("button", "Update").click();
33-
56+
refreshUntilFirstRowMatches(text => text.includes(dataInviteUser.email));
3457
cy.get(dataCy("emails-list"))
3558
.find("tbody tr")
3659
.should("exist")

src/organisms/NavBar/NavBar.test.tsx

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useStore } from "@/data/store";
1+
import { StoreState, useStore } from "@/data/store";
22
import { mockedJwt } from "@/mocks/data/auth";
33
import { mockedUser } from "@/mocks/data/user";
44
import theme from "@/theme";
@@ -15,6 +15,9 @@ import {
1515
waitFor,
1616
} from "../../utils/testUtils";
1717
import NavBar from "./NavBar";
18+
import { mockedOrganisation } from "@/mocks/data/organisation";
19+
import { mockedCustodian } from "@/mocks/data/custodian";
20+
import { AccountType } from "@/types/accounts";
1821

1922
jest.mock("js-cookie", () => ({
2023
get: jest.fn(),
@@ -117,7 +120,11 @@ describe("NavBar Component", () => {
117120
selector({
118121
getUser: () => mockedUser(),
119122
setUser: jest.fn(),
120-
})
123+
config: {
124+
organisation: mockedOrganisation,
125+
custodian: mockedCustodian,
126+
},
127+
} as unknown as StoreState)
121128
);
122129

123130
render(<NavBar loggedIn />);
@@ -127,6 +134,40 @@ describe("NavBar Component", () => {
127134
expect(handleLogout).toHaveBeenCalled();
128135
});
129136

137+
it("displays 'Organisation' chip when the user belongs to an organisation", () => {
138+
mockUseStore.mockImplementation(selector =>
139+
selector({
140+
getUser: () => mockedUser(),
141+
setUser: jest.fn(),
142+
config: {
143+
organisation: mockedOrganisation,
144+
custodian: undefined,
145+
},
146+
} as unknown as StoreState)
147+
);
148+
149+
render(<NavBar loggedIn />);
150+
151+
expect(screen.getByText(AccountType.ORGANISATION)).toBeInTheDocument();
152+
});
153+
154+
it("displays 'Custodian' chip when the user belongs to an custodian", () => {
155+
mockUseStore.mockImplementation(selector =>
156+
selector({
157+
getUser: () => mockedUser(),
158+
setUser: jest.fn(),
159+
config: {
160+
organisation: undefined,
161+
custodian: mockedCustodian,
162+
},
163+
} as unknown as StoreState)
164+
);
165+
166+
render(<NavBar loggedIn />);
167+
168+
expect(screen.getByText(AccountType.CUSTODIAN)).toBeInTheDocument();
169+
});
170+
130171
it("displays 'My Account' and 'Sign Out' if the user is authenticated", () => {
131172
mockGetMe.mockResolvedValueOnce({
132173
status: 200,
@@ -137,7 +178,11 @@ describe("NavBar Component", () => {
137178
selector({
138179
getUser: () => mockedUser(),
139180
setUser: jest.fn(),
140-
})
181+
config: {
182+
organisation: undefined,
183+
custodian: undefined,
184+
},
185+
} as unknown as StoreState)
141186
);
142187

143188
(get as jest.Mock).mockReturnValue(mockedJwt);

src/organisms/NavBar/NavBar.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import MenuIcon from "@mui/icons-material/Menu";
99
import {
1010
Box,
1111
Button,
12+
Chip,
1213
IconButton,
1314
MenuItem,
1415
MenuList,
@@ -27,6 +28,7 @@ import { handleLogin, handleLogout } from "../../utils/keycloak";
2728
import NotificationsMenu from "../NotificationsMenu";
2829
import SupportMenu from "../SupportMenu/SupportMenu";
2930
import { StyledContainer, StyledHeader } from "./NavBar.styles";
31+
import { AccountType } from "@/types/accounts";
3032

3133
const NAMESPACE_TRANSLATIONS_NAVBAR = "NavBar";
3234

@@ -105,6 +107,8 @@ export default function NavBar({ loggedIn }: NavBarProps) {
105107
store.getUser(),
106108
store.setUser,
107109
]);
110+
const storedOrganisation = useStore(state => state.config.organisation);
111+
const storedCustodian = useStore(state => state.config.custodian);
108112

109113
const theme = useTheme();
110114
const [isDrawerOpen, setIsDrawerOpen] = useState(false);
@@ -214,6 +218,24 @@ export default function NavBar({ loggedIn }: NavBarProps) {
214218
sx={{ mr: 4 }}
215219
/>
216220
</Link>
221+
{loggedIn && (
222+
<Chip
223+
label={
224+
storedOrganisation
225+
? AccountType.ORGANISATION
226+
: storedCustodian
227+
? AccountType.CUSTODIAN
228+
: AccountType.USER
229+
}
230+
sx={{
231+
textTransform: "uppercase",
232+
backgroundColor: theme.palette[`neutral-500`].main,
233+
color: theme.palette.white,
234+
}}
235+
size="medium"
236+
/>
237+
)}
238+
217239
{renderButtons(left_buttons)}
218240
</Box>
219241
<Box sx={{ display: "flex", alignItems: "center", gap: 2 }}>

0 commit comments

Comments
 (0)