@@ -10,6 +10,20 @@ import { spy } from 'sinon';
1010import type { SinonSpy } from 'sinon' ;
1111
1212import RegularIndexActions from './regular-index-actions' ;
13+ import type { RegularIndex } from '../../modules/regular-indexes' ;
14+
15+ const commonIndexProperties : RegularIndex = {
16+ name : 'artist_id_index' ,
17+ type : 'regular' ,
18+ cardinality : 'compound' ,
19+ properties : [ ] ,
20+ fields : [ ] ,
21+ extra : { } ,
22+ size : 0 ,
23+ relativeSize : 0 ,
24+ usageCount : 0 ,
25+ buildProgress : 0 ,
26+ } ;
1327
1428describe ( 'IndexActions Component' , function ( ) {
1529 let onDeleteSpy : SinonSpy ;
@@ -24,10 +38,100 @@ describe('IndexActions Component', function () {
2438 onUnhideIndexSpy = spy ( ) ;
2539 } ) ;
2640
41+ describe ( 'build progress display' , function ( ) {
42+ it ( 'does not display progress percentage when buildProgress is 0' , function ( ) {
43+ render (
44+ < RegularIndexActions
45+ index = { {
46+ ...commonIndexProperties ,
47+ name : 'test_index' ,
48+ buildProgress : 0 ,
49+ } }
50+ serverVersion = { '4.4.0' }
51+ onDeleteIndexClick = { onDeleteSpy }
52+ onHideIndexClick = { onHideIndexSpy }
53+ onUnhideIndexClick = { onUnhideIndexSpy }
54+ />
55+ ) ;
56+
57+ // Should not show building spinner or percentage
58+ expect ( ( ) => screen . getByTestId ( 'index-building-spinner' ) ) . to . throw ;
59+ expect ( ( ) => screen . getByText ( / B u i l d i n g \. \. \. \d + % / ) ) . to . throw ;
60+ } ) ;
61+
62+ it ( 'displays progress percentage when buildProgress is 50% (0.5)' , function ( ) {
63+ render (
64+ < RegularIndexActions
65+ index = { {
66+ ...commonIndexProperties ,
67+ name : 'test_index' ,
68+ buildProgress : 0.5 ,
69+ } }
70+ serverVersion = { '4.4.0' }
71+ onDeleteIndexClick = { onDeleteSpy }
72+ onHideIndexClick = { onHideIndexSpy }
73+ onUnhideIndexClick = { onUnhideIndexSpy }
74+ />
75+ ) ;
76+
77+ // Should show building spinner and percentage
78+ const buildingSpinner = screen . getByTestId ( 'index-building-spinner' ) ;
79+ expect ( buildingSpinner ) . to . exist ;
80+
81+ const progressText = screen . getByText ( 'Building... 50%' ) ;
82+ expect ( progressText ) . to . exist ;
83+ } ) ;
84+
85+ it ( 'does not display progress percentage when buildProgress is 100% (1.0)' , function ( ) {
86+ render (
87+ < RegularIndexActions
88+ index = { {
89+ ...commonIndexProperties ,
90+ name : 'test_index' ,
91+ buildProgress : 1.0 ,
92+ } }
93+ serverVersion = { '4.4.0' }
94+ onDeleteIndexClick = { onDeleteSpy }
95+ onHideIndexClick = { onHideIndexSpy }
96+ onUnhideIndexClick = { onUnhideIndexSpy }
97+ />
98+ ) ;
99+
100+ // Should not show building spinner or percentage when complete
101+ expect ( ( ) => screen . getByTestId ( 'index-building-spinner' ) ) . to . throw ;
102+ expect ( ( ) => screen . getByText ( / B u i l d i n g \. \. \. \d + % / ) ) . to . throw ;
103+ } ) ;
104+
105+ it ( 'displays cancel button when index is building' , function ( ) {
106+ render (
107+ < RegularIndexActions
108+ index = { {
109+ ...commonIndexProperties ,
110+ name : 'building_index' ,
111+ buildProgress : 0.3 ,
112+ } }
113+ serverVersion = { '4.4.0' }
114+ onDeleteIndexClick = { onDeleteSpy }
115+ onHideIndexClick = { onHideIndexSpy }
116+ onUnhideIndexClick = { onUnhideIndexSpy }
117+ />
118+ ) ;
119+
120+ const cancelButton = screen . getByLabelText ( 'Cancel Index building_index' ) ;
121+ expect ( cancelButton ) . to . exist ;
122+ expect ( onDeleteSpy . callCount ) . to . equal ( 0 ) ;
123+ userEvent . click ( cancelButton ) ;
124+ expect ( onDeleteSpy . callCount ) . to . equal ( 1 ) ;
125+ } ) ;
126+ } ) ;
127+
27128 it ( 'renders delete button for a regular index' , function ( ) {
28129 render (
29130 < RegularIndexActions
30- index = { { name : 'artist_id_index' } }
131+ index = { {
132+ ...commonIndexProperties ,
133+ name : 'artist_id_index' ,
134+ } }
31135 serverVersion = { '4.4.0' }
32136 onDeleteIndexClick = { onDeleteSpy }
33137 onHideIndexClick = { onHideIndexSpy }
@@ -52,6 +156,7 @@ describe('IndexActions Component', function () {
52156 render (
53157 < RegularIndexActions
54158 index = { {
159+ ...commonIndexProperties ,
55160 name : 'artist_id_index' ,
56161 } }
57162 serverVersion = { '4.4.0' }
@@ -75,6 +180,7 @@ describe('IndexActions Component', function () {
75180 render (
76181 < RegularIndexActions
77182 index = { {
183+ ...commonIndexProperties ,
78184 name : 'artist_id_index' ,
79185 extra : { hidden : true } ,
80186 } }
@@ -103,6 +209,7 @@ describe('IndexActions Component', function () {
103209 render (
104210 < RegularIndexActions
105211 index = { {
212+ ...commonIndexProperties ,
106213 name : 'artist_id_index' ,
107214 extra : { hidden : true } ,
108215 } }
0 commit comments