Skip to content

Commit 92c3d3b

Browse files
committed
Merge branch 'improvement/MK8S-176-fix-broken-link-in-volumes' into tmp/octopus/w/133.0/improvement/MK8S-176-fix-broken-link-in-volumes
2 parents 5eb0203 + 47bbab8 commit 92c3d3b

File tree

2 files changed

+97
-16
lines changed

2 files changed

+97
-16
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import { CoreUiThemeProvider } from '@scality/core-ui/dist/next';
2+
import { coreUIAvailableThemes } from '@scality/core-ui/dist/style/theme';
3+
import { act, render, screen, waitFor } from '@testing-library/react';
4+
import userEvent from '@testing-library/user-event';
5+
import type { PropsWithChildren } from 'react';
6+
import { QueryClient } from 'react-query';
7+
import { MemoryRouter, Route, Routes, useLocation } from 'react-router-dom';
8+
import { STATUS_CRITICAL, STATUS_WARNING } from '../constants';
9+
import { QueryClientProvider } from '../QueryClientProvider';
10+
import ActiveAlertsCounter from './ActiveAlertsCounter';
11+
12+
const AlertsPage = () => {
13+
const location = useLocation();
14+
return (
15+
<div data-testid="alerts-page">
16+
Alerts page
17+
<span data-testid="alerts-search">{location.search}</span>
18+
</div>
19+
);
20+
};
21+
22+
const defaultProps = {
23+
criticalCounter: 3,
24+
warningCounter: 5,
25+
};
26+
27+
const initialPath = '/nodes/node1/overview';
28+
29+
const wrapper = ({ children }: PropsWithChildren) => (
30+
<QueryClientProvider client={new QueryClient()}>
31+
<CoreUiThemeProvider theme={coreUIAvailableThemes.darkRebrand}>
32+
<MemoryRouter initialEntries={[initialPath]}>{children}</MemoryRouter>
33+
</CoreUiThemeProvider>
34+
</QueryClientProvider>
35+
);
36+
37+
const renderWithRoutes = () =>
38+
render(
39+
<Routes>
40+
<Route path="/nodes/:nodeName/overview" element={<ActiveAlertsCounter {...defaultProps} />} />
41+
<Route path="/nodes/:nodeName/alerts" element={<AlertsPage />} />
42+
<Route path="/alerts" element={<AlertsPage />} />
43+
</Routes>,
44+
{ wrapper },
45+
);
46+
47+
describe('ActiveAlertsCounter', () => {
48+
it('displays critical and warning counts', () => {
49+
renderWithRoutes();
50+
51+
expect(screen.getByText('Critical')).toBeInTheDocument();
52+
expect(screen.getByText('Warning')).toBeInTheDocument();
53+
expect(screen.getByText('3')).toBeInTheDocument();
54+
expect(screen.getByText('5')).toBeInTheDocument();
55+
});
56+
57+
it('navigates to alerts page with severity=critical when Critical counter is clicked', async () => {
58+
const { container } = renderWithRoutes();
59+
60+
const criticalCounter = container.querySelector('[data-cy="critical_counter_node"]');
61+
if (!criticalCounter) throw new Error('critical counter not found');
62+
await act(async () => {
63+
await userEvent.click(criticalCounter);
64+
});
65+
66+
await waitFor(() => {
67+
expect(screen.getByTestId('alerts-page')).toBeInTheDocument();
68+
});
69+
expect(screen.getByText('Alerts page')).toBeInTheDocument();
70+
expect(screen.getByTestId('alerts-search')).toHaveTextContent(`?severity=${STATUS_CRITICAL}`);
71+
});
72+
73+
it('navigates to alerts page with severity=warning when Warning counter is clicked', async () => {
74+
const { container } = renderWithRoutes();
75+
76+
const warningCounter = container.querySelector('[data-cy="warning_counter_node"]');
77+
if (!warningCounter) throw new Error('warning counter not found');
78+
await act(async () => {
79+
await userEvent.click(warningCounter);
80+
});
81+
82+
await waitFor(() => {
83+
expect(screen.getByTestId('alerts-page')).toBeInTheDocument();
84+
});
85+
expect(screen.getByText('Alerts page')).toBeInTheDocument();
86+
expect(screen.getByTestId('alerts-search')).toHaveTextContent(`?severity=${STATUS_WARNING}`);
87+
});
88+
});

ui/src/components/ActiveAlertsCounter.tsx

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import React from 'react';
2-
import styled from 'styled-components';
3-
import { useLocation, useResolvedPath } from 'react-router';
41
import { Icon } from '@scality/core-ui/dist/components/icon/Icon.component';
5-
import { padding, fontSize } from '@scality/core-ui/dist/style/theme';
6-
import { STATUS_WARNING, STATUS_CRITICAL } from '../constants';
7-
import { useBasenameRelativeNavigate } from '@scality/module-federation';
2+
import { fontSize, padding } from '@scality/core-ui/dist/style/theme';
3+
import { useLocation, useNavigate, useResolvedPath } from 'react-router';
4+
import styled from 'styled-components';
5+
import { STATUS_CRITICAL, STATUS_WARNING } from '../constants';
6+
87
export const CountersWrapper = styled.div`
98
color: ${(props) => props.theme.textPrimary};
109
display: flex;
@@ -48,7 +47,7 @@ const CounterIcon = ({ name, status }) => {
4847

4948
const ActiveAlertsCounter = (props) => {
5049
const { criticalCounter, warningCounter } = props;
51-
const navigate = useBasenameRelativeNavigate();
50+
const navigate = useNavigate();
5251
const location = useLocation();
5352
let url = useResolvedPath('').pathname;
5453

@@ -60,26 +59,20 @@ const ActiveAlertsCounter = (props) => {
6059
query.set('severity', status);
6160
}
6261

63-
url = url?.replace(/\/overview/, '/alerts');
62+
url = '../alerts';
6463
return `${url}?${query.toString()}`;
6564
};
6665

6766
return (
6867
<CountersWrapper>
69-
<CounterWrapper
70-
onClick={() => navigate(getLink(STATUS_CRITICAL))}
71-
data-cy="critical_counter_node"
72-
>
68+
<CounterWrapper onClick={() => navigate(getLink(STATUS_CRITICAL))} data-cy="critical_counter_node">
7369
<CounterTitle>Critical</CounterTitle>
7470
<CounterValueWrapper>
7571
<CounterIcon name="Times-circle" status={STATUS_CRITICAL} />
7672
<CounterValue>{criticalCounter}</CounterValue>
7773
</CounterValueWrapper>
7874
</CounterWrapper>
79-
<CounterWrapper
80-
onClick={() => navigate(getLink(STATUS_WARNING))}
81-
data-cy="warning_counter_node"
82-
>
75+
<CounterWrapper onClick={() => navigate(getLink(STATUS_WARNING))} data-cy="warning_counter_node">
8376
<CounterTitle>Warning</CounterTitle>
8477
<CounterValueWrapper>
8578
<CounterIcon name="Exclamation-circle" status={STATUS_WARNING} />

0 commit comments

Comments
 (0)