@@ -13,32 +13,28 @@ import { renderWithI18n } from '@kbn/test-jest-helpers';
1313import { ReindexStep } from '@kbn/reindex-service-plugin/common' ;
1414import { ReindexStatus } from '@kbn/upgrade-assistant-pkg-common' ;
1515import { LoadingState } from '../../../../../../types' ;
16- import type { ReindexState } from '../../../use_reindex' ;
1716import { ReindexProgress } from './progress' ;
17+ import { createReindexState } from '../../../../test_utils/helpers' ;
1818
1919describe ( 'ReindexProgress' , ( ) => {
2020 it ( 'renders' , ( ) => {
2121 renderWithI18n (
2222 < ReindexProgress
23- reindexState = {
24- {
25- lastCompletedStep : ReindexStep . created ,
26- status : ReindexStatus . inProgress ,
27- reindexTaskPercComplete : null ,
28- errorMessage : null ,
23+ reindexState = { {
24+ ...createReindexState ( {
2925 loadingState : LoadingState . Success ,
3026 meta : {
27+ ...createReindexState ( ) . meta ,
3128 indexName : 'foo' ,
3229 reindexName : 'reindexed-foo' ,
3330 aliases : [ ] ,
34- isFrozen : false ,
35- isReadonly : false ,
36- isInDataStream : false ,
37- isClosedIndex : false ,
38- isFollowerIndex : false ,
3931 } ,
40- } as ReindexState
41- }
32+ } ) ,
33+ lastCompletedStep : ReindexStep . created ,
34+ status : ReindexStatus . inProgress ,
35+ reindexTaskPercComplete : null ,
36+ errorMessage : null ,
37+ } }
4238 cancelReindex = { jest . fn ( ) }
4339 />
4440 ) ;
@@ -61,25 +57,22 @@ describe('ReindexProgress', () => {
6157 it ( 'displays errors in the step that failed' , ( ) => {
6258 renderWithI18n (
6359 < ReindexProgress
64- reindexState = {
65- {
66- lastCompletedStep : ReindexStep . reindexCompleted ,
67- status : ReindexStatus . failed ,
68- reindexTaskPercComplete : 1 ,
69- errorMessage : `This is an error that happened on alias switch` ,
60+ reindexState = { {
61+ ...createReindexState ( {
7062 loadingState : LoadingState . Success ,
7163 meta : {
64+ ...createReindexState ( ) . meta ,
7265 indexName : 'foo' ,
7366 reindexName : 'reindexed-foo' ,
7467 aliases : [ ] ,
7568 isFrozen : true ,
76- isReadonly : false ,
77- isInDataStream : false ,
78- isClosedIndex : false ,
79- isFollowerIndex : false ,
8069 } ,
81- } as ReindexState
82- }
70+ } ) ,
71+ lastCompletedStep : ReindexStep . reindexCompleted ,
72+ status : ReindexStatus . failed ,
73+ reindexTaskPercComplete : 1 ,
74+ errorMessage : `This is an error that happened on alias switch` ,
75+ } }
8376 cancelReindex = { jest . fn ( ) }
8477 />
8578 ) ;
@@ -97,4 +90,110 @@ describe('ReindexProgress', () => {
9790 expect ( stepContent ! ) . toHaveTextContent ( 'There was an error' ) ;
9891 expect ( stepContent ! ) . toHaveTextContent ( 'This is an error that happened on alias switch' ) ;
9992 } ) ;
93+
94+ it ( 'has started but not yet reindexing documents' , ( ) => {
95+ renderWithI18n (
96+ < ReindexProgress
97+ reindexState = { {
98+ ...createReindexState ( {
99+ loadingState : LoadingState . Success ,
100+ meta : {
101+ ...createReindexState ( ) . meta ,
102+ indexName : 'foo' ,
103+ reindexName : 'reindexed-foo' ,
104+ aliases : [ ] ,
105+ } ,
106+ } ) ,
107+ lastCompletedStep : ReindexStep . readonly ,
108+ status : ReindexStatus . inProgress ,
109+ reindexTaskPercComplete : null ,
110+ } }
111+ cancelReindex = { jest . fn ( ) }
112+ />
113+ ) ;
114+
115+ expect ( screen . getByTestId ( 'reindexChecklistTitle' ) ) . toHaveTextContent (
116+ 'Reindexing in progress… 5%'
117+ ) ;
118+ expect ( screen . queryByTestId ( 'cancelReindexingDocumentsButton' ) ) . toBeNull ( ) ;
119+ } ) ;
120+
121+ it ( 'has started reindexing documents' , ( ) => {
122+ renderWithI18n (
123+ < ReindexProgress
124+ reindexState = { {
125+ ...createReindexState ( {
126+ loadingState : LoadingState . Success ,
127+ meta : {
128+ ...createReindexState ( ) . meta ,
129+ indexName : 'foo' ,
130+ reindexName : 'reindexed-foo' ,
131+ aliases : [ ] ,
132+ } ,
133+ } ) ,
134+ lastCompletedStep : ReindexStep . reindexStarted ,
135+ status : ReindexStatus . inProgress ,
136+ reindexTaskPercComplete : 0.25 ,
137+ } }
138+ cancelReindex = { jest . fn ( ) }
139+ />
140+ ) ;
141+
142+ expect ( screen . getByTestId ( 'reindexChecklistTitle' ) ) . toHaveTextContent (
143+ 'Reindexing in progress… 30%'
144+ ) ;
145+ expect ( screen . getByTestId ( 'cancelReindexingDocumentsButton' ) ) . toBeInTheDocument ( ) ;
146+ } ) ;
147+
148+ it ( 'has completed reindexing documents' , ( ) => {
149+ renderWithI18n (
150+ < ReindexProgress
151+ reindexState = { {
152+ ...createReindexState ( {
153+ loadingState : LoadingState . Success ,
154+ meta : {
155+ ...createReindexState ( ) . meta ,
156+ indexName : 'foo' ,
157+ reindexName : 'reindexed-foo' ,
158+ aliases : [ ] ,
159+ } ,
160+ } ) ,
161+ lastCompletedStep : ReindexStep . reindexCompleted ,
162+ status : ReindexStatus . inProgress ,
163+ reindexTaskPercComplete : 1 ,
164+ } }
165+ cancelReindex = { jest . fn ( ) }
166+ />
167+ ) ;
168+
169+ expect ( screen . getByTestId ( 'reindexChecklistTitle' ) ) . toHaveTextContent (
170+ 'Reindexing in progress… 90%'
171+ ) ;
172+ expect ( screen . queryByTestId ( 'cancelReindexingDocumentsButton' ) ) . toBeNull ( ) ;
173+ } ) ;
174+
175+ it ( 'has completed' , ( ) => {
176+ renderWithI18n (
177+ < ReindexProgress
178+ reindexState = { {
179+ ...createReindexState ( {
180+ loadingState : LoadingState . Success ,
181+ meta : {
182+ ...createReindexState ( ) . meta ,
183+ indexName : 'foo' ,
184+ reindexName : 'reindexed-foo' ,
185+ aliases : [ ] ,
186+ } ,
187+ } ) ,
188+ lastCompletedStep : ReindexStep . aliasCreated ,
189+ status : ReindexStatus . completed ,
190+ reindexTaskPercComplete : 1 ,
191+ } }
192+ cancelReindex = { jest . fn ( ) }
193+ />
194+ ) ;
195+
196+ expect ( screen . getByTestId ( 'reindexChecklistTitle' ) ) . toHaveTextContent ( 'Reindexing process' ) ;
197+ expect ( screen . queryByTestId ( 'cancelReindexingDocumentsButton' ) ) . toBeNull ( ) ;
198+ } ) ;
100199} ) ;
0 commit comments