Skip to content

Commit 70beee2

Browse files
committed
test: buildProgress display
1 parent 7498e14 commit 70beee2

File tree

4 files changed

+121
-1
lines changed

4 files changed

+121
-1
lines changed

packages/compass-indexes/src/components/indexes/indexes.spec.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ describe('Indexes Component', function () {
201201
},
202202
],
203203
usageCount: 20,
204+
buildProgress: 0,
204205
},
205206
],
206207
inProgressIndexes: [
@@ -214,6 +215,7 @@ describe('Indexes Component', function () {
214215
},
215216
],
216217
status: 'inprogress',
218+
buildProgress: 0,
217219
},
218220
],
219221
error: undefined,
@@ -256,6 +258,7 @@ describe('Indexes Component', function () {
256258
},
257259
],
258260
usageCount: 20,
261+
buildProgress: 0,
259262
},
260263
],
261264
inProgressIndexes: [
@@ -270,6 +273,7 @@ describe('Indexes Component', function () {
270273
],
271274
status: 'failed',
272275
error: 'Error message',
276+
buildProgress: 0,
273277
},
274278
],
275279
error: undefined,

packages/compass-indexes/src/components/regular-indexes-table/in-progress-index-actions.spec.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ describe('IndexActions Component', function () {
2626
index={{
2727
name: 'artist_id_index',
2828
status: 'inprogress',
29+
buildProgress: 0,
2930
}}
3031
onDeleteFailedIndexClick={onDeleteSpy}
3132
/>
@@ -41,6 +42,7 @@ describe('IndexActions Component', function () {
4142
index={{
4243
name: 'artist_id_index',
4344
status: 'failed',
45+
buildProgress: 0,
4446
}}
4547
onDeleteFailedIndexClick={onDeleteSpy}
4648
/>

packages/compass-indexes/src/components/regular-indexes-table/regular-index-actions.spec.tsx

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ import { spy } from 'sinon';
1010
import type { SinonSpy } from 'sinon';
1111

1212
import 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

1428
describe('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(/Building\.\.\. \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(/Building\.\.\. \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
}}

packages/compass-indexes/src/components/regular-indexes-table/regular-indexes-table.spec.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const indexes: RegularIndex[] = [
3333
},
3434
],
3535
usageCount: 10,
36+
buildProgress: 0,
3637
},
3738
{
3839
ns: 'db.coll',
@@ -56,6 +57,7 @@ const indexes: RegularIndex[] = [
5657
},
5758
],
5859
usageCount: 15,
60+
buildProgress: 0,
5961
},
6062
{
6163
ns: 'db.coll',
@@ -78,6 +80,7 @@ const indexes: RegularIndex[] = [
7880
},
7981
],
8082
usageCount: 20,
83+
buildProgress: 0,
8184
},
8285
{
8386
ns: 'db.coll',
@@ -100,6 +103,7 @@ const indexes: RegularIndex[] = [
100103
},
101104
],
102105
usageCount: 25,
106+
buildProgress: 0,
103107
},
104108
];
105109

@@ -118,6 +122,7 @@ const inProgressIndexes: InProgressIndex[] = [
118122
},
119123
],
120124
status: 'inprogress',
125+
buildProgress: 0,
121126
},
122127
{
123128
id: 'in-progress-2',
@@ -130,6 +135,7 @@ const inProgressIndexes: InProgressIndex[] = [
130135
],
131136
status: 'inprogress',
132137
error: 'this is an error',
138+
buildProgress: 0,
133139
},
134140
];
135141

@@ -328,6 +334,7 @@ describe('RegularIndexesTable Component', function () {
328334
extra: {},
329335
size: 11111,
330336
relativeSize: 0,
337+
buildProgress: 0,
331338
},
332339
];
333340

0 commit comments

Comments
 (0)