[7.12] fix bug and a test to check that users cannot navigate if a step is invalid (#95939) (#96304)

* fix bug and a test to check that users cannot navigate if a step is invalid (#95939)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
# Conflicts:
#	x-pack/plugins/snapshot_restore/__jest__/client_integration/helpers/restore_snapshot.helpers.ts
#	x-pack/plugins/snapshot_restore/__jest__/client_integration/restore_snapshot.test.ts

* added missing next button

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Jean-Louis Leysens 2021-04-07 13:47:12 +02:00 committed by GitHub
parent a78c6d2b3b
commit 11e86ad6df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 88 additions and 4 deletions

View file

@ -5,6 +5,7 @@
* 2.0.
*/
import { act } from 'react-dom/test-utils';
import { registerTestBed, TestBed, TestBedConfig } from '@kbn/test/jest';
import { RestoreSnapshot } from '../../../public/application/sections/restore_snapshot';
import { WithAppDependencies } from './setup_environment';
@ -23,11 +24,57 @@ const initTestBed = registerTestBed<RestoreSnapshotFormTestSubject>(
);
const setupActions = (testBed: TestBed<RestoreSnapshotFormTestSubject>) => {
const { find } = testBed;
const { find, component, form, exists } = testBed;
return {
findDataStreamCallout() {
return find('dataStreamWarningCallOut');
},
canGoToADifferentStep() {
const canGoNext = find('restoreSnapshotsForm.nextButton').props().disabled !== true;
const canGoPrevious = exists('restoreSnapshotsForm.backButton')
? find('restoreSnapshotsForm.nextButton').props().disabled !== true
: true;
return canGoNext && canGoPrevious;
},
toggleModifyIndexSettings() {
act(() => {
form.toggleEuiSwitch('modifyIndexSettingsSwitch');
});
component.update();
},
toggleGlobalState() {
act(() => {
form.toggleEuiSwitch('includeGlobalStateSwitch');
});
component.update();
},
toggleIncludeAliases() {
act(() => {
form.toggleEuiSwitch('includeAliasesSwitch');
});
component.update();
},
goToStep(step: number) {
while (--step > 0) {
find('nextButton').simulate('click');
}
component.update();
},
async clickRestore() {
await act(async () => {
find('restoreButton').simulate('click');
});
component.update();
},
};
};
@ -48,4 +95,12 @@ export const setup = async (): Promise<RestoreSnapshotTestBed> => {
export type RestoreSnapshotFormTestSubject =
| 'snapshotRestoreStepLogistics'
| 'dataStreamWarningCallOut';
| 'includeGlobalStateSwitch'
| 'includeAliasesSwitch'
| 'nextButton'
| 'restoreButton'
| 'systemIndicesInfoCallOut'
| 'dataStreamWarningCallOut'
| 'restoreSnapshotsForm.backButton'
| 'restoreSnapshotsForm.nextButton'
| 'modifyIndexSettingsSwitch';

View file

@ -5,6 +5,7 @@
* 2.0.
*/
import { act } from 'react-dom/test-utils';
import { nextTick, pageHelpers, setupEnvironment } from './helpers';
import { RestoreSnapshotTestBed } from './helpers/restore_snapshot.helpers';
import * as fixtures from '../../test/fixtures';
@ -20,6 +21,27 @@ describe('<RestoreSnapshot />', () => {
afterAll(() => {
server.restore();
});
describe('wizard navigation', () => {
beforeEach(async () => {
httpRequestsMockHelpers.setGetSnapshotResponse(fixtures.getSnapshot());
await act(async () => {
testBed = await setup();
});
testBed.component.update();
});
it('does not allow navigation when the step is invalid', async () => {
const { actions } = testBed;
actions.goToStep(2);
expect(actions.canGoToADifferentStep()).toBe(true);
actions.toggleModifyIndexSettings();
expect(actions.canGoToADifferentStep()).toBe(false);
});
});
describe('with data streams', () => {
beforeEach(async () => {
httpRequestsMockHelpers.setGetSnapshotResponse(fixtures.getSnapshot());

View file

@ -104,7 +104,7 @@ export const RestoreSnapshotForm: React.FunctionComponent<Props> = ({
updateCurrentStep={updateCurrentStep}
/>
<EuiSpacer size="l" />
<EuiForm>
<EuiForm data-test-subj="restoreSnapshotsForm">
<CurrentStepForm
snapshotDetails={snapshotDetails}
restoreSettings={restoreSettings}
@ -124,7 +124,12 @@ export const RestoreSnapshotForm: React.FunctionComponent<Props> = ({
<EuiFlexGroup>
{currentStep > 1 ? (
<EuiFlexItem grow={false}>
<EuiButtonEmpty iconType="arrowLeft" onClick={() => onBack()}>
<EuiButtonEmpty
iconType="arrowLeft"
onClick={() => onBack()}
disabled={!validation.isValid}
data-test-subj="backButton"
>
<FormattedMessage
id="xpack.snapshotRestore.restoreForm.backButtonLabel"
defaultMessage="Back"
@ -139,6 +144,7 @@ export const RestoreSnapshotForm: React.FunctionComponent<Props> = ({
iconType="arrowRight"
onClick={() => onNext()}
disabled={!validation.isValid}
data-test-subj="nextButton"
>
<FormattedMessage
id="xpack.snapshotRestore.restoreForm.nextButtonLabel"

View file

@ -146,6 +146,7 @@ export const RestoreSnapshotStepSettings: React.FunctionComponent<StepProps> = (
<EuiFormRow hasEmptyLabelSpace fullWidth>
<Fragment>
<EuiSwitch
data-test-subj="modifyIndexSettingsSwitch"
label={
<FormattedMessage
id="xpack.snapshotRestore.restoreForm.stepSettings.indexSettingsLabel"