Skip to content

Commit 9538f69

Browse files
committed
merge: Merge branch 'ESAS/disable_scenario_run_PROD-13346'
2 parents 692c82b + 9adca64 commit 9538f69

File tree

7 files changed

+140
-17
lines changed

7 files changed

+140
-17
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright (c) Cosmo Tech.
2+
// Licensed under the MIT license.
3+
import { DatasetManager, Login, ScenarioParameters, Scenarios, ScenarioSelector } from '../../commons/actions';
4+
import { stub } from '../../commons/services/stubbing';
5+
import {
6+
WORKSPACE,
7+
DATASETS_TO_REFRESH,
8+
ORGANIZATION_WITH_DEFAULT_ROLE_USER,
9+
} from '../../fixtures/stubbing/DatasetManager';
10+
import { SCENARIOS_WITH_DATASET_ERROR } from '../../fixtures/stubbing/DisableLaunchButton/scenarios';
11+
12+
describe('DisableLaunchButton', () => {
13+
stub.start();
14+
stub.setOrganizations([ORGANIZATION_WITH_DEFAULT_ROLE_USER]);
15+
stub.setWorkspaces([WORKSPACE]);
16+
stub.setDatasets([...DATASETS_TO_REFRESH]);
17+
stub.setScenarios(SCENARIOS_WITH_DATASET_ERROR);
18+
19+
const scenarioWithBrokenDataset = SCENARIOS_WITH_DATASET_ERROR[1];
20+
const scenarioReadyToLaunch = SCENARIOS_WITH_DATASET_ERROR[2];
21+
const scenarioWithoutDataset = SCENARIOS_WITH_DATASET_ERROR[3];
22+
23+
const refreshSuccessOptions = {
24+
expectedPollsCount: 2,
25+
finalIngestionStatus: 'SUCCESS',
26+
};
27+
28+
const refreshFailedOptions = {
29+
expectedPollsCount: 2,
30+
finalIngestionStatus: 'ERROR',
31+
};
32+
33+
beforeEach(() => Login.login({ url: '/W-stbbdbrwryWithDM', workspaceId: 'W-stbbdbrwryWithDM' }));
34+
after(stub.stop);
35+
it('can disable and enable Launch button when dataset status changes', () => {
36+
ScenarioParameters.getLaunchButton().should('be.disabled');
37+
ScenarioSelector.selectScenario(scenarioWithBrokenDataset.name, scenarioWithBrokenDataset.id);
38+
ScenarioParameters.getLaunchButton().should('not.be.disabled');
39+
ScenarioSelector.selectScenario(scenarioReadyToLaunch.name, scenarioReadyToLaunch.id);
40+
ScenarioParameters.getLaunchButton().should('not.be.disabled');
41+
ScenarioSelector.selectScenario(scenarioWithoutDataset.name, scenarioWithoutDataset.id);
42+
ScenarioParameters.getLaunchButton().should('not.be.disabled');
43+
DatasetManager.ignoreDatasetTwingraphQueries();
44+
DatasetManager.switchToDatasetManagerView();
45+
DatasetManager.selectDatasetById(DATASETS_TO_REFRESH[1].id);
46+
DatasetManager.refreshDataset(DATASETS_TO_REFRESH[1].id, refreshFailedOptions);
47+
DatasetManager.getDatasetOverviewPlaceholderTitle().contains('An error', { timeout: 30000 });
48+
Scenarios.switchToScenarioView();
49+
ScenarioSelector.selectScenario(scenarioWithBrokenDataset.name, scenarioWithBrokenDataset.id);
50+
ScenarioParameters.getLaunchButton().should('be.disabled');
51+
DatasetManager.switchToDatasetManagerView();
52+
DatasetManager.selectDatasetById(DATASETS_TO_REFRESH[1].id);
53+
DatasetManager.refreshDataset(DATASETS_TO_REFRESH[1].id, refreshSuccessOptions);
54+
DatasetManager.getRefreshDatasetSpinner(DATASETS_TO_REFRESH[1].id, 30000).should('not.exist');
55+
Scenarios.switchToScenarioView();
56+
ScenarioParameters.getLaunchButton().should('not.be.disabled');
57+
});
58+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) Cosmo Tech.
2+
// Licensed under the MIT license.
3+
import { SCENARIO_EXAMPLE } from '../default';
4+
5+
export const SCENARIOS_WITH_DATASET_ERROR = [
6+
{
7+
...SCENARIO_EXAMPLE,
8+
name: 'Test Cypress - 1 - dataset not found',
9+
id: 's-stubbedscnr02',
10+
datasetList: ['D-stbdatasetnfd'],
11+
},
12+
{
13+
...SCENARIO_EXAMPLE,
14+
name: 'Test Cypress - 2 - broken dataset',
15+
id: 's-stubbedscnr01',
16+
datasetList: ['D-stbdataset9'],
17+
},
18+
{
19+
...SCENARIO_EXAMPLE,
20+
name: 'Test Cypress - 3',
21+
id: 's-stubbedscnr03',
22+
datasetList: ['D-stbdataset8'],
23+
},
24+
{
25+
...SCENARIO_EXAMPLE,
26+
name: 'Test Cypress - 4 - empty datasetList',
27+
id: 's-stubbedscnr04',
28+
datasetList: [],
29+
},
30+
];

public/locales/en/translation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"discard": "DISCARD",
4242
"edit": "Edit parameters",
4343
"launch": "LAUNCH",
44+
"launchDisabled": "The scenario cannot be run because its dataset isn't found or its data ingestion has failed",
4445
"save": "SAVE",
4546
"update": {
4647
"launch": "SAVE AND LAUNCH"

public/locales/fr/translation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"discard": "ABANDONNER",
4242
"edit": "Éditer les parameters",
4343
"launch": "LANCER",
44+
"launchDisabled": "Le scénario ne peut pas être lancé parce que son dataset n'est pas trouvé ou l'ingestion des données a échoué",
4445
"save": "SAUVEGARDER",
4546
"update": {
4647
"launch": "SAUVEGARDER ET LANCER"

src/components/ScenarioParameters/components/ScenarioActions/ScenarioActions.spec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ jest.mock('@cosmotech/ui', () => ({
2222
PermissionsGate: ({ children }) => {
2323
return <div data-testid="PermissionsGate">{children}</div>;
2424
},
25+
FadingTooltip: ({ children }) => {
26+
return <div data-testid="FadingTooltip">{children}</div>;
27+
},
2528
}));
2629

2730
const mockUseLaunchScenario = jest.fn();

src/components/ScenarioParameters/components/ScenarioActions/components/LaunchButton/LaunchButton.js

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
// Copyright (c) Cosmo Tech.
22
// Licensed under the MIT license.
3-
import React, { useCallback } from 'react';
3+
import React, { useCallback, useMemo } from 'react';
44
import { useFormState } from 'react-hook-form';
55
import { useTranslation } from 'react-i18next';
66
import PlayCircleOutlineIcon from '@mui/icons-material/PlayCircleOutline';
77
import { Button, Grid } from '@mui/material';
8-
import { PermissionsGate } from '@cosmotech/ui';
8+
import { FadingTooltip, PermissionsGate } from '@cosmotech/ui';
99
import { useUpdateParameters } from '../../../../../../hooks/ScenarioParametersHooks';
1010
import { useUserAppAndCurrentScenarioPermissions } from '../../../../../../hooks/SecurityHooks';
11-
import { SCENARIO_RUN_STATE } from '../../../../../../services/config/ApiConstants';
11+
import { INGESTION_STATUS, SCENARIO_RUN_STATE } from '../../../../../../services/config/ApiConstants';
1212
import { ACL_PERMISSIONS } from '../../../../../../services/config/accessControl';
1313
import { useSetApplicationErrorMessage } from '../../../../../../state/hooks/ApplicationHooks';
14+
import { useDatasets } from '../../../../../../state/hooks/DatasetHooks';
1415
import {
16+
useCurrentScenarioDatasetList,
1517
useCurrentScenarioId,
1618
useCurrentScenarioState,
1719
useLaunchScenario,
@@ -29,6 +31,15 @@ export const LaunchButton = () => {
2931
const setApplicationErrorMessage = useSetApplicationErrorMessage();
3032
const launchScenario = useLaunchScenario();
3133
const userAppAndCurrentScenarioPermissions = useUserAppAndCurrentScenarioPermissions();
34+
const currentScenarioDatasetList = useCurrentScenarioDatasetList();
35+
const datasets = useDatasets();
36+
const isCurrentScenarioDatasetUnavailable = useMemo(() => {
37+
if (currentScenarioDatasetList && currentScenarioDatasetList?.length > 0) {
38+
const currentScenarioDataset = datasets?.find((dataset) => dataset.id === currentScenarioDatasetList?.[0]);
39+
return !currentScenarioDataset || currentScenarioDataset?.ingestionStatus === INGESTION_STATUS.ERROR;
40+
}
41+
return false;
42+
}, [currentScenarioDatasetList, datasets]);
3243

3344
const isCurrentScenarioRunning =
3445
currentScenarioState === SCENARIO_RUN_STATE.RUNNING ||
@@ -73,21 +84,32 @@ export const LaunchButton = () => {
7384
necessaryPermissions={[ACL_PERMISSIONS.SCENARIO.LAUNCH]}
7485
>
7586
<Grid item>
76-
<Button
77-
data-cy="launch-scenario-button"
78-
variant="contained"
79-
startIcon={<PlayCircleOutlineIcon />}
80-
onClick={launchCurrentScenario}
81-
disabled={!isValid}
87+
<FadingTooltip
88+
title={
89+
isCurrentScenarioDatasetUnavailable
90+
? t(
91+
'commoncomponents.button.scenario.parameters.launchDisabled',
92+
"The scenario cannot be run because its dataset isn't found or its data ingestion has failed"
93+
)
94+
: ''
95+
}
8296
>
83-
{isDirty ? (
84-
<span data-cy="save-and-launch-label">
85-
{t('commoncomponents.button.scenario.parameters.update.launch', 'SAVE AND LAUNCH')}
86-
</span>
87-
) : (
88-
<span data-cy="launch-label">{t('commoncomponents.button.scenario.parameters.launch', 'LAUNCH')}</span>
89-
)}
90-
</Button>
97+
<Button
98+
data-cy="launch-scenario-button"
99+
variant="contained"
100+
startIcon={<PlayCircleOutlineIcon />}
101+
onClick={launchCurrentScenario}
102+
disabled={!isValid || isCurrentScenarioDatasetUnavailable}
103+
>
104+
{isDirty ? (
105+
<span data-cy="save-and-launch-label">
106+
{t('commoncomponents.button.scenario.parameters.update.launch', 'SAVE AND LAUNCH')}
107+
</span>
108+
) : (
109+
<span data-cy="launch-label">{t('commoncomponents.button.scenario.parameters.launch', 'LAUNCH')}</span>
110+
)}
111+
</Button>
112+
</FadingTooltip>
91113
</Grid>
92114
</PermissionsGate>
93115
) : null;

tests/samples/datasets.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,12 @@ export const DEFAULT_DATASETS_LIST_DATA = [
3535
ingestionStatus: 'SUCCESS',
3636
twincacheStatus: 'FULL',
3737
},
38+
{
39+
...DEFAULT_DATASET,
40+
id: 'D-4jwyQnmv7jx',
41+
name: 'DataSet Sample 001',
42+
main: true,
43+
ingestionStatus: 'SUCCESS',
44+
twincacheStatus: 'FULL',
45+
},
3846
];

0 commit comments

Comments
 (0)