Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Upgrade Assistant] Reindexing progress #114275

Merged
merged 4 commits into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { act } from 'react-dom/test-utils';
import { setupEnvironment } from '../helpers';
import { ElasticsearchTestBed, setupElasticsearchPage } from './es_deprecations.helpers';
import { esDeprecationsMockResponse, MOCK_SNAPSHOT_ID, MOCK_JOB_ID } from './mocked_responses';
import { ReindexStatus, ReindexStep } from '../../../common/types';

// Note: The reindexing flyout UX is subject to change; more tests should be added here once functionality is built out
describe('Reindex deprecation flyout', () => {
Expand Down Expand Up @@ -93,4 +94,110 @@ describe('Reindex deprecation flyout', () => {

expect(exists('reindexDetails.fetchFailedCallout')).toBe(true);
});

describe('reindexing progress', () => {
it('has not started yet', async () => {
const { actions, find, exists } = testBed;

await actions.table.clickDeprecationRowAt('reindex', 0);
expect(find('reindexChecklistTitle').text()).toEqual('Reindexing process');
expect(exists('cancelReindexingDocumentsButton')).toBe(false);
});

it('has started but not yet reindexing documents', async () => {
httpRequestsMockHelpers.setReindexStatusResponse({
reindexOp: {
status: ReindexStatus.inProgress,
lastCompletedStep: ReindexStep.readonly,
reindexTaskPercComplete: null,
},
warnings: [],
hasRequiredPrivileges: true,
});

await act(async () => {
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
});

testBed.component.update();
const { actions, find, exists } = testBed;

await actions.table.clickDeprecationRowAt('reindex', 0);

expect(find('reindexChecklistTitle').text()).toEqual('Reindexing in progress… 5%');
expect(exists('cancelReindexingDocumentsButton')).toBe(false);
});

it('has started reindexing documents', async () => {
httpRequestsMockHelpers.setReindexStatusResponse({
reindexOp: {
status: ReindexStatus.inProgress,
lastCompletedStep: ReindexStep.reindexStarted,
reindexTaskPercComplete: 0.25,
},
warnings: [],
hasRequiredPrivileges: true,
});

await act(async () => {
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
});

testBed.component.update();
const { actions, find, exists } = testBed;

await actions.table.clickDeprecationRowAt('reindex', 0);

expect(find('reindexChecklistTitle').text()).toEqual('Reindexing in progress… 31%');
expect(exists('cancelReindexingDocumentsButton')).toBe(true);
});

it('has completed reindexing documents', async () => {
httpRequestsMockHelpers.setReindexStatusResponse({
reindexOp: {
status: ReindexStatus.inProgress,
lastCompletedStep: ReindexStep.reindexCompleted,
reindexTaskPercComplete: 1,
},
warnings: [],
hasRequiredPrivileges: true,
});

await act(async () => {
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
});

testBed.component.update();
const { actions, find, exists } = testBed;

await actions.table.clickDeprecationRowAt('reindex', 0);

expect(find('reindexChecklistTitle').text()).toEqual('Reindexing in progress… 95%');
expect(exists('cancelReindexingDocumentsButton')).toBe(false);
});

it('has completed', async () => {
httpRequestsMockHelpers.setReindexStatusResponse({
reindexOp: {
status: ReindexStatus.completed,
lastCompletedStep: ReindexStep.aliasCreated,
reindexTaskPercComplete: 1,
},
warnings: [],
hasRequiredPrivileges: true,
});

await act(async () => {
testBed = await setupElasticsearchPage({ isReadOnlyMode: false });
});

testBed.component.update();
const { actions, find, exists } = testBed;

await actions.table.clickDeprecationRowAt('reindex', 0);

expect(find('reindexChecklistTitle').text()).toEqual('Reindexing process');
expect(exists('cancelReindexingDocumentsButton')).toBe(false);
});
});
});

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
EuiFlyoutBody,
EuiFlyoutFooter,
EuiSpacer,
EuiTitle,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';

Expand Down Expand Up @@ -144,14 +143,6 @@ export const ChecklistFlyoutStep: React.FunctionComponent<{
</p>
</EuiCallOut>
<EuiSpacer />
<EuiTitle size="xs">
<h3>
<FormattedMessage
id="xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklistTitle"
defaultMessage="Reindexing process"
/>
</h3>
</EuiTitle>
<ReindexProgress reindexState={reindexState} cancelReindex={cancelReindex} />
</EuiFlyoutBody>
<EuiFlyoutFooter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,45 +29,69 @@ describe('ReindexProgress', () => {
);

expect(wrapper).toMatchInlineSnapshot(`
<StepProgress
steps={
Array [
Object {
"status": "inProgress",
"title": <FormattedMessage
defaultMessage="Setting old index to read-only"
id="xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.readonlyStepTitle"
values={Object {}}
/>,
},
Object {
"status": "incomplete",
"title": <FormattedMessage
defaultMessage="Creating new index"
id="xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.createIndexStepTitle"
values={Object {}}
/>,
},
Object {
"status": "incomplete",
"title": <FormattedMessage
defaultMessage="Reindexing documents"
id="xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.reindexingDocumentsStepTitle"
values={Object {}}
/>,
},
Object {
"status": "incomplete",
"title": <FormattedMessage
defaultMessage="Swapping original index with alias"
id="xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.aliasSwapStepTitle"
values={Object {}}
/>,
},
]
}
/>
`);
<Fragment>
<EuiTitle
data-test-subj="reindexChecklistTitle"
size="xs"
>
<h3>
<FormattedMessage
defaultMessage="Reindexing in progress… {percents}"
id="xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingInProgressTitle"
values={
Object {
"percents": "0%",
}
}
/>
</h3>
</EuiTitle>
<StepProgress
steps={
Array [
Object {
"status": "inProgress",
"title": <FormattedMessage
defaultMessage="Setting old index to read-only"
id="xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.readonlyStepTitle"
values={Object {}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this was here from before, but I don't think we need to specify empty value objects for all these FormattedMessage components 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I regenerated those snapshots with node scripts/jest.js -i plugins/upgrade_assistant/ -u command, so I think this is how the component is 'shallow rendered'.

/>,
},
Object {
"status": "incomplete",
"title": <FormattedMessage
defaultMessage="Creating new index"
id="xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.createIndexStepTitle"
values={Object {}}
/>,
},
Object {
"status": "incomplete",
"title": <EuiFlexGroup
alignItems="center"
>
<EuiFlexItem>
<FormattedMessage
defaultMessage="Reindexing documents"
id="xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.reindexingDocumentsStepTitle"
values={Object {}}
/>
</EuiFlexItem>
</EuiFlexGroup>,
},
Object {
"status": "incomplete",
"title": <FormattedMessage
defaultMessage="Swapping original index with alias"
id="xpack.upgradeAssistant.checkupTab.reindexing.flyout.checklistStep.reindexingChecklist.aliasSwapStepTitle"
values={Object {}}
/>,
},
]
}
/>
</Fragment>
`);
});

it('displays errors in the step that failed', () => {
Expand All @@ -84,30 +108,9 @@ describe('ReindexProgress', () => {
cancelReindex={jest.fn()}
/>
);

const aliasStep = wrapper.props().steps[3];
const aliasStep = (wrapper.find('StepProgress').props() as any).steps[3];
expect(aliasStep.children.props.errorMessage).toEqual(
`This is an error that happened on alias switch`
);
});

it('shows reindexing document progress bar', () => {
const wrapper = shallow(
<ReindexProgress
reindexState={
{
lastCompletedStep: ReindexStep.reindexStarted,
status: ReindexStatus.inProgress,
reindexTaskPercComplete: 0.25,
errorMessage: null,
} as ReindexState
}
cancelReindex={jest.fn()}
/>
);

const reindexStep = wrapper.props().steps[2];
expect(reindexStep.children.type.name).toEqual('ReindexProgressBar');
expect(reindexStep.children.props.reindexState.reindexTaskPercComplete).toEqual(0.25);
});
});
Loading