Skip to content

Commit a35a632

Browse files
committed
add test
1 parent 963e98e commit a35a632

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

packages/compass-global-writes/src/store/index.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
TEST_POLLING_INTERVAL,
88
unmanageNamespace,
99
cancelSharding,
10+
setPluginTitleVisibility,
1011
} from './reducer';
1112
import sinon from 'sinon';
1213
import type {
@@ -278,6 +279,33 @@ describe('GlobalWritesStore Store', function () {
278279
expect(confirmationStub).to.have.been.called;
279280
});
280281

282+
it('sharding -> pause sharding -> resume sharding -> valid shard key', async function () {
283+
let mockShardKey = false;
284+
confirmationStub.resolves(true);
285+
// initial state === sharding
286+
const store = createStore({
287+
isNamespaceManaged: () => true,
288+
hasShardKey: Sinon.fake(() => mockShardKey),
289+
});
290+
await waitFor(() => {
291+
expect(store.getState().status).to.equal('SHARDING');
292+
});
293+
294+
// user leaves the workspace
295+
store.dispatch(setPluginTitleVisibility(false));
296+
mockShardKey = true;
297+
await wait(TEST_POLLING_INTERVAL * 2);
298+
expect(store.getState().pollingTimeout).to.be.undefined;
299+
expect(store.getState().status).to.equal('SHARDING'); // no update
300+
301+
// user comes back
302+
store.dispatch(setPluginTitleVisibility(true));
303+
await wait(TEST_POLLING_INTERVAL);
304+
await waitFor(() => {
305+
expect(store.getState().status).to.equal('SHARD_KEY_CORRECT'); // now there is an update
306+
});
307+
});
308+
281309
it('valid shard key', async function () {
282310
const store = createStore({
283311
isNamespaceManaged: () => true,

0 commit comments

Comments
 (0)