Skip to content

Commit b967004

Browse files
author
Mathieu Anderson
authored
feat(coral): Remove feature flag for User information sections (#2061)
* feat(coral): Remove feature flag for user info * fix(coral): Remove feature flag mocks * fix(coral): Fix test --------- Signed-off-by: Mathieu Anderson <mathieu.anderson@aiven.io>
1 parent 703cd3d commit b967004

7 files changed

Lines changed: 27 additions & 190 deletions

File tree

coral/src/app/layout/header/ProfileDropdown.test.tsx

Lines changed: 4 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { customRender } from "src/services/test-utils/render-with-wrappers";
77
const mockLogoutUser = logoutUser as jest.MockedFunction<typeof logoutUser>;
88
const mockedNavigate = jest.fn();
99
const mockAuthUser = jest.fn();
10-
const mockIsFeatureFlagActive = jest.fn();
1110
const mockToast = jest.fn();
1211
const mockDismiss = jest.fn();
1312

@@ -21,10 +20,6 @@ jest.mock("src/app/context-provider/AuthProvider", () => ({
2120
useAuthContext: () => mockAuthUser(),
2221
}));
2322

24-
jest.mock("src/services/feature-flags/utils", () => ({
25-
isFeatureFlagActive: () => mockIsFeatureFlagActive(),
26-
}));
27-
2823
jest.mock("@aivenio/aquarium", () => ({
2924
...jest.requireActual("@aivenio/aquarium"),
3025
useToastContext: () => [mockToast, mockDismiss],
@@ -34,19 +29,16 @@ const menuItems = [
3429
{
3530
angularPath: "/myProfile",
3631
path: "/user/profile",
37-
behindFeatureFlag: true,
3832
name: "User profile",
3933
},
4034
{
4135
angularPath: "/changePwd",
4236
path: "/user/change-password",
43-
behindFeatureFlag: true,
4437
name: "Change password",
4538
},
4639
{
4740
angularPath: "/tenantInfo",
4841
path: "/user/tenant-info",
49-
behindFeatureFlag: true,
5042
name: "Tenant information",
5143
},
5244
];
@@ -63,7 +55,6 @@ describe("ProfileDropdown", () => {
6355

6456
describe("renders all necessary elements when dropdown is closed", () => {
6557
beforeAll(() => {
66-
mockIsFeatureFlagActive.mockReturnValue(false);
6758
mockAuthUser.mockReturnValue(testUser);
6859
customRender(<ProfileDropdown />, { memoryRouter: true });
6960
});
@@ -89,7 +80,6 @@ describe("ProfileDropdown", () => {
8980

9081
describe("renders all necessary elements when dropdown is open", () => {
9182
beforeAll(async () => {
92-
mockIsFeatureFlagActive.mockReturnValue(false);
9383
mockAuthUser.mockReturnValue(testUser);
9484
customRender(<ProfileDropdown />, { memoryRouter: true });
9585
const button = screen.getByRole("button", { name: "Open profile menu" });
@@ -125,9 +115,8 @@ describe("ProfileDropdown", () => {
125115
});
126116
});
127117

128-
describe("handles user choosing items from the menu when feature-flag for user information is disabled", () => {
118+
describe("handles user choosing items from the menu", () => {
129119
beforeEach(() => {
130-
mockIsFeatureFlagActive.mockReturnValue(false);
131120
mockAuthUser.mockReturnValue(testUser);
132121
Object.defineProperty(window, "location", {
133122
value: {
@@ -145,7 +134,8 @@ describe("ProfileDropdown", () => {
145134

146135
menuItems.forEach((item) => {
147136
const name = item.name;
148-
const path = item.angularPath;
137+
138+
const path = item.path;
149139

150140
it(`navigates to "${path}" when user clicks "${name}"`, async () => {
151141
const button = screen.getByRole("button", {
@@ -156,74 +146,13 @@ describe("ProfileDropdown", () => {
156146
const menuItem = screen.getByRole("menuitem", { name: name });
157147
await user.click(menuItem);
158148

159-
// in tests it will start with http://localhost/ since that is the window.origin
160-
expect(window.location.assign).toHaveBeenCalledWith(
161-
`http://localhost${path}`
162-
);
149+
expect(mockedNavigate).toHaveBeenCalledWith(path);
163150
});
164151
});
165152
});
166153

167-
describe("handles user choosing items from the menu when feature-flag for user information is enabled", () => {
168-
beforeEach(() => {
169-
mockIsFeatureFlagActive.mockReturnValue(true);
170-
mockAuthUser.mockReturnValue(testUser);
171-
Object.defineProperty(window, "location", {
172-
value: {
173-
assign: jest.fn(),
174-
},
175-
writable: true,
176-
});
177-
customRender(<ProfileDropdown />, { memoryRouter: true });
178-
});
179-
180-
afterEach(() => {
181-
jest.restoreAllMocks();
182-
cleanup();
183-
});
184-
185-
menuItems.forEach((item) => {
186-
const name = item.name;
187-
188-
if (item.behindFeatureFlag) {
189-
const path = item.path;
190-
191-
it(`navigates to "${path}" when user clicks "${name}"`, async () => {
192-
const button = screen.getByRole("button", {
193-
name: "Open profile menu",
194-
});
195-
await user.click(button);
196-
197-
const menuItem = screen.getByRole("menuitem", { name: name });
198-
await user.click(menuItem);
199-
200-
expect(window.location.assign).not.toHaveBeenCalled();
201-
expect(mockedNavigate).toHaveBeenCalledWith("/user/profile");
202-
});
203-
} else {
204-
const path = item.angularPath;
205-
206-
it(`navigates to "${path}" when user clicks "${name}"`, async () => {
207-
const button = screen.getByRole("button", {
208-
name: "Open profile menu",
209-
});
210-
await user.click(button);
211-
212-
const menuItem = screen.getByRole("menuitem", { name: name });
213-
await user.click(menuItem);
214-
215-
// in tests it will start with http://localhost/ since that is the window.origin
216-
expect(window.location.assign).toHaveBeenCalledWith(
217-
`http://localhost${path}`
218-
);
219-
});
220-
}
221-
});
222-
});
223-
224154
describe("handles user sucessfully login out", () => {
225155
beforeEach(() => {
226-
mockIsFeatureFlagActive.mockReturnValue(false);
227156
mockAuthUser.mockReturnValue(testUser);
228157
// calling '/logout` successfully will resolve in us
229158
// receiving a 401 error so this is mocking the real behavior
@@ -286,7 +215,6 @@ describe("ProfileDropdown", () => {
286215
});
287216

288217
describe("handles error in logout process", () => {
289-
mockIsFeatureFlagActive(false);
290218
mockAuthUser.mockReturnValue(testUser);
291219
const testError = {
292220
status: 500,

coral/src/app/layout/header/ProfileDropdown.tsx

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,48 @@
11
import {
22
Box,
33
DropdownMenu,
4-
Typography,
54
Icon,
5+
Typography,
66
useToastContext,
77
Button,
88
} from "@aivenio/aquarium";
9-
import user from "@aivenio/aquarium/dist/src/icons/user";
109
import logOut from "@aivenio/aquarium/dist/src/icons/logOut";
10+
import user from "@aivenio/aquarium/dist/src/icons/user";
11+
import { useNavigate } from "react-router-dom";
12+
import { useAuthContext } from "src/app/context-provider/AuthProvider";
1113
import classes from "src/app/layout/header/ProfileDropdown.module.css";
1214
import { logoutUser } from "src/domain/auth-user";
13-
import { useAuthContext } from "src/app/context-provider/AuthProvider";
14-
import { useNavigate } from "react-router-dom";
15-
import useFeatureFlag from "src/services/feature-flags/hook/useFeatureFlag";
16-
import { FeatureFlag } from "src/services/feature-flags/types";
1715

1816
type MenuItem = {
1917
angularPath: string;
2018
path: string;
2119
name: string;
22-
behindFeatureFlag: boolean;
2320
};
2421

2522
const menuItems: MenuItem[] = [
2623
{
2724
angularPath: "/myProfile",
2825
path: "/user/profile",
29-
behindFeatureFlag: true,
3026
name: "User profile",
3127
},
3228
{
3329
angularPath: "/changePwd",
3430
path: "/user/change-password",
35-
behindFeatureFlag: true,
3631
name: "Change password",
3732
},
3833
{
3934
angularPath: "/tenantInfo",
4035
path: "/user/tenant-info",
41-
behindFeatureFlag: true,
4236
name: "Tenant information",
4337
},
4438
];
4539

4640
const LOGOUT_KEY = "logout";
4741
function ProfileDropdown() {
48-
const userInformationFeatureFlagEnabled = useFeatureFlag(
49-
FeatureFlag.FEATURE_FLAG_USER_INFORMATION
50-
);
51-
5242
const navigate = useNavigate();
5343
const authUser = useAuthContext();
5444
const [toast, dismiss] = useToastContext();
5545

56-
function navigateToAngular(path: string) {
57-
window.location.assign(`${window.origin}${path}`);
58-
}
59-
6046
function onDropdownClick(actionKey: React.Key) {
6147
if (actionKey === LOGOUT_KEY) {
6248
toast({
@@ -90,12 +76,7 @@ function ProfileDropdown() {
9076
return;
9177
}
9278

93-
if (selectedItem.behindFeatureFlag && userInformationFeatureFlagEnabled) {
94-
navigate(selectedItem.path);
95-
return;
96-
}
97-
98-
navigateToAngular(selectedItem.angularPath);
79+
navigate(selectedItem.path);
9980
}
10081
}
10182

coral/src/app/layout/main-navigation/MainNavigation.test.tsx

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ const submenuItems = [
7272
links: [
7373
{
7474
name: "User profile",
75-
linkTo: isFeatureFlagActiveMock() ? `/user/profile` : `/myProfile`,
75+
linkTo: "/user/profile",
7676
},
7777
{
7878
name: "Change password",
79-
linkTo: "/changePwd",
79+
linkTo: "/user/change-password",
8080
},
8181
{
8282
name: "Tenant information",
83-
linkTo: "/tenantInfo",
83+
linkTo: "/user/tenant-info",
8484
},
8585
],
8686
},
@@ -176,53 +176,6 @@ describe("MainNavigation.tsx", () => {
176176
});
177177
});
178178

179-
describe("renders links to profile behind feature flag", () => {
180-
afterEach(() => {
181-
cleanup();
182-
jest.resetAllMocks();
183-
});
184-
185-
it("renders a link to the old UI when feature flag is false", async () => {
186-
isFeatureFlagActiveMock.mockReturnValue(false);
187-
customRender(<MainNavigation />, {
188-
memoryRouter: true,
189-
queryClient: true,
190-
});
191-
192-
const button = screen.getByRole("button", {
193-
name: new RegExp("User information", "i"),
194-
});
195-
await userEvent.click(button);
196-
const list = screen.getByRole("list", {
197-
name: "User information submenu",
198-
});
199-
200-
const link = within(list).getByRole("link", { name: "User profile" });
201-
expect(link).toBeVisible();
202-
expect(link).toHaveAttribute("href", "/myProfile");
203-
});
204-
205-
it("renders a link to the profile page when feature flag is true", async () => {
206-
isFeatureFlagActiveMock.mockReturnValue(true);
207-
customRender(<MainNavigation />, {
208-
memoryRouter: true,
209-
queryClient: true,
210-
});
211-
212-
const button = screen.getByRole("button", {
213-
name: new RegExp("User information", "i"),
214-
});
215-
await userEvent.click(button);
216-
const list = screen.getByRole("list", {
217-
name: "User information submenu",
218-
});
219-
220-
const link = within(list).getByRole("link", { name: "User profile" });
221-
expect(link).toBeVisible();
222-
expect(link).toHaveAttribute("href", "/user/profile");
223-
});
224-
});
225-
226179
describe("renders links to cluster behind feature flag", () => {
227180
afterEach(() => {
228181
cleanup();

coral/src/app/layout/main-navigation/MainNavigation.tsx

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ import { FeatureFlag } from "src/services/feature-flags/types";
1818

1919
function MainNavigation() {
2020
const { pathname } = useLocation();
21-
const userInformationFeatureFlagEnabled = useFeatureFlag(
22-
FeatureFlag.FEATURE_FLAG_USER_INFORMATION
23-
);
2421

2522
const clusterViewFeatureFlagIsEnabled = useFeatureFlag(
2623
FeatureFlag.FEATURE_FLAG_VIEW_CLUSTER
@@ -137,29 +134,17 @@ function MainNavigation() {
137134
defaultExpanded={pathname.startsWith(Routes.USER_INFORMATION)}
138135
>
139136
<MainNavigationLink
140-
to={
141-
userInformationFeatureFlagEnabled
142-
? Routes.USER_PROFILE
143-
: "/myProfile"
144-
}
137+
to={Routes.USER_PROFILE}
145138
linkText={"User profile"}
146139
active={pathname.startsWith(Routes.USER_PROFILE)}
147140
/>
148141
<MainNavigationLink
149-
to={
150-
userInformationFeatureFlagEnabled
151-
? Routes.USER_CHANGE_PASSWORD
152-
: "/changePwd"
153-
}
142+
to={Routes.USER_CHANGE_PASSWORD}
154143
linkText={"Change password"}
155144
active={pathname.startsWith(Routes.USER_CHANGE_PASSWORD)}
156145
/>
157146
<MainNavigationLink
158-
to={
159-
userInformationFeatureFlagEnabled
160-
? Routes.USER_TENANT_INFO
161-
: "/tenantInfo"
162-
}
147+
to={Routes.USER_TENANT_INFO}
163148
linkText={"Tenant information"}
164149
active={pathname.startsWith(Routes.USER_TENANT_INFO)}
165150
/>

0 commit comments

Comments
 (0)