Skip to content

Commit 84a6d70

Browse files
committed
PluginTitle tests
1 parent 7cc3dcf commit 84a6d70

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import React from 'react';
2+
import { expect } from 'chai';
3+
import { PluginTitle } from './plugin-title';
4+
import { render, screen } from '@mongodb-js/testing-library-compass';
5+
import Sinon from 'sinon';
6+
7+
describe('PluginTitle', function () {
8+
let onVisibilityChanged: Sinon.SinonSpy;
9+
10+
beforeEach(function () {
11+
onVisibilityChanged = Sinon.spy();
12+
});
13+
14+
afterEach(function () {
15+
onVisibilityChanged.resetHistory();
16+
});
17+
18+
it('Renders a warning', function () {
19+
render(
20+
<PluginTitle
21+
onVisibilityChanged={onVisibilityChanged}
22+
showWarning={true}
23+
/>
24+
);
25+
expect(screen.getByLabelText('warning')).to.be.visible;
26+
});
27+
28+
it('Does not render a warning', function () {
29+
render(
30+
<PluginTitle
31+
onVisibilityChanged={onVisibilityChanged}
32+
showWarning={false}
33+
/>
34+
);
35+
expect(screen.queryByLabelText('warning')).not.to.exist;
36+
});
37+
38+
it('Calls the onVisibilityChanged callback when dismounted', function () {
39+
const mount = render(
40+
<PluginTitle
41+
onVisibilityChanged={onVisibilityChanged}
42+
showWarning={false}
43+
/>
44+
);
45+
46+
expect(onVisibilityChanged).to.have.been.calledOnceWith(true);
47+
48+
mount.unmount();
49+
50+
expect(onVisibilityChanged).to.have.been.calledTwice;
51+
expect(onVisibilityChanged.getCalls()[1].args[0]).to.equal(false);
52+
});
53+
});

packages/compass-global-writes/src/plugin-title.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const iconStylesDark = css({
3434
color: palette.yellow.base,
3535
});
3636

37-
const PluginTitle = ({
37+
export const PluginTitle = ({
3838
showWarning,
3939
onVisibilityChanged,
4040
}: {
@@ -66,6 +66,7 @@ const PluginTitle = ({
6666
>
6767
<Icon
6868
glyph="ImportantWithCircle"
69+
aria-label="warning"
6970
className={cx(
7071
warningIconStyles,
7172
iconStylesLight,

0 commit comments

Comments
 (0)