Skip to content

Commit 8fb6188

Browse files
committed
test(snapshot): add basic tooltip snapshots
1 parent f50c028 commit 8fb6188

File tree

6 files changed

+41
-12
lines changed

6 files changed

+41
-12
lines changed

src/action-tooltip.snap.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Components: Tooltip should render the component 1`] = `
4+
<body>
5+
<div>
6+
<div
7+
class="tooltip animation-null top"
8+
style="min-width: 200px; max-width: 200px; text-align: left;"
9+
>
10+
Hello World!
11+
12+
</div>
13+
</div>
14+
</body>
15+
`;

src/action-tooltip.svelte

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
box-shadow: var(--tooltip-box-shadow);
104104
border-radius: var(--tooltip-border-radius);
105105
color: var(--tooltip-color);
106+
opacity: 0;
106107
font-family: var(--tooltip-font-family);
107108
font-size: var(--tooltip-font-size);
108109
font-style: normal;
@@ -111,11 +112,14 @@
111112
padding: var(--tooltip-padding);
112113
position: absolute;
113114
text-align: left;
115+
visibility: hidden;
114116
white-space: nowrap;
115117
z-index: var(--tooltip-z-index);
116118
}
117119
118120
.tooltip.show {
121+
opacity: 1;
122+
visibility: visible;
119123
white-space: normal;
120124
}
121125

src/action-tooltip.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { render } from '@testing-library/svelte';
2+
import Tooltip from './action-tooltip.svelte';
3+
4+
describe('Components: Tooltip', () => {
5+
let TestHarness;
6+
7+
beforeEach(() => {
8+
TestHarness = () =>
9+
render(Tooltip, {
10+
content: 'Hello World!'
11+
});
12+
});
13+
14+
it('should render the component', () => {
15+
const { container } = TestHarness();
16+
expect(container).toMatchSnapshot();
17+
});
18+
});

src/helpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const getMinWidth = (element, maxWidth) => {
1515
const elementPadding = elementPaddingLeft + elementPaddingRight;
1616
const contentWidth = elementWidth - elementPadding;
1717

18-
return Math.round(Math.min(maxWidth, contentWidth));
18+
return Math.round(Math.min(maxWidth, contentWidth || maxWidth));
1919
};
2020

2121
export const isInViewport = (element) => {

src/tooltip.snap.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ exports[`Components: Tooltip should render the component 1`] = `
88
>
99
1010
<div
11-
class="tooltip animation- top"
12-
style="min-width: NaNpx; max-width: 200px; text-align: left;"
11+
class="tooltip animation-null top"
12+
style="min-width: 200px; max-width: 200px; text-align: left;"
1313
>
1414
Hello World!
1515

src/tooltip.test.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,7 @@ describe('Components: Tooltip', () => {
77
beforeEach(() => {
88
TestHarness = () =>
99
render(Tooltip, {
10-
content: 'Hello World!',
11-
align: 'left',
12-
position: 'top',
13-
maxWidth: 200,
14-
style: null,
15-
theme: '',
16-
animation: '',
17-
arrow: true,
18-
autoPosition: false
10+
content: 'Hello World!'
1911
});
2012
});
2113

0 commit comments

Comments
 (0)