Skip to content

Commit 59f4b87

Browse files
committed
lint fix
1 parent ab9ffff commit 59f4b87

2 files changed

Lines changed: 57 additions & 7 deletions

File tree

src/views/schedule-actions/__tests__/schedule-actions.test.tsx

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,18 @@ jest.mock('../schedule-actions-modal/schedule-actions-modal', () =>
3030

3131
jest.mock('../schedule-actions-menu/schedule-actions-menu', () =>
3232
jest.fn((props) => {
33+
const areAllActionsDisabled = props.actionsEnabledConfig
34+
? Object.entries(props.actionsEnabledConfig).every(
35+
([_, value]) => value !== 'ENABLED'
36+
)
37+
: true;
38+
3339
return (
3440
<div
3541
onClick={() => props.onActionSelect(mockScheduleActionsConfig[0])}
3642
data-testid="actions-menu"
3743
>
38-
Actions Menu
44+
Actions Menu{areAllActionsDisabled ? ' (disabled)' : ''}
3945
</div>
4046
);
4147
})
@@ -74,6 +80,17 @@ describe(ScheduleActions.name, () => {
7480
expect(await screen.findByTestId('actions-menu')).toBeInTheDocument();
7581
});
7682

83+
it('renders the button with disabled configs if config fetching fails', async () => {
84+
const { user } = setup({ isConfigError: true });
85+
86+
const actionsButton = await screen.findByRole('button');
87+
await user.click(actionsButton);
88+
89+
const actionsMenu = await screen.findByTestId('actions-menu');
90+
expect(actionsMenu).toBeInTheDocument();
91+
expect(actionsMenu).toHaveTextContent('Actions Menu (disabled)');
92+
});
93+
7794
it('shows the modal when a menu option is clicked', async () => {
7895
const { user } = setup({});
7996

@@ -93,7 +110,13 @@ describe(ScheduleActions.name, () => {
93110
});
94111
});
95112

96-
function setup({ isError = false }: { isError?: boolean }) {
113+
function setup({
114+
isError = false,
115+
isConfigError = false,
116+
}: {
117+
isError?: boolean;
118+
isConfigError?: boolean;
119+
}) {
97120
const user = userEvent.setup();
98121

99122
render(<ScheduleActions />, {
@@ -113,6 +136,27 @@ function setup({ isError = false }: { isError?: boolean }) {
113136
return HttpResponse.json(mockDescribeScheduleResponse);
114137
},
115138
},
139+
{
140+
path: '/api/config',
141+
httpMethod: 'GET',
142+
mockOnce: false,
143+
httpResolver: () => {
144+
if (isConfigError) {
145+
return HttpResponse.json(
146+
{ message: 'Failed to fetch config' },
147+
{ status: 500 }
148+
);
149+
}
150+
151+
return HttpResponse.json(
152+
{
153+
pause: 'ENABLED',
154+
resume: 'ENABLED',
155+
},
156+
{ status: 200 }
157+
);
158+
},
159+
},
116160
],
117161
});
118162

src/views/schedule-actions/schedule-actions.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@ import { useParams } from 'next/navigation';
1010
import { MdArrowDropDown } from 'react-icons/md';
1111

1212
import Button from '@/components/button/button';
13+
import useConfigValue from '@/hooks/use-config-value/use-config-value';
1314
import { type SchedulePageLayoutParams } from '@/views/schedule-page/schedule-page.types';
1415
import useDescribeSchedule from '@/views/shared/hooks/use-describe-schedule/use-describe-schedule';
1516

17+
import { type SelectableScheduleAction } from './config/schedule-actions.config';
1618
import ScheduleActionsMenu from './schedule-actions-menu/schedule-actions-menu';
1719
import ScheduleActionsModal from './schedule-actions-modal/schedule-actions-modal';
1820
import { overrides } from './schedule-actions.styles';
19-
import { type SelectableScheduleAction } from './config/schedule-actions.config';
20-
import {
21-
type ErasedScheduleAction,
22-
} from './schedule-actions.types';
21+
import { type ErasedScheduleAction } from './schedule-actions.types';
2322

2423
export default function ScheduleActions() {
2524
const params = useParams<SchedulePageLayoutParams>();
@@ -33,6 +32,12 @@ export default function ScheduleActions() {
3332
...scheduleDetailsParams,
3433
});
3534

35+
const { data: actionsEnabledConfig, isLoading: isActionsEnabledLoading } =
36+
useConfigValue('SCHEDULE_ACTIONS_ENABLED', {
37+
domain: params.domain,
38+
cluster: params.cluster,
39+
});
40+
3641
const [selectedAction, setSelectedAction] = useState<
3742
SelectableScheduleAction | undefined
3843
>(undefined);
@@ -49,6 +54,7 @@ export default function ScheduleActions() {
4954
content={({ close }) => (
5055
<ScheduleActionsMenu
5156
schedule={schedule}
57+
actionsEnabledConfig={actionsEnabledConfig}
5258
onActionSelect={(action) => {
5359
setSelectedAction(action);
5460
close();
@@ -63,7 +69,7 @@ export default function ScheduleActions() {
6369
kind="secondary"
6470
endEnhancer={<MdArrowDropDown size={20} />}
6571
loadingIndicatorType="skeleton"
66-
isLoading={isScheduleLoading}
72+
isLoading={isScheduleLoading || isActionsEnabledLoading}
6773
>
6874
Schedule Actions
6975
</Button>

0 commit comments

Comments
 (0)