Skip to content

Commit 7757215

Browse files
authored
fix(crud): make sure that the initial state of the store is set right away instead of through setState calls (#5351)
1 parent c1cb856 commit 7757215

File tree

3 files changed

+32
-261
lines changed

3 files changed

+32
-261
lines changed

packages/compass-crud/src/stores/crud-store.spec.ts

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -372,101 +372,6 @@ describe('store', function () {
372372
});
373373
});
374374

375-
describe('#onCollectionChanged', function () {
376-
let store: CrudStore;
377-
378-
beforeEach(function () {
379-
const plugin = activateDocumentsPlugin(
380-
{
381-
isSearchIndexesSupported: true,
382-
isReadonly: false,
383-
isTimeSeries: false,
384-
namespace: 'compass-crud.another',
385-
},
386-
{
387-
dataService,
388-
localAppRegistry,
389-
globalAppRegistry,
390-
instance,
391-
preferences,
392-
logger: createNoopLoggerAndTelemetry(),
393-
},
394-
createActivateHelpers()
395-
);
396-
store = plugin.store;
397-
deactivate = () => plugin.deactivate();
398-
});
399-
400-
context('when the collection is not readonly', function () {
401-
beforeEach(function () {
402-
store.state.table.path = ['test-path'];
403-
store.state.table.types = ['test-types'];
404-
store.state.table.doc = {};
405-
store.state.table.editParams = {};
406-
});
407-
408-
it('resets the state for the new editable collection', async function () {
409-
const listener = waitForState(store, (state) => {
410-
expect(state.table.path).to.deep.equal([]);
411-
expect(state.table.types).to.deep.equal([]);
412-
expect(state.table.doc).to.equal(null);
413-
expect(state.table.editParams).to.equal(null);
414-
expect(state.collection).to.equal('another');
415-
expect(state.isEditable).to.equal(true);
416-
expect(state.ns).to.equal('compass-crud.another');
417-
});
418-
419-
store.onCollectionChanged('compass-crud.another');
420-
421-
await listener;
422-
});
423-
});
424-
425-
context('when the collection is readonly', function () {
426-
beforeEach(function () {
427-
const plugin = activateDocumentsPlugin(
428-
{
429-
isSearchIndexesSupported: true,
430-
isReadonly: true,
431-
isTimeSeries: false,
432-
namespace: 'compass-crud.another',
433-
},
434-
{
435-
dataService,
436-
localAppRegistry,
437-
globalAppRegistry,
438-
instance,
439-
preferences,
440-
logger: createNoopLoggerAndTelemetry(),
441-
},
442-
createActivateHelpers()
443-
);
444-
store = plugin.store;
445-
deactivate = () => plugin.deactivate();
446-
store.state.table.path = ['test-path'];
447-
store.state.table.types = ['test-types'];
448-
store.state.table.doc = {};
449-
store.state.table.editParams = {};
450-
});
451-
452-
it('resets the state for the new readonly collection', async function () {
453-
const listener = waitForState(store, (state) => {
454-
expect(state.table.path).to.deep.equal([]);
455-
expect(state.table.types).to.deep.equal([]);
456-
expect(state.table.doc).to.equal(null);
457-
expect(state.table.editParams).to.equal(null);
458-
expect(state.collection).to.equal('another');
459-
expect(state.isEditable).to.equal(false);
460-
expect(state.ns).to.equal('compass-crud.another');
461-
});
462-
463-
store.onCollectionChanged('compass-crud.another');
464-
465-
await listener;
466-
});
467-
});
468-
});
469-
470375
describe('#onQueryChanged', function () {
471376
let store: CrudStore;
472377

0 commit comments

Comments
 (0)