@instructure/ui-tooltip 10.19.2-snapshot-2 → 10.19.2-snapshot-4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/package.json +15 -17
- package/tsconfig.build.json +0 -2
- package/tsconfig.build.tsbuildinfo +1 -1
- package/es/Tooltip/TooltipLocator.js +0 -46
- package/es/Tooltip/__new-tests__/Tooltip.test.js +0 -177
- package/es/Tooltip/locator.js +0 -28
- package/lib/Tooltip/TooltipLocator.js +0 -53
- package/lib/Tooltip/__new-tests__/Tooltip.test.js +0 -178
- package/lib/Tooltip/locator.js +0 -43
- package/src/Tooltip/TooltipLocator.ts +0 -43
- package/src/Tooltip/__new-tests__/Tooltip.test.tsx +0 -198
- package/src/Tooltip/locator.ts +0 -30
- package/types/Tooltip/TooltipLocator.d.ts +0 -329
- package/types/Tooltip/TooltipLocator.d.ts.map +0 -1
- package/types/Tooltip/__new-tests__/Tooltip.test.d.ts +0 -2
- package/types/Tooltip/__new-tests__/Tooltip.test.d.ts.map +0 -1
- package/types/Tooltip/locator.d.ts +0 -5
- package/types/Tooltip/locator.d.ts.map +0 -1
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The MIT License (MIT)
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import { locator } from '@instructure/ui-test-locator';
|
|
26
|
-
import { parseQueryArguments } from '@instructure/ui-test-queries';
|
|
27
|
-
// @ts-ignore: Cannot find module
|
|
28
|
-
// eslint-disable-next-line no-restricted-imports
|
|
29
|
-
import { PopoverLocator } from '@instructure/ui-popover/es/Popover/PopoverLocator';
|
|
30
|
-
import { Tooltip } from './index';
|
|
31
|
-
export const customMethods = {
|
|
32
|
-
findTrigger: (...args) => {
|
|
33
|
-
const _parseQueryArguments = parseQueryArguments(...args),
|
|
34
|
-
element = _parseQueryArguments.element,
|
|
35
|
-
options = _parseQueryArguments.options;
|
|
36
|
-
return PopoverLocator.findTrigger(element, '[aria-describedby]', options);
|
|
37
|
-
},
|
|
38
|
-
findContent: (...args) => {
|
|
39
|
-
const _parseQueryArguments2 = parseQueryArguments(...args),
|
|
40
|
-
element = _parseQueryArguments2.element,
|
|
41
|
-
options = _parseQueryArguments2.options;
|
|
42
|
-
return PopoverLocator.findContent(element, '[role="tooltip"]', options);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
// @ts-ignore: Property 'selector' does not exist type Tooltip
|
|
46
|
-
export const TooltipLocator = locator(Tooltip.selector, customMethods);
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
var _Tooltip, _Tooltip2, _Tooltip3, _a, _Tooltip4, _Tooltip5, _Tooltip6, _h;
|
|
2
|
-
/*
|
|
3
|
-
* The MIT License (MIT)
|
|
4
|
-
*
|
|
5
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
6
|
-
*
|
|
7
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
-
* in the Software without restriction, including without limitation the rights
|
|
10
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
-
* furnished to do so, subject to the following conditions:
|
|
13
|
-
*
|
|
14
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
-
* copies or substantial portions of the Software.
|
|
16
|
-
*
|
|
17
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
-
* SOFTWARE.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
import { render, screen, waitFor } from '@testing-library/react';
|
|
27
|
-
import { vi } from 'vitest';
|
|
28
|
-
import userEvent from '@testing-library/user-event';
|
|
29
|
-
import '@testing-library/jest-dom';
|
|
30
|
-
|
|
31
|
-
// eslint-disable-next-line no-restricted-imports
|
|
32
|
-
import { generateA11yTests } from '@instructure/ui-scripts/lib/test/generateA11yTests';
|
|
33
|
-
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
34
|
-
import { Tooltip } from '../index';
|
|
35
|
-
import TooltipExamples from '../__examples__/Tooltip.examples';
|
|
36
|
-
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
37
|
-
describe('<Tooltip />', () => {
|
|
38
|
-
let consoleErrorMock;
|
|
39
|
-
beforeEach(() => {
|
|
40
|
-
// Mocking console to prevent test output pollution and expect for messages
|
|
41
|
-
consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
42
|
-
});
|
|
43
|
-
afterEach(() => {
|
|
44
|
-
consoleErrorMock.mockRestore();
|
|
45
|
-
});
|
|
46
|
-
it('should render', async () => {
|
|
47
|
-
render(_Tooltip || (_Tooltip = _jsx(Tooltip, {
|
|
48
|
-
renderTip: "Hello",
|
|
49
|
-
children: _jsx("a", {
|
|
50
|
-
href: "example.html",
|
|
51
|
-
children: "Hover or focus me"
|
|
52
|
-
})
|
|
53
|
-
})));
|
|
54
|
-
const tip = screen.getByRole('tooltip');
|
|
55
|
-
expect(tip).toBeInTheDocument();
|
|
56
|
-
expect(tip).toHaveTextContent('Hello');
|
|
57
|
-
});
|
|
58
|
-
it('should render children', async () => {
|
|
59
|
-
render(_Tooltip2 || (_Tooltip2 = _jsx(Tooltip, {
|
|
60
|
-
renderTip: "Hello",
|
|
61
|
-
children: _jsx("a", {
|
|
62
|
-
"data-testid": "trigger",
|
|
63
|
-
href: "example.html",
|
|
64
|
-
children: "Hover or focus me"
|
|
65
|
-
})
|
|
66
|
-
})));
|
|
67
|
-
const tip = screen.getByRole('tooltip');
|
|
68
|
-
const trigger = screen.getByTestId('trigger');
|
|
69
|
-
expect(trigger).toBeInTheDocument();
|
|
70
|
-
expect(trigger).toHaveTextContent('Hover or focus me');
|
|
71
|
-
expect(trigger).toHaveAttribute('href', 'example.html');
|
|
72
|
-
expect(tip).toHaveTextContent('Hello');
|
|
73
|
-
});
|
|
74
|
-
it('should have an aria-describedby attribute', async () => {
|
|
75
|
-
render(_Tooltip3 || (_Tooltip3 = _jsx(Tooltip, {
|
|
76
|
-
renderTip: _jsx("h2", {
|
|
77
|
-
children: "Hello"
|
|
78
|
-
}),
|
|
79
|
-
children: _jsx("a", {
|
|
80
|
-
"data-testid": "trigger",
|
|
81
|
-
href: "example.html",
|
|
82
|
-
children: "Hover or focus me"
|
|
83
|
-
})
|
|
84
|
-
})));
|
|
85
|
-
const trigger = screen.getByTestId('trigger');
|
|
86
|
-
const tooltip = screen.getByRole('tooltip');
|
|
87
|
-
expect(trigger).toHaveAttribute('aria-describedby', tooltip.id);
|
|
88
|
-
});
|
|
89
|
-
it('should accept a function for renderTip', async () => {
|
|
90
|
-
render(_jsx(Tooltip, {
|
|
91
|
-
renderTip: () => 'Hello',
|
|
92
|
-
children: _a || (_a = _jsx("a", {
|
|
93
|
-
href: "example.html",
|
|
94
|
-
children: "Hover or focus me"
|
|
95
|
-
}))
|
|
96
|
-
}));
|
|
97
|
-
const content = screen.getByText('Hello');
|
|
98
|
-
expect(content).toBeInTheDocument();
|
|
99
|
-
});
|
|
100
|
-
describe('using as', () => {
|
|
101
|
-
it('should render children', async () => {
|
|
102
|
-
render(_Tooltip4 || (_Tooltip4 = _jsx(Tooltip, {
|
|
103
|
-
renderTip: _jsx("h2", {
|
|
104
|
-
children: "Hello"
|
|
105
|
-
}),
|
|
106
|
-
placement: "end",
|
|
107
|
-
as: "a",
|
|
108
|
-
href: "example.html",
|
|
109
|
-
children: "Hover or focus me"
|
|
110
|
-
})));
|
|
111
|
-
const tip = screen.getByRole('tooltip');
|
|
112
|
-
const trigger = screen.getByText('Hover or focus me');
|
|
113
|
-
expect(trigger).toBeInTheDocument();
|
|
114
|
-
expect(trigger).toHaveAttribute('href', 'example.html');
|
|
115
|
-
expect(trigger.tagName).toBe('A');
|
|
116
|
-
expect(tip).toBeInTheDocument();
|
|
117
|
-
expect(tip).toHaveTextContent('Hello');
|
|
118
|
-
});
|
|
119
|
-
it('should have an aria-describedby attribute', async () => {
|
|
120
|
-
render(_Tooltip5 || (_Tooltip5 = _jsx(Tooltip, {
|
|
121
|
-
renderTip: _jsx("h2", {
|
|
122
|
-
children: "Hello"
|
|
123
|
-
}),
|
|
124
|
-
placement: "end",
|
|
125
|
-
as: "a",
|
|
126
|
-
href: "example.html",
|
|
127
|
-
children: "Hover or focus me"
|
|
128
|
-
})));
|
|
129
|
-
const trigger = screen.getByText('Hover or focus me');
|
|
130
|
-
const tooltip = screen.getByRole('tooltip');
|
|
131
|
-
expect(trigger).toHaveAttribute('aria-describedby', tooltip.id);
|
|
132
|
-
});
|
|
133
|
-
it('should pass down the href attribute', async () => {
|
|
134
|
-
render(_Tooltip6 || (_Tooltip6 = _jsx(Tooltip, {
|
|
135
|
-
renderTip: _jsx("h2", {
|
|
136
|
-
children: "Hello"
|
|
137
|
-
}),
|
|
138
|
-
placement: "end",
|
|
139
|
-
as: "a",
|
|
140
|
-
href: "example.html",
|
|
141
|
-
children: "Hover or focus me"
|
|
142
|
-
})));
|
|
143
|
-
const link = screen.getByText('Hover or focus me');
|
|
144
|
-
expect(link).toHaveAttribute('href', 'example.html');
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
describe('using children', () => {
|
|
148
|
-
it('should call onClick of child', async () => {
|
|
149
|
-
const onClick = vi.fn();
|
|
150
|
-
render(_jsx(Tooltip, {
|
|
151
|
-
renderTip: _h || (_h = _jsx("h2", {
|
|
152
|
-
children: "Hello"
|
|
153
|
-
})),
|
|
154
|
-
children: _jsx("button", {
|
|
155
|
-
onClick: onClick,
|
|
156
|
-
children: "Hover or focus me"
|
|
157
|
-
})
|
|
158
|
-
}));
|
|
159
|
-
const button = screen.getByText('Hover or focus me');
|
|
160
|
-
await userEvent.click(button);
|
|
161
|
-
await waitFor(() => {
|
|
162
|
-
expect(onClick).toHaveBeenCalledTimes(1);
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
describe('with generated examples', () => {
|
|
167
|
-
const generatedComponents = generateA11yTests(Tooltip, TooltipExamples);
|
|
168
|
-
for (const component of generatedComponents) {
|
|
169
|
-
it(component.description, async () => {
|
|
170
|
-
const _render = render(component.content),
|
|
171
|
-
container = _render.container;
|
|
172
|
-
const axeCheck = await runAxeCheck(container);
|
|
173
|
-
expect(axeCheck).toBe(true);
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
});
|
package/es/Tooltip/locator.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The MIT License (MIT)
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import { TooltipLocator } from './TooltipLocator';
|
|
26
|
-
export { customMethods } from './TooltipLocator';
|
|
27
|
-
export { TooltipLocator };
|
|
28
|
-
export default TooltipLocator;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.customMethods = exports.TooltipLocator = void 0;
|
|
7
|
-
var _locator = require("@instructure/ui-test-locator/lib/utils/locator.js");
|
|
8
|
-
var _uiTestQueries = require("@instructure/ui-test-queries");
|
|
9
|
-
var _PopoverLocator = require("@instructure/ui-popover/lib/Popover/PopoverLocator");
|
|
10
|
-
var _index = require("./index");
|
|
11
|
-
/*
|
|
12
|
-
* The MIT License (MIT)
|
|
13
|
-
*
|
|
14
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
15
|
-
*
|
|
16
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
17
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
18
|
-
* in the Software without restriction, including without limitation the rights
|
|
19
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
20
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
21
|
-
* furnished to do so, subject to the following conditions:
|
|
22
|
-
*
|
|
23
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
24
|
-
* copies or substantial portions of the Software.
|
|
25
|
-
*
|
|
26
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
27
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
28
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
29
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
30
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
31
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
32
|
-
* SOFTWARE.
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
// @ts-ignore: Cannot find module
|
|
36
|
-
// eslint-disable-next-line no-restricted-imports
|
|
37
|
-
|
|
38
|
-
const customMethods = exports.customMethods = {
|
|
39
|
-
findTrigger: (...args) => {
|
|
40
|
-
const _parseQueryArguments = (0, _uiTestQueries.parseQueryArguments)(...args),
|
|
41
|
-
element = _parseQueryArguments.element,
|
|
42
|
-
options = _parseQueryArguments.options;
|
|
43
|
-
return _PopoverLocator.PopoverLocator.findTrigger(element, '[aria-describedby]', options);
|
|
44
|
-
},
|
|
45
|
-
findContent: (...args) => {
|
|
46
|
-
const _parseQueryArguments2 = (0, _uiTestQueries.parseQueryArguments)(...args),
|
|
47
|
-
element = _parseQueryArguments2.element,
|
|
48
|
-
options = _parseQueryArguments2.options;
|
|
49
|
-
return _PopoverLocator.PopoverLocator.findContent(element, '[role="tooltip"]', options);
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
// @ts-ignore: Property 'selector' does not exist type Tooltip
|
|
53
|
-
const TooltipLocator = exports.TooltipLocator = (0, _locator.locator)(_index.Tooltip.selector, customMethods);
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
var _react = require("@testing-library/react");
|
|
5
|
-
var _vitest = require("vitest");
|
|
6
|
-
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
7
|
-
require("@testing-library/jest-dom");
|
|
8
|
-
var _generateA11yTests = require("@instructure/ui-scripts/lib/test/generateA11yTests");
|
|
9
|
-
var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
|
|
10
|
-
var _index = require("../index");
|
|
11
|
-
var _Tooltip7 = _interopRequireDefault(require("../__examples__/Tooltip.examples"));
|
|
12
|
-
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
13
|
-
var _Tooltip, _Tooltip2, _Tooltip3, _a, _Tooltip4, _Tooltip5, _Tooltip6, _h;
|
|
14
|
-
/*
|
|
15
|
-
* The MIT License (MIT)
|
|
16
|
-
*
|
|
17
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
18
|
-
*
|
|
19
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
20
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
21
|
-
* in the Software without restriction, including without limitation the rights
|
|
22
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
23
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
24
|
-
* furnished to do so, subject to the following conditions:
|
|
25
|
-
*
|
|
26
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
27
|
-
* copies or substantial portions of the Software.
|
|
28
|
-
*
|
|
29
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
30
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
31
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
32
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
33
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
34
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
35
|
-
* SOFTWARE.
|
|
36
|
-
*/
|
|
37
|
-
// eslint-disable-next-line no-restricted-imports
|
|
38
|
-
describe('<Tooltip />', () => {
|
|
39
|
-
let consoleErrorMock;
|
|
40
|
-
beforeEach(() => {
|
|
41
|
-
// Mocking console to prevent test output pollution and expect for messages
|
|
42
|
-
consoleErrorMock = _vitest.vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
43
|
-
});
|
|
44
|
-
afterEach(() => {
|
|
45
|
-
consoleErrorMock.mockRestore();
|
|
46
|
-
});
|
|
47
|
-
it('should render', async () => {
|
|
48
|
-
(0, _react.render)(_Tooltip || (_Tooltip = (0, _jsxRuntime.jsx)(_index.Tooltip, {
|
|
49
|
-
renderTip: "Hello",
|
|
50
|
-
children: (0, _jsxRuntime.jsx)("a", {
|
|
51
|
-
href: "example.html",
|
|
52
|
-
children: "Hover or focus me"
|
|
53
|
-
})
|
|
54
|
-
})));
|
|
55
|
-
const tip = _react.screen.getByRole('tooltip');
|
|
56
|
-
expect(tip).toBeInTheDocument();
|
|
57
|
-
expect(tip).toHaveTextContent('Hello');
|
|
58
|
-
});
|
|
59
|
-
it('should render children', async () => {
|
|
60
|
-
(0, _react.render)(_Tooltip2 || (_Tooltip2 = (0, _jsxRuntime.jsx)(_index.Tooltip, {
|
|
61
|
-
renderTip: "Hello",
|
|
62
|
-
children: (0, _jsxRuntime.jsx)("a", {
|
|
63
|
-
"data-testid": "trigger",
|
|
64
|
-
href: "example.html",
|
|
65
|
-
children: "Hover or focus me"
|
|
66
|
-
})
|
|
67
|
-
})));
|
|
68
|
-
const tip = _react.screen.getByRole('tooltip');
|
|
69
|
-
const trigger = _react.screen.getByTestId('trigger');
|
|
70
|
-
expect(trigger).toBeInTheDocument();
|
|
71
|
-
expect(trigger).toHaveTextContent('Hover or focus me');
|
|
72
|
-
expect(trigger).toHaveAttribute('href', 'example.html');
|
|
73
|
-
expect(tip).toHaveTextContent('Hello');
|
|
74
|
-
});
|
|
75
|
-
it('should have an aria-describedby attribute', async () => {
|
|
76
|
-
(0, _react.render)(_Tooltip3 || (_Tooltip3 = (0, _jsxRuntime.jsx)(_index.Tooltip, {
|
|
77
|
-
renderTip: (0, _jsxRuntime.jsx)("h2", {
|
|
78
|
-
children: "Hello"
|
|
79
|
-
}),
|
|
80
|
-
children: (0, _jsxRuntime.jsx)("a", {
|
|
81
|
-
"data-testid": "trigger",
|
|
82
|
-
href: "example.html",
|
|
83
|
-
children: "Hover or focus me"
|
|
84
|
-
})
|
|
85
|
-
})));
|
|
86
|
-
const trigger = _react.screen.getByTestId('trigger');
|
|
87
|
-
const tooltip = _react.screen.getByRole('tooltip');
|
|
88
|
-
expect(trigger).toHaveAttribute('aria-describedby', tooltip.id);
|
|
89
|
-
});
|
|
90
|
-
it('should accept a function for renderTip', async () => {
|
|
91
|
-
(0, _react.render)((0, _jsxRuntime.jsx)(_index.Tooltip, {
|
|
92
|
-
renderTip: () => 'Hello',
|
|
93
|
-
children: _a || (_a = (0, _jsxRuntime.jsx)("a", {
|
|
94
|
-
href: "example.html",
|
|
95
|
-
children: "Hover or focus me"
|
|
96
|
-
}))
|
|
97
|
-
}));
|
|
98
|
-
const content = _react.screen.getByText('Hello');
|
|
99
|
-
expect(content).toBeInTheDocument();
|
|
100
|
-
});
|
|
101
|
-
describe('using as', () => {
|
|
102
|
-
it('should render children', async () => {
|
|
103
|
-
(0, _react.render)(_Tooltip4 || (_Tooltip4 = (0, _jsxRuntime.jsx)(_index.Tooltip, {
|
|
104
|
-
renderTip: (0, _jsxRuntime.jsx)("h2", {
|
|
105
|
-
children: "Hello"
|
|
106
|
-
}),
|
|
107
|
-
placement: "end",
|
|
108
|
-
as: "a",
|
|
109
|
-
href: "example.html",
|
|
110
|
-
children: "Hover or focus me"
|
|
111
|
-
})));
|
|
112
|
-
const tip = _react.screen.getByRole('tooltip');
|
|
113
|
-
const trigger = _react.screen.getByText('Hover or focus me');
|
|
114
|
-
expect(trigger).toBeInTheDocument();
|
|
115
|
-
expect(trigger).toHaveAttribute('href', 'example.html');
|
|
116
|
-
expect(trigger.tagName).toBe('A');
|
|
117
|
-
expect(tip).toBeInTheDocument();
|
|
118
|
-
expect(tip).toHaveTextContent('Hello');
|
|
119
|
-
});
|
|
120
|
-
it('should have an aria-describedby attribute', async () => {
|
|
121
|
-
(0, _react.render)(_Tooltip5 || (_Tooltip5 = (0, _jsxRuntime.jsx)(_index.Tooltip, {
|
|
122
|
-
renderTip: (0, _jsxRuntime.jsx)("h2", {
|
|
123
|
-
children: "Hello"
|
|
124
|
-
}),
|
|
125
|
-
placement: "end",
|
|
126
|
-
as: "a",
|
|
127
|
-
href: "example.html",
|
|
128
|
-
children: "Hover or focus me"
|
|
129
|
-
})));
|
|
130
|
-
const trigger = _react.screen.getByText('Hover or focus me');
|
|
131
|
-
const tooltip = _react.screen.getByRole('tooltip');
|
|
132
|
-
expect(trigger).toHaveAttribute('aria-describedby', tooltip.id);
|
|
133
|
-
});
|
|
134
|
-
it('should pass down the href attribute', async () => {
|
|
135
|
-
(0, _react.render)(_Tooltip6 || (_Tooltip6 = (0, _jsxRuntime.jsx)(_index.Tooltip, {
|
|
136
|
-
renderTip: (0, _jsxRuntime.jsx)("h2", {
|
|
137
|
-
children: "Hello"
|
|
138
|
-
}),
|
|
139
|
-
placement: "end",
|
|
140
|
-
as: "a",
|
|
141
|
-
href: "example.html",
|
|
142
|
-
children: "Hover or focus me"
|
|
143
|
-
})));
|
|
144
|
-
const link = _react.screen.getByText('Hover or focus me');
|
|
145
|
-
expect(link).toHaveAttribute('href', 'example.html');
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
describe('using children', () => {
|
|
149
|
-
it('should call onClick of child', async () => {
|
|
150
|
-
const onClick = _vitest.vi.fn();
|
|
151
|
-
(0, _react.render)((0, _jsxRuntime.jsx)(_index.Tooltip, {
|
|
152
|
-
renderTip: _h || (_h = (0, _jsxRuntime.jsx)("h2", {
|
|
153
|
-
children: "Hello"
|
|
154
|
-
})),
|
|
155
|
-
children: (0, _jsxRuntime.jsx)("button", {
|
|
156
|
-
onClick: onClick,
|
|
157
|
-
children: "Hover or focus me"
|
|
158
|
-
})
|
|
159
|
-
}));
|
|
160
|
-
const button = _react.screen.getByText('Hover or focus me');
|
|
161
|
-
await _userEvent.default.click(button);
|
|
162
|
-
await (0, _react.waitFor)(() => {
|
|
163
|
-
expect(onClick).toHaveBeenCalledTimes(1);
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
describe('with generated examples', () => {
|
|
168
|
-
const generatedComponents = (0, _generateA11yTests.generateA11yTests)(_index.Tooltip, _Tooltip7.default);
|
|
169
|
-
for (const component of generatedComponents) {
|
|
170
|
-
it(component.description, async () => {
|
|
171
|
-
const _render = (0, _react.render)(component.content),
|
|
172
|
-
container = _render.container;
|
|
173
|
-
const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
|
|
174
|
-
expect(axeCheck).toBe(true);
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
});
|
package/lib/Tooltip/locator.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "TooltipLocator", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _TooltipLocator.TooltipLocator;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "customMethods", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _TooltipLocator.customMethods;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
exports.default = void 0;
|
|
19
|
-
var _TooltipLocator = require("./TooltipLocator");
|
|
20
|
-
/*
|
|
21
|
-
* The MIT License (MIT)
|
|
22
|
-
*
|
|
23
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
24
|
-
*
|
|
25
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
26
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
27
|
-
* in the Software without restriction, including without limitation the rights
|
|
28
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
29
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
30
|
-
* furnished to do so, subject to the following conditions:
|
|
31
|
-
*
|
|
32
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
33
|
-
* copies or substantial portions of the Software.
|
|
34
|
-
*
|
|
35
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
36
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
37
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
38
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
39
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
40
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
41
|
-
* SOFTWARE.
|
|
42
|
-
*/
|
|
43
|
-
var _default = exports.default = _TooltipLocator.TooltipLocator;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The MIT License (MIT)
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import { locator } from '@instructure/ui-test-locator'
|
|
26
|
-
import { parseQueryArguments } from '@instructure/ui-test-queries'
|
|
27
|
-
// @ts-ignore: Cannot find module
|
|
28
|
-
// eslint-disable-next-line no-restricted-imports
|
|
29
|
-
import { PopoverLocator } from '@instructure/ui-popover/es/Popover/PopoverLocator'
|
|
30
|
-
import { Tooltip } from './index'
|
|
31
|
-
|
|
32
|
-
export const customMethods = {
|
|
33
|
-
findTrigger: (...args: any[]) => {
|
|
34
|
-
const { element, options } = parseQueryArguments(...args)
|
|
35
|
-
return PopoverLocator.findTrigger(element, '[aria-describedby]', options)
|
|
36
|
-
},
|
|
37
|
-
findContent: (...args: any[]) => {
|
|
38
|
-
const { element, options } = parseQueryArguments(...args)
|
|
39
|
-
return PopoverLocator.findContent(element, '[role="tooltip"]', options)
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
// @ts-ignore: Property 'selector' does not exist type Tooltip
|
|
43
|
-
export const TooltipLocator = locator(Tooltip.selector, customMethods)
|