Skip to content

Commit 004aeae

Browse files
authored
[UA] Add unit tests to data streams (elastic#217879)
Fixes elastic#217785 ## Summary This PR adds jest tests for the data streams flows in the file `data_streams_deprecation_flyout.test.ts `
1 parent 22cb968 commit 004aeae

File tree

15 files changed

+967
-15
lines changed

15 files changed

+967
-15
lines changed

x-pack/platform/plugins/private/upgrade_assistant/__jest__/client_integration/es_deprecations/data_streams_deprecation_flyout.test.ts

Lines changed: 781 additions & 0 deletions
Large diffs are not rendered by default.

x-pack/platform/plugins/private/upgrade_assistant/__jest__/client_integration/es_deprecations/deprecations_list.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ describe('ES deprecations table', () => {
140140

141141
expect(find('deprecationTableRow').length).toEqual(criticalDeprecations.length);
142142

143+
await actions.searchBar.clickStatusFilterDropdown();
143144
await actions.searchBar.clickFilterByTitle('Critical'); // Reset filter
144145

145146
expect(find('deprecationTableRow').length).toEqual(

x-pack/platform/plugins/private/upgrade_assistant/__jest__/client_integration/es_deprecations/es_deprecations.helpers.ts

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ const createActions = (testBed: TestBed) => {
4040
component.update();
4141
},
4242
clickDeprecationRowAt: async (
43-
deprecationType: 'mlSnapshot' | 'indexSetting' | 'reindex' | 'default' | 'clusterSetting',
43+
deprecationType:
44+
| 'mlSnapshot'
45+
| 'indexSetting'
46+
| 'reindex'
47+
| 'default'
48+
| 'clusterSetting'
49+
| 'dataStream',
4450
index: number
4551
) => {
4652
await act(async () => {
@@ -177,6 +183,46 @@ const createActions = (testBed: TestBed) => {
177183
component.update();
178184
},
179185
};
186+
const dataStreamDeprecationFlyout = {
187+
clickReindexButton: async () => {
188+
await act(async () => {
189+
find('startDataStreamReindexingButton').simulate('click');
190+
});
191+
192+
component.update();
193+
},
194+
clickReadOnlyButton: async () => {
195+
await act(async () => {
196+
find('startDataStreamReadonlyButton').simulate('click');
197+
});
198+
199+
component.update();
200+
},
201+
closeFlyout: async () => {
202+
await act(async () => {
203+
find('closeDataStreamReindexingButton').simulate('click');
204+
});
205+
component.update();
206+
},
207+
checkMigrationWarningCheckbox: async () => {
208+
await act(async () => {
209+
find('migrationWarningCheckbox')
210+
.find('input.euiCheckbox__input')
211+
.simulate('change', {
212+
target: {
213+
checked: true,
214+
},
215+
});
216+
});
217+
component.update();
218+
},
219+
clickStartActionButton: async () => {
220+
await act(async () => {
221+
find('startActionButton').simulate('click');
222+
});
223+
component.update();
224+
},
225+
};
180226

181227
return {
182228
table,
@@ -186,6 +232,7 @@ const createActions = (testBed: TestBed) => {
186232
reindexDeprecationFlyout,
187233
indexSettingsDeprecationFlyout,
188234
clusterSettingsDeprecationFlyout,
235+
dataStreamDeprecationFlyout,
189236
};
190237
};
191238

x-pack/platform/plugins/private/upgrade_assistant/__jest__/client_integration/es_deprecations/mocked_responses.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,72 @@ const MOCK_DEFAULT_DEPRECATION: EnrichedDeprecationInfo = {
8080
index: 'nested_multi-fields',
8181
};
8282

83+
export const MOCK_DS_DEPRECATION: EnrichedDeprecationInfo = {
84+
index: 'reindex_or_readonly_ds',
85+
type: 'data_streams',
86+
details: 'Data stream deprecation details',
87+
message: 'Outdated data stream',
88+
url: 'doc_url',
89+
level: 'critical',
90+
resolveDuringUpgrade: false,
91+
correctiveAction: {
92+
type: 'dataStream',
93+
metadata: {
94+
excludedActions: [],
95+
reindexRequired: true,
96+
totalBackingIndices: 1,
97+
indicesRequiringUpgradeCount: 1,
98+
indicesRequiringUpgrade: ['ds_index'],
99+
ignoredIndicesRequiringUpgrade: [],
100+
ignoredIndicesRequiringUpgradeCount: 0,
101+
},
102+
},
103+
};
104+
105+
export const MOCK_DS_DEPRECATION_REINDEX: EnrichedDeprecationInfo = {
106+
index: 'reindex_ds',
107+
type: 'data_streams',
108+
details: 'Data stream deprecation details',
109+
message: 'Outdated data stream',
110+
url: 'doc_url',
111+
level: 'critical',
112+
resolveDuringUpgrade: false,
113+
correctiveAction: {
114+
type: 'dataStream',
115+
metadata: {
116+
excludedActions: ['readOnly'],
117+
reindexRequired: true,
118+
totalBackingIndices: 1,
119+
indicesRequiringUpgradeCount: 1,
120+
indicesRequiringUpgrade: ['ds_index'],
121+
ignoredIndicesRequiringUpgrade: [],
122+
ignoredIndicesRequiringUpgradeCount: 0,
123+
},
124+
},
125+
};
126+
127+
export const MOCK_DS_DEPRECATION_READ_ONLY: EnrichedDeprecationInfo = {
128+
index: 'readonly_ds',
129+
type: 'data_streams',
130+
details: 'Data stream deprecation details',
131+
message: 'Outdated data stream',
132+
url: 'doc_url',
133+
level: 'critical',
134+
resolveDuringUpgrade: false,
135+
correctiveAction: {
136+
type: 'dataStream',
137+
metadata: {
138+
excludedActions: ['reindex'],
139+
reindexRequired: true,
140+
totalBackingIndices: 1,
141+
indicesRequiringUpgradeCount: 1,
142+
indicesRequiringUpgrade: ['ds_index'],
143+
ignoredIndicesRequiringUpgrade: [],
144+
ignoredIndicesRequiringUpgradeCount: 0,
145+
},
146+
},
147+
};
148+
83149
export const esDeprecationsMockResponse: ESUpgradeStatus = {
84150
totalCriticalDeprecations: 2,
85151
migrationsDeprecations: [
@@ -88,6 +154,9 @@ export const esDeprecationsMockResponse: ESUpgradeStatus = {
88154
MOCK_DEFAULT_DEPRECATION,
89155
MOCK_REINDEX_DEPRECATION,
90156
MOCK_CLUSTER_SETTING_DEPRECATION,
157+
MOCK_DS_DEPRECATION,
158+
MOCK_DS_DEPRECATION_REINDEX,
159+
MOCK_DS_DEPRECATION_READ_ONLY,
91160
],
92161
totalCriticalHealthIssues: 0,
93162
enrichedHealthIndicators: [],

x-pack/platform/plugins/private/upgrade_assistant/__jest__/client_integration/helpers/http_requests.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,25 @@ const registerHttpRequestMockHelpers = (
150150
mockResponse('POST', `${API_BASE_PATH}/cluster_settings`, response, error);
151151
};
152152

153+
const setDataStreamMigrationStatusResponse = (
154+
dataStreamName: string,
155+
response?: object,
156+
error?: ResponseError
157+
) =>
158+
mockResponse('GET', `${API_BASE_PATH}/migrate_data_stream/${dataStreamName}`, response, error);
159+
160+
const setDataStreamMetadataResponse = (
161+
dataStreamName: string,
162+
response?: object,
163+
error?: ResponseError
164+
) =>
165+
mockResponse(
166+
'GET',
167+
`${API_BASE_PATH}/migrate_data_stream/${dataStreamName}/metadata`,
168+
response,
169+
error
170+
);
171+
153172
return {
154173
setLoadCloudBackupStatusResponse,
155174
setLoadEsDeprecationsResponse,
@@ -170,6 +189,8 @@ const registerHttpRequestMockHelpers = (
170189
setLoadRemoteClustersResponse,
171190
setLoadNodeDiskSpaceResponse,
172191
setClusterSettingsResponse,
192+
setDataStreamMigrationStatusResponse,
193+
setDataStreamMetadataResponse,
173194
};
174195
};
175196

x-pack/platform/plugins/private/upgrade_assistant/public/application/components/es_deprecations/common/step_progress.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const Step: React.FunctionComponent<StepProgressStep & { idx: number }> = ({
6060

6161
return (
6262
<Fragment>
63-
<div className="upgStepProgress__step">
63+
<div className="upgStepProgress__step" data-test-subj="stepProgressStep">
6464
<StepStatus status={status} idx={idx} />
6565
<div className={titleClassName}>{title}</div>
6666
</div>

x-pack/platform/plugins/private/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/data_streams/flyout/container.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ export const DataStreamReindexFlyout: React.FunctionComponent<Props> = ({
284284
description: lastIndexCreationDateFormatted,
285285
},
286286
]}
287+
data-test-subj="dataStreamLastIndexCreationDate"
287288
/>
288289
</EuiFlexItem>
289290
<EuiFlexGroup>
@@ -301,6 +302,7 @@ export const DataStreamReindexFlyout: React.FunctionComponent<Props> = ({
301302
description: docsSizeFormatted,
302303
},
303304
]}
305+
data-test-subj="dataStreamSize"
304306
/>
305307
</EuiFlexItem>
306308
<EuiFlexItem>
@@ -317,6 +319,7 @@ export const DataStreamReindexFlyout: React.FunctionComponent<Props> = ({
317319
description: indicesRequiringUpgradeDocsCount,
318320
},
319321
]}
322+
data-test-subj="dataStreamDocumentCount"
320323
/>
321324
</EuiFlexItem>
322325
</EuiFlexGroup>

x-pack/platform/plugins/private/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/data_streams/flyout/steps/checklist/checklist_step.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export const ChecklistFlyoutStep: React.FunctionComponent<{
5858

5959
return (
6060
<Fragment>
61-
<EuiFlyoutBody>
61+
<EuiFlyoutBody data-test-subj="dataStreamMigrationChecklistFlyout">
6262
{hasRequiredPrivileges === false && (
6363
<Fragment>
6464
<EuiSpacer />
@@ -71,6 +71,7 @@ export const ChecklistFlyoutStep: React.FunctionComponent<{
7171
}
7272
color="danger"
7373
iconType="warning"
74+
data-test-subj="dsInsufficientPrivilegesCallout"
7475
/>
7576
</Fragment>
7677
)}
@@ -159,7 +160,12 @@ export const ChecklistFlyoutStep: React.FunctionComponent<{
159160
<EuiFlyoutFooter>
160161
<EuiFlexGroup justifyContent="spaceBetween">
161162
<EuiFlexItem grow={false}>
162-
<EuiButtonEmpty iconType="cross" onClick={closeFlyout} flush="left">
163+
<EuiButtonEmpty
164+
iconType="cross"
165+
onClick={closeFlyout}
166+
flush="left"
167+
data-test-subj="closeDataStreamReindexingButton"
168+
>
163169
<FormattedMessage
164170
id="xpack.upgradeAssistant.dataStream.migration.flyout.checklistStep.closeButtonLabel"
165171
defaultMessage="Close"

x-pack/platform/plugins/private/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/data_streams/flyout/steps/completed/completed_step.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ export const MigrationCompletedFlyoutStep: React.FunctionComponent<Props> = ({
3737
<>
3838
<EuiFlyoutBody>
3939
<EuiTitle size="s">
40-
<h3>
40+
<h3 data-test-subj="dataStreamMigrationCompletedTitle">
4141
<FormattedMessage
4242
id="xpack.upgradeAssistant.dataStream.migration.flyout.warningsStep.acceptChangesTitle"
4343
defaultMessage="Data Stream Migration Complete"
4444
/>
4545
</h3>
4646
</EuiTitle>
4747
<EuiSpacer size="m" />
48-
<p>
48+
<p data-test-subj="dataStreamMigrationCompletedDescription">
4949
<FormattedMessage
5050
id="xpack.upgradeAssistant.dataStream.migration.flyout.warningsStep.acceptChangesTitle"
5151
defaultMessage="Success! {count, plural, =0 {backing indices} =1 {# backing index} other {# backing indices}} successfully {resolutionType, select, reindex {reindexed} readonly {marked as read-only} other {migrated}}."
@@ -56,7 +56,12 @@ export const MigrationCompletedFlyoutStep: React.FunctionComponent<Props> = ({
5656
<EuiFlyoutFooter>
5757
<EuiFlexGroup justifyContent="spaceBetween">
5858
<EuiFlexItem grow={false}>
59-
<EuiButtonEmpty iconType="cross" onClick={closeFlyout} flush="left">
59+
<EuiButtonEmpty
60+
iconType="cross"
61+
onClick={closeFlyout}
62+
flush="left"
63+
data-test-subj="closeDataStreamReindexingButton"
64+
>
6065
<FormattedMessage
6166
id="xpack.upgradeAssistant.dataStream.migration.flyout.completedStep.closeButtonLabel"
6267
defaultMessage="Close"

x-pack/platform/plugins/private/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/data_streams/flyout/steps/confirm/callouts.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const ReindexWarningCallout: React.FunctionComponent<{}> = () => {
2020
}
2121
color="warning"
2222
iconType="warning"
23+
data-test-subj="reindexDsWarningCallout"
2324
>
2425
<p>
2526
<FormattedMessage
@@ -42,6 +43,7 @@ export const ReadonlyWarningCallout: React.FunctionComponent<{}> = () => {
4243
}
4344
color="warning"
4445
iconType="warning"
46+
data-test-subj="readOnlyDsWarningCallout"
4547
>
4648
<p>
4749
<FormattedMessage

0 commit comments

Comments
 (0)