Skip to content

Commit

Permalink
fix bug and a test to check that users cannot navigate if a step is i…
Browse files Browse the repository at this point in the history
…nvalid
  • Loading branch information
jloleysens committed Mar 31, 2021
1 parent 44a4635 commit 4db039c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,34 @@ const initTestBed = registerTestBed<RestoreSnapshotFormTestSubject>(
);

const setupActions = (testBed: TestBed<RestoreSnapshotFormTestSubject>) => {
const { find, component, form } = testBed;
const { find, component, form, exists } = testBed;
return {
findDataStreamCallout() {
return find('dataStreamWarningCallOut');
},

goToNextStep() {
act(() => {
find('restoreSnapshotsForm.nextButton').simulate('click');
});
component.update();
},

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');
Expand Down Expand Up @@ -59,4 +81,7 @@ export type RestoreSnapshotFormTestSubject =
| 'snapshotRestoreStepLogistics'
| 'includeGlobalStateSwitch'
| 'systemIndicesInfoCallOut'
| 'dataStreamWarningCallOut';
| 'dataStreamWarningCallOut'
| 'restoreSnapshotsForm.backButton'
| 'restoreSnapshotsForm.nextButton'
| 'modifyIndexSettingsSwitch';
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@ describe('<RestoreSnapshot />', () => {
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.goToNextStep();
expect(actions.canGoToADifferentStep()).toBe(true);
actions.toggleModifyIndexSettings();
expect(actions.canGoToADifferentStep()).toBe(false);
});
});

describe('with data streams', () => {
beforeEach(async () => {
httpRequestsMockHelpers.setGetSnapshotResponse(fixtures.getSnapshot());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -125,7 +125,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"
Expand All @@ -140,6 +145,7 @@ export const RestoreSnapshotForm: React.FunctionComponent<Props> = ({
iconType="arrowRight"
onClick={() => onNext()}
disabled={!validation.isValid}
data-test-subj="nextButton"
>
<FormattedMessage
id="xpack.snapshotRestore.restoreForm.nextButtonLabel"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 4db039c

Please sign in to comment.