Преглед изворни кода

[FE] Fix URL for Logout button (#3246)

Mgrdich пре 2 година
родитељ
комит
ceb9c5dd85

+ 1 - 1
kafka-ui-react-app/src/components/NavBar/UserInfo/UserInfo.tsx

@@ -26,7 +26,7 @@ const UserInfo = () => {
       }
     >
       <DropdownItem>
-        <S.LogoutLink href="/logout">Log out</S.LogoutLink>
+        <S.LogoutLink href={`${window.basePath}/logout`}>Log out</S.LogoutLink>
       </DropdownItem>
     </Dropdown>
   ) : null;

+ 20 - 0
kafka-ui-react-app/src/components/NavBar/UserInfo/__tests__/UserInfo.spec.tsx

@@ -22,6 +22,10 @@ describe('UserInfo', () => {
 
   it('should render the userInfo during click opens the dropdown', async () => {
     const username = 'someName';
+    Object.defineProperty(window, 'basePath', {
+      value: '',
+      writable: true,
+    });
     (useUserInfo as jest.Mock).mockImplementation(() => ({ username }));
 
     renderComponent();
@@ -33,6 +37,22 @@ describe('UserInfo', () => {
     expect(logout).toHaveAttribute('href', '/logout');
   });
 
+  it('should render correct url during basePath initialization', async () => {
+    const username = 'someName';
+    const baseUrl = '/path';
+    Object.defineProperty(window, 'basePath', {
+      value: baseUrl,
+      writable: true,
+    });
+    (useUserInfo as jest.Mock).mockImplementation(() => ({ username }));
+
+    renderComponent();
+
+    const logout = screen.getByText('Log out');
+    expect(logout).toBeInTheDocument();
+    expect(logout).toHaveAttribute('href', `${baseUrl}/logout`);
+  });
+
   it('should not render anything if the username does not exists', () => {
     (useUserInfo as jest.Mock).mockImplementation(() => ({
       username: undefined,