Skip to content

Commit bc7ec3b

Browse files
add version-specific logic
1 parent 2e2e92f commit bc7ec3b

18 files changed

Lines changed: 133 additions & 152 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
import SemVer from 'semver/classes/semver';
8+
9+
/*
10+
* These constants are used only in tests to add conditional logic based on Kibana version
11+
* On master, the version should represent the next major version (e.g., master --> 8.0.0)
12+
* The release branch should match the release version (e.g., 7.x --> 7.0.0)
13+
*/
14+
export const mockKibanaVersion = '8.0.0';
15+
export const mockKibanaSemverVersion = new SemVer(mockKibanaVersion);

x-pack/plugins/upgrade_assistant/public/application/components/tabs.test.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
*/
77

88
import React from 'react';
9-
import SemVer from 'semver/classes/semver';
109
import { mountWithIntl } from '@kbn/test/jest';
1110
import { httpServiceMock } from 'src/core/public/mocks';
11+
import { mockKibanaSemverVersion } from '../../../common/constants';
1212
import { UpgradeAssistantTabs } from './tabs';
1313
import { LoadingState } from './types';
1414

@@ -18,7 +18,6 @@ import { OverviewTab } from './tabs/overview';
1818
const promisesToResolve = () => new Promise((resolve) => setTimeout(resolve, 0));
1919

2020
const mockHttp = httpServiceMock.createSetupContract();
21-
const mockKibanaVersion = new SemVer('8.0.0');
2221

2322
jest.mock('../app_context', () => {
2423
return {
@@ -29,9 +28,9 @@ jest.mock('../app_context', () => {
2928
ELASTIC_WEBSITE_URL: 'https://www.elastic.co/',
3029
},
3130
kibanaVersionInfo: {
32-
currentMajor: mockKibanaVersion.major,
33-
prevMajor: mockKibanaVersion.major - 1,
34-
nextMajor: mockKibanaVersion.major + 1,
31+
currentMajor: mockKibanaSemverVersion.major,
32+
prevMajor: mockKibanaSemverVersion.major - 1,
33+
nextMajor: mockKibanaSemverVersion.major + 1,
3534
},
3635
};
3736
},

x-pack/plugins/upgrade_assistant/public/application/components/tabs/checkup/checkup_tab.test.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import { shallow } from 'enzyme';
99
import React from 'react';
10-
import SemVer from 'semver/classes/semver';
10+
import { mockKibanaSemverVersion } from '../../../../../common/constants';
1111

1212
import { LoadingState } from '../../types';
1313
import AssistanceData from '../__fixtures__/checkup_api_response.json';
@@ -22,8 +22,6 @@ const defaultProps = {
2222
setSelectedTabIndex: jest.fn(),
2323
};
2424

25-
const mockKibanaVersion = new SemVer('8.0.0');
26-
2725
jest.mock('../../../app_context', () => {
2826
return {
2927
useAppContext: () => {
@@ -33,9 +31,9 @@ jest.mock('../../../app_context', () => {
3331
ELASTIC_WEBSITE_URL: 'https://www.elastic.co/',
3432
},
3533
kibanaVersionInfo: {
36-
currentMajor: mockKibanaVersion.major,
37-
prevMajor: mockKibanaVersion.major - 1,
38-
nextMajor: mockKibanaVersion.major + 1,
34+
currentMajor: mockKibanaSemverVersion.major,
35+
prevMajor: mockKibanaSemverVersion.major - 1,
36+
nextMajor: mockKibanaSemverVersion.major + 1,
3937
},
4038
};
4139
},

x-pack/plugins/upgrade_assistant/public/application/components/tabs/checkup/deprecations/index_table.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ export class IndexDeprecationTable extends React.Component<
145145
// NOTE: this naive implementation assumes all indices in the table are
146146
// should show the reindex button. This should work for known use cases.
147147
const { indices } = this.props;
148-
const showActionsColumn = Boolean(indices.find((i) => i.reindex === true));
148+
const hasActionsColumn = Boolean(indices.find((i) => i.reindex === true));
149149

150-
if (showActionsColumn === false) {
150+
if (hasActionsColumn === false) {
151151
return null;
152152
}
153153

x-pack/plugins/upgrade_assistant/public/application/components/tabs/checkup/deprecations/reindex/flyout/__snapshots__/warning_step.test.tsx.snap

Lines changed: 0 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugins/upgrade_assistant/public/application/components/tabs/checkup/deprecations/reindex/flyout/checklist_step.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('ChecklistFlyout', () => {
2929
status: undefined,
3030
reindexTaskPercComplete: null,
3131
errorMessage: null,
32-
reindexWarnings: [ReindexWarning.allField],
32+
reindexWarnings: [ReindexWarning.customTypeName],
3333
hasRequiredPrivileges: true,
3434
} as ReindexState,
3535
};

x-pack/plugins/upgrade_assistant/public/application/components/tabs/checkup/deprecations/reindex/flyout/warning_step.test.tsx

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import { I18nProvider } from '@kbn/i18n/react';
99
import { mount, shallow } from 'enzyme';
1010
import React from 'react';
11+
import { mockKibanaSemverVersion } from '../../../../../../../../common/constants';
1112

1213
import { ReindexWarning } from '../../../../../../../../common/types';
1314
import { idForWarning, WarningsFlyoutStep } from './warnings_step';
@@ -20,6 +21,11 @@ jest.mock('../../../../../../app_context', () => {
2021
DOC_LINK_VERSION: 'current',
2122
ELASTIC_WEBSITE_URL: 'https://www.elastic.co/',
2223
},
24+
kibanaVersionInfo: {
25+
currentMajor: mockKibanaSemverVersion.major,
26+
prevMajor: mockKibanaSemverVersion.major - 1,
27+
nextMajor: mockKibanaSemverVersion.major + 1,
28+
},
2329
};
2430
},
2531
};
@@ -37,19 +43,21 @@ describe('WarningsFlyoutStep', () => {
3743
expect(shallow(<WarningsFlyoutStep {...defaultProps} />)).toMatchSnapshot();
3844
});
3945

40-
it('does not allow proceeding until all are checked', () => {
41-
const wrapper = mount(
42-
<I18nProvider>
43-
<WarningsFlyoutStep {...defaultProps} />
44-
</I18nProvider>
45-
);
46-
const button = wrapper.find('EuiButton');
47-
48-
button.simulate('click');
49-
expect(defaultProps.advanceNextStep).not.toHaveBeenCalled();
50-
51-
wrapper.find(`input#${idForWarning(ReindexWarning.customTypeName)}`).simulate('change');
52-
button.simulate('click');
53-
expect(defaultProps.advanceNextStep).toHaveBeenCalled();
54-
});
46+
if (mockKibanaSemverVersion.major === 7) {
47+
it('does not allow proceeding until all are checked', () => {
48+
const wrapper = mount(
49+
<I18nProvider>
50+
<WarningsFlyoutStep {...defaultProps} />
51+
</I18nProvider>
52+
);
53+
const button = wrapper.find('EuiButton');
54+
55+
button.simulate('click');
56+
expect(defaultProps.advanceNextStep).not.toHaveBeenCalled();
57+
58+
wrapper.find(`input#${idForWarning(ReindexWarning.customTypeName)}`).simulate('change');
59+
button.simulate('click');
60+
expect(defaultProps.advanceNextStep).toHaveBeenCalled();
61+
});
62+
}
5563
});

x-pack/plugins/upgrade_assistant/public/application/components/tabs/checkup/deprecations/reindex/flyout/warnings_step.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,10 @@ export const WarningsFlyoutStep: React.FunctionComponent<WarningsConfirmationFly
101101
}));
102102
};
103103

104-
const { docLinks } = useAppContext();
104+
const { docLinks, kibanaVersionInfo } = useAppContext();
105105
const { ELASTIC_WEBSITE_URL, DOC_LINK_VERSION } = docLinks;
106106
const esDocBasePath = `${ELASTIC_WEBSITE_URL}guide/en/elasticsearch/reference`;
107107

108-
// TODO: Revisit warnings returned for 8.0 upgrade; many of these are likely obselete now
109108
return (
110109
<>
111110
<EuiFlyoutBody>
@@ -130,7 +129,7 @@ export const WarningsFlyoutStep: React.FunctionComponent<WarningsConfirmationFly
130129

131130
<EuiSpacer />
132131

133-
{warnings.includes(ReindexWarning.customTypeName) && (
132+
{kibanaVersionInfo.currentMajor === 7 && warnings.includes(ReindexWarning.customTypeName) && (
134133
<WarningCheckbox
135134
checkedIds={checkedIds}
136135
onChange={onChange}

x-pack/plugins/upgrade_assistant/server/lib/__fixtures__/version.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@
55
* 2.0.
66
*/
77

8-
import { SemVer } from 'semver';
8+
import { mockKibanaSemverVersion } from '../../../common/constants';
99

10-
export const MOCK_VERSION_STRING = '8.0.0';
11-
12-
export const getMockVersionInfo = (versionString = MOCK_VERSION_STRING) => {
13-
const currentVersion = new SemVer(versionString);
14-
const currentMajor = currentVersion.major;
10+
export const getMockVersionInfo = () => {
11+
const currentMajor = mockKibanaSemverVersion.major;
1512

1613
return {
17-
currentVersion,
14+
currentVersion: mockKibanaSemverVersion,
1815
currentMajor,
1916
prevMajor: currentMajor - 1,
2017
nextMajor: currentMajor + 1,

x-pack/plugins/upgrade_assistant/server/lib/es_version_precheck.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import { SemVer } from 'semver';
99
import { IScopedClusterClient, kibanaResponseFactory } from 'src/core/server';
1010
import { coreMock } from 'src/core/server/mocks';
1111
import { licensingMock } from '../../../../plugins/licensing/server/mocks';
12-
import { MOCK_VERSION_STRING, getMockVersionInfo } from './__fixtures__/version';
12+
import { mockKibanaVersion } from '../../common/constants';
13+
import { getMockVersionInfo } from './__fixtures__/version';
1314

1415
import {
1516
esVersionCheck,
@@ -97,7 +98,7 @@ describe('verifyAllMatchKibanaVersion', () => {
9798

9899
describe('EsVersionPrecheck', () => {
99100
beforeEach(() => {
100-
versionService.setup(MOCK_VERSION_STRING);
101+
versionService.setup(mockKibanaVersion);
101102
});
102103

103104
it('returns a 403 when callCluster fails with a 403', async () => {

0 commit comments

Comments
 (0)