Skip to content

Commit c0ad255

Browse files
committed
Add unit tests to components package
1 parent 467f0a2 commit c0ad255

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

packages/compass-components/src/components/workspace-tabs/tab.spec.tsx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ import { Tab } from './tab';
1313
describe('Tab', function () {
1414
let onCloseSpy: sinon.SinonSpy;
1515
let onSelectSpy: sinon.SinonSpy;
16+
let onDuplicateSpy: sinon.SinonSpy;
17+
let onCloseAllOthersSpy: sinon.SinonSpy;
1618

1719
beforeEach(function () {
1820
onCloseSpy = sinon.spy();
1921
onSelectSpy = sinon.spy();
22+
onDuplicateSpy = sinon.spy();
23+
onCloseAllOthersSpy = sinon.spy();
2024
});
2125

2226
afterEach(cleanup);
@@ -28,6 +32,8 @@ describe('Tab', function () {
2832
type="Databases"
2933
onClose={onCloseSpy}
3034
onSelect={onSelectSpy}
35+
onDuplicate={onDuplicateSpy}
36+
onCloseAllOthers={onCloseAllOthersSpy}
3137
title="docs"
3238
isSelected
3339
isDragging={false}
@@ -73,6 +79,8 @@ describe('Tab', function () {
7379
type="Databases"
7480
onClose={onCloseSpy}
7581
onSelect={onSelectSpy}
82+
onDuplicate={onDuplicateSpy}
83+
onCloseAllOthers={onCloseAllOthersSpy}
7684
title="docs"
7785
isSelected={false}
7886
isDragging={false}
@@ -98,4 +106,48 @@ describe('Tab', function () {
98106
).to.not.equal('none');
99107
});
100108
});
109+
110+
describe('when right-clicking', function () {
111+
beforeEach(function () {
112+
render(
113+
<Tab
114+
type="Databases"
115+
onClose={onCloseSpy}
116+
onSelect={onSelectSpy}
117+
onDuplicate={onDuplicateSpy}
118+
onCloseAllOthers={onCloseAllOthersSpy}
119+
title="docs"
120+
isSelected={false}
121+
isDragging={false}
122+
tabContentId="1"
123+
tooltip={[['Connection', 'ABC']]}
124+
iconGlyph="Folder"
125+
/>
126+
);
127+
});
128+
129+
describe('clicking menu items', function () {
130+
it('should propagate clicks on "Duplicate"', async function () {
131+
const tab = await screen.findByText('docs');
132+
userEvent.click(tab, { button: 2 });
133+
expect(screen.getByTestId('context-menu')).to.be.visible;
134+
135+
const menuItem = await screen.findByText('Duplicate');
136+
menuItem.click();
137+
expect(onDuplicateSpy.callCount).to.equal(1);
138+
expect(onCloseAllOthersSpy.callCount).to.equal(0);
139+
});
140+
141+
it('should propagate clicks on "Close all other tabs"', async function () {
142+
const tab = await screen.findByText('docs');
143+
userEvent.click(tab, { button: 2 });
144+
expect(screen.getByTestId('context-menu')).to.be.visible;
145+
146+
const menuItem = await screen.findByText('Close all other tabs');
147+
menuItem.click();
148+
expect(onDuplicateSpy.callCount).to.equal(0);
149+
expect(onCloseAllOthersSpy.callCount).to.equal(1);
150+
});
151+
});
152+
});
101153
});

packages/compass-components/src/components/workspace-tabs/workspace-tabs.spec.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ describe('WorkspaceTabs', function () {
3636
let onSelectNextSpy: sinon.SinonSpy;
3737
let onSelectPrevSpy: sinon.SinonSpy;
3838
let onMoveTabSpy: sinon.SinonSpy;
39+
let onDuplicateSpy: sinon.SinonSpy;
40+
let onCloseAllOthersSpy: sinon.SinonSpy;
3941

4042
beforeEach(function () {
4143
onCreateNewTabSpy = sinon.spy();
@@ -44,6 +46,8 @@ describe('WorkspaceTabs', function () {
4446
onSelectNextSpy = sinon.spy();
4547
onSelectPrevSpy = sinon.spy();
4648
onMoveTabSpy = sinon.spy();
49+
onDuplicateSpy = sinon.spy();
50+
onCloseAllOthersSpy = sinon.spy();
4751
});
4852

4953
afterEach(cleanup);
@@ -59,6 +63,8 @@ describe('WorkspaceTabs', function () {
5963
onSelectNextTab={onSelectNextSpy}
6064
onSelectPrevTab={onSelectPrevSpy}
6165
onMoveTab={onMoveTabSpy}
66+
onDuplicateTab={onDuplicateSpy}
67+
onCloseAllOtherTabs={onCloseAllOthersSpy}
6268
tabs={[]}
6369
selectedTabIndex={0}
6470
/>
@@ -87,7 +93,11 @@ describe('WorkspaceTabs', function () {
8793
onCreateNewTab={onCreateNewTabSpy}
8894
onCloseTab={onCloseTabSpy}
8995
onSelectTab={onSelectSpy}
96+
onSelectNextTab={onSelectNextSpy}
97+
onSelectPrevTab={onSelectPrevSpy}
9098
onMoveTab={onMoveTabSpy}
99+
onDuplicateTab={onDuplicateSpy}
100+
onCloseAllOtherTabs={onCloseAllOthersSpy}
91101
tabs={[1, 2, 3].map((tabId) => mockTab(tabId))}
92102
selectedTabIndex={1}
93103
/>
@@ -156,7 +166,11 @@ describe('WorkspaceTabs', function () {
156166
onCreateNewTab={onCreateNewTabSpy}
157167
onCloseTab={onCloseTabSpy}
158168
onSelectTab={onSelectSpy}
169+
onSelectNextTab={onSelectNextSpy}
170+
onSelectPrevTab={onSelectPrevSpy}
159171
onMoveTab={onMoveTabSpy}
172+
onDuplicateTab={onDuplicateSpy}
173+
onCloseAllOtherTabs={onCloseAllOthersSpy}
160174
tabs={[1, 2].map((tabId) => mockTab(tabId))}
161175
selectedTabIndex={0}
162176
/>
@@ -182,7 +196,11 @@ describe('WorkspaceTabs', function () {
182196
onCreateNewTab={onCreateNewTabSpy}
183197
onCloseTab={onCloseTabSpy}
184198
onSelectTab={onSelectSpy}
199+
onSelectNextTab={onSelectNextSpy}
200+
onSelectPrevTab={onSelectPrevSpy}
185201
onMoveTab={onMoveTabSpy}
202+
onDuplicateTab={onDuplicateSpy}
203+
onCloseAllOtherTabs={onCloseAllOthersSpy}
186204
tabs={[1, 2].map((tabId) => mockTab(tabId))}
187205
selectedTabIndex={1}
188206
/>

0 commit comments

Comments
 (0)