Skip to content

Commit f234f5d

Browse files
committed
Add unit tests for the store
1 parent b3eb304 commit f234f5d

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

packages/compass-workspaces/src/stores/workspaces.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ describe('tabs behavior', function () {
5959
collectionSubtabSelected,
6060
openFallbackWorkspace: openFallbackTab,
6161
getActiveTab,
62+
duplicateTab,
63+
closeAllOtherTabs,
6264
} = workspacesSlice;
6365

6466
describe('openWorkspace', function () {
@@ -503,6 +505,41 @@ describe('tabs behavior', function () {
503505
expect(getActiveTab(store.getState())).to.not.have.property('namespace');
504506
});
505507
});
508+
509+
describe('duplicateTab', function () {
510+
it('should duplicate tab by index', function () {
511+
const store = configureStore();
512+
openTabs(store);
513+
const tabCountBefore = store.getState().tabs.length;
514+
515+
store.dispatch(duplicateTab(1));
516+
const state = store.getState();
517+
expect(state)
518+
.to.have.property('tabs')
519+
.have.lengthOf(tabCountBefore + 1);
520+
const { id: existingTabId, ...existingTabState } = state.tabs[1];
521+
const { id: newTabId, ...newTabState } = state.tabs[2];
522+
// We expect their ids to differ
523+
expect(existingTabId).to.not.equal(newTabId);
524+
// but other properties should be the same
525+
expect(existingTabState).to.deep.equal(newTabState);
526+
});
527+
});
528+
529+
describe('closeAllOtherTabs', function () {
530+
it('should close all other tabs by index', function () {
531+
const store = configureStore();
532+
openTabs(store);
533+
const stateBefore = store.getState();
534+
expect(stateBefore.tabs.length).to.be.greaterThan(1);
535+
536+
store.dispatch(closeAllOtherTabs(1));
537+
const state = store.getState();
538+
expect(state.tabs.length).to.equal(1);
539+
expect(state).to.have.property('activeTabId', stateBefore.tabs[1].id);
540+
expect(state.tabs[0]).deep.equal(stateBefore.tabs[1]);
541+
});
542+
});
506543
});
507544

508545
describe('_bulkTabsClose', function () {

0 commit comments

Comments
 (0)