@instructure/ui-img 10.6.0 → 10.6.1-snapshot-1
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 +8 -0
- package/es/Img/__new-tests__/Img.test.js +165 -0
- package/lib/Img/__new-tests__/Img.test.js +169 -0
- package/package.json +15 -11
- package/src/Img/__new-tests__/Img.test.tsx +155 -0
- package/tsconfig.build.json +2 -2
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Img/__new-tests__/Img.test.d.ts +2 -0
- package/types/Img/__new-tests__/Img.test.d.ts.map +1 -0
- package/es/Img/ImgLocator.js +0 -28
- package/es/Img/locator.js +0 -26
- package/lib/Img/ImgLocator.js +0 -34
- package/lib/Img/locator.js +0 -37
- package/src/Img/ImgLocator.ts +0 -29
- package/src/Img/locator.ts +0 -27
- package/types/Img/ImgLocator.d.ts +0 -310
- package/types/Img/ImgLocator.d.ts.map +0 -1
- package/types/Img/locator.d.ts +0 -4
- package/types/Img/locator.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [10.6.1-snapshot-1](https://github.com/instructure/instructure-ui/compare/v10.6.0...v10.6.1-snapshot-1) (2024-11-19)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @instructure/ui-img
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# [10.6.0](https://github.com/instructure/instructure-ui/compare/v10.5.0...v10.6.0) (2024-11-18)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @instructure/ui-img
|
|
@@ -0,0 +1,165 @@
|
|
|
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
|
+
import React from 'react';
|
|
25
|
+
import { render } from '@testing-library/react';
|
|
26
|
+
import { vi } from 'vitest';
|
|
27
|
+
import '@testing-library/jest-dom';
|
|
28
|
+
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
29
|
+
import { Img } from '../index';
|
|
30
|
+
describe('<Img />', () => {
|
|
31
|
+
var _Img, _Img2, _Img3, _Img4, _Img5, _Img6, _Img7;
|
|
32
|
+
const image = 'data:image/gif;base64,R0lGODlhFAAUAJEAAP/9/fYQEPytrflWViH5BAAAAAAALAAAAAAUABQAQAJKhI+pGe09lnhBnEETfodatVHNh1BR+ZzH9LAOCYrVYpiAfWWJOxrC/5MASbyZT4d6AUIBlUYGoR1FsAXUuTN5YhxAEYbrpKRkQwEAOw==';
|
|
33
|
+
let consoleWarningMock;
|
|
34
|
+
let consoleErrorMock;
|
|
35
|
+
beforeEach(() => {
|
|
36
|
+
// Mocking console to prevent test output pollution and expect for messages
|
|
37
|
+
consoleWarningMock = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
38
|
+
consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
39
|
+
});
|
|
40
|
+
afterEach(() => {
|
|
41
|
+
consoleWarningMock.mockRestore();
|
|
42
|
+
consoleErrorMock.mockRestore();
|
|
43
|
+
});
|
|
44
|
+
describe('for a11y', () => {
|
|
45
|
+
it('should meet a11y standards', async () => {
|
|
46
|
+
const _render = render(_Img || (_Img = /*#__PURE__*/React.createElement(Img, {
|
|
47
|
+
src: image
|
|
48
|
+
}))),
|
|
49
|
+
container = _render.container;
|
|
50
|
+
const axeCheck = await runAxeCheck(container);
|
|
51
|
+
expect(axeCheck).toBe(true);
|
|
52
|
+
});
|
|
53
|
+
it('should render an empty alt attribute by default', async () => {
|
|
54
|
+
const _render2 = render(_Img2 || (_Img2 = /*#__PURE__*/React.createElement(Img, {
|
|
55
|
+
src: image
|
|
56
|
+
}))),
|
|
57
|
+
container = _render2.container;
|
|
58
|
+
const img = container.querySelector('img');
|
|
59
|
+
expect(img).toHaveAttribute('alt', '');
|
|
60
|
+
});
|
|
61
|
+
it('should render the provided alt attribute', async () => {
|
|
62
|
+
const altValue = 'Foo';
|
|
63
|
+
const _render3 = render(/*#__PURE__*/React.createElement(Img, {
|
|
64
|
+
src: image,
|
|
65
|
+
alt: altValue
|
|
66
|
+
})),
|
|
67
|
+
container = _render3.container;
|
|
68
|
+
const img = container.querySelector('img');
|
|
69
|
+
expect(img).toHaveAttribute('alt', altValue);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
it('should render an overlay color', async () => {
|
|
73
|
+
const _render4 = render(/*#__PURE__*/React.createElement(Img, {
|
|
74
|
+
src: image,
|
|
75
|
+
overlay: {
|
|
76
|
+
color: '#ff0000',
|
|
77
|
+
opacity: 7
|
|
78
|
+
}
|
|
79
|
+
})),
|
|
80
|
+
container = _render4.container;
|
|
81
|
+
const overlay = container.querySelector('[class*="-img__overlay"]');
|
|
82
|
+
expect(overlay).toBeInTheDocument();
|
|
83
|
+
});
|
|
84
|
+
it('should render a blur filter', async () => {
|
|
85
|
+
const _render5 = render(_Img3 || (_Img3 = /*#__PURE__*/React.createElement(Img, {
|
|
86
|
+
src: image,
|
|
87
|
+
withBlur: true
|
|
88
|
+
}))),
|
|
89
|
+
container = _render5.container;
|
|
90
|
+
const img = container.querySelector('img');
|
|
91
|
+
const style = getComputedStyle(img);
|
|
92
|
+
expect(style.filter).toContain('blur');
|
|
93
|
+
});
|
|
94
|
+
it('should render a grayscale filter', async () => {
|
|
95
|
+
const _render6 = render(_Img4 || (_Img4 = /*#__PURE__*/React.createElement(Img, {
|
|
96
|
+
src: image,
|
|
97
|
+
withGrayscale: true
|
|
98
|
+
}))),
|
|
99
|
+
container = _render6.container;
|
|
100
|
+
const img = container.querySelector('img');
|
|
101
|
+
const style = getComputedStyle(img);
|
|
102
|
+
expect(style.filter).toContain('grayscale');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// // If component renders as simple image
|
|
106
|
+
it('should display block-level when display="block"', async () => {
|
|
107
|
+
const _render7 = render(_Img5 || (_Img5 = /*#__PURE__*/React.createElement(Img, {
|
|
108
|
+
src: image,
|
|
109
|
+
display: "block"
|
|
110
|
+
}))),
|
|
111
|
+
container = _render7.container;
|
|
112
|
+
const img = container.querySelector('img');
|
|
113
|
+
const style = getComputedStyle(img);
|
|
114
|
+
expect(style.display).toBe('block');
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// // If component has an overlay and renders as image inside containing element
|
|
118
|
+
it('should display block-level with overlay when display="block"', async () => {
|
|
119
|
+
const _render8 = render(/*#__PURE__*/React.createElement(Img, {
|
|
120
|
+
src: image,
|
|
121
|
+
display: "block",
|
|
122
|
+
overlay: {
|
|
123
|
+
color: 'tomato',
|
|
124
|
+
opacity: 7
|
|
125
|
+
}
|
|
126
|
+
})),
|
|
127
|
+
container = _render8.container;
|
|
128
|
+
const img = container.querySelector('img');
|
|
129
|
+
const imgContainer = container.querySelector('[class*="-img__container"]');
|
|
130
|
+
const imgStyle = getComputedStyle(img);
|
|
131
|
+
const imgContainerStyle = getComputedStyle(imgContainer);
|
|
132
|
+
expect(imgStyle.display).toBe('block');
|
|
133
|
+
expect(imgContainerStyle.display).toBe('block');
|
|
134
|
+
});
|
|
135
|
+
it('should apply CSS object-fit: cover when constrain="cover"', async () => {
|
|
136
|
+
const _render9 = render(/*#__PURE__*/React.createElement("div", {
|
|
137
|
+
style: {
|
|
138
|
+
width: 16,
|
|
139
|
+
height: 16
|
|
140
|
+
}
|
|
141
|
+
}, _Img6 || (_Img6 = /*#__PURE__*/React.createElement(Img, {
|
|
142
|
+
src: image,
|
|
143
|
+
constrain: "cover"
|
|
144
|
+
})))),
|
|
145
|
+
container = _render9.container;
|
|
146
|
+
const img = container.querySelector('img');
|
|
147
|
+
const imgStyle = getComputedStyle(img);
|
|
148
|
+
expect(imgStyle.objectFit).toBe('cover');
|
|
149
|
+
});
|
|
150
|
+
it('should apply CSS object-fit: contain when constrain="contain"', async () => {
|
|
151
|
+
const _render10 = render(/*#__PURE__*/React.createElement("div", {
|
|
152
|
+
style: {
|
|
153
|
+
width: 16,
|
|
154
|
+
height: 16
|
|
155
|
+
}
|
|
156
|
+
}, _Img7 || (_Img7 = /*#__PURE__*/React.createElement(Img, {
|
|
157
|
+
src: image,
|
|
158
|
+
constrain: "contain"
|
|
159
|
+
})))),
|
|
160
|
+
container = _render10.container;
|
|
161
|
+
const img = container.querySelector('img');
|
|
162
|
+
const imgStyle = getComputedStyle(img);
|
|
163
|
+
expect(imgStyle.objectFit).toBe('contain');
|
|
164
|
+
});
|
|
165
|
+
});
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
var _react = _interopRequireDefault(require("react"));
|
|
5
|
+
var _react2 = require("@testing-library/react");
|
|
6
|
+
var _vitest = require("vitest");
|
|
7
|
+
require("@testing-library/jest-dom");
|
|
8
|
+
var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
|
|
9
|
+
var _index = require("../index");
|
|
10
|
+
/*
|
|
11
|
+
* The MIT License (MIT)
|
|
12
|
+
*
|
|
13
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
14
|
+
*
|
|
15
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
16
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
17
|
+
* in the Software without restriction, including without limitation the rights
|
|
18
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
19
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
20
|
+
* furnished to do so, subject to the following conditions:
|
|
21
|
+
*
|
|
22
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
23
|
+
* copies or substantial portions of the Software.
|
|
24
|
+
*
|
|
25
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
26
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
27
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
28
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
29
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
30
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
31
|
+
* SOFTWARE.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
describe('<Img />', () => {
|
|
35
|
+
var _Img, _Img2, _Img3, _Img4, _Img5, _Img6, _Img7;
|
|
36
|
+
const image = 'data:image/gif;base64,R0lGODlhFAAUAJEAAP/9/fYQEPytrflWViH5BAAAAAAALAAAAAAUABQAQAJKhI+pGe09lnhBnEETfodatVHNh1BR+ZzH9LAOCYrVYpiAfWWJOxrC/5MASbyZT4d6AUIBlUYGoR1FsAXUuTN5YhxAEYbrpKRkQwEAOw==';
|
|
37
|
+
let consoleWarningMock;
|
|
38
|
+
let consoleErrorMock;
|
|
39
|
+
beforeEach(() => {
|
|
40
|
+
// Mocking console to prevent test output pollution and expect for messages
|
|
41
|
+
consoleWarningMock = _vitest.vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
42
|
+
consoleErrorMock = _vitest.vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
43
|
+
});
|
|
44
|
+
afterEach(() => {
|
|
45
|
+
consoleWarningMock.mockRestore();
|
|
46
|
+
consoleErrorMock.mockRestore();
|
|
47
|
+
});
|
|
48
|
+
describe('for a11y', () => {
|
|
49
|
+
it('should meet a11y standards', async () => {
|
|
50
|
+
const _render = (0, _react2.render)(_Img || (_Img = /*#__PURE__*/_react.default.createElement(_index.Img, {
|
|
51
|
+
src: image
|
|
52
|
+
}))),
|
|
53
|
+
container = _render.container;
|
|
54
|
+
const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
|
|
55
|
+
expect(axeCheck).toBe(true);
|
|
56
|
+
});
|
|
57
|
+
it('should render an empty alt attribute by default', async () => {
|
|
58
|
+
const _render2 = (0, _react2.render)(_Img2 || (_Img2 = /*#__PURE__*/_react.default.createElement(_index.Img, {
|
|
59
|
+
src: image
|
|
60
|
+
}))),
|
|
61
|
+
container = _render2.container;
|
|
62
|
+
const img = container.querySelector('img');
|
|
63
|
+
expect(img).toHaveAttribute('alt', '');
|
|
64
|
+
});
|
|
65
|
+
it('should render the provided alt attribute', async () => {
|
|
66
|
+
const altValue = 'Foo';
|
|
67
|
+
const _render3 = (0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.Img, {
|
|
68
|
+
src: image,
|
|
69
|
+
alt: altValue
|
|
70
|
+
})),
|
|
71
|
+
container = _render3.container;
|
|
72
|
+
const img = container.querySelector('img');
|
|
73
|
+
expect(img).toHaveAttribute('alt', altValue);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
it('should render an overlay color', async () => {
|
|
77
|
+
const _render4 = (0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.Img, {
|
|
78
|
+
src: image,
|
|
79
|
+
overlay: {
|
|
80
|
+
color: '#ff0000',
|
|
81
|
+
opacity: 7
|
|
82
|
+
}
|
|
83
|
+
})),
|
|
84
|
+
container = _render4.container;
|
|
85
|
+
const overlay = container.querySelector('[class*="-img__overlay"]');
|
|
86
|
+
expect(overlay).toBeInTheDocument();
|
|
87
|
+
});
|
|
88
|
+
it('should render a blur filter', async () => {
|
|
89
|
+
const _render5 = (0, _react2.render)(_Img3 || (_Img3 = /*#__PURE__*/_react.default.createElement(_index.Img, {
|
|
90
|
+
src: image,
|
|
91
|
+
withBlur: true
|
|
92
|
+
}))),
|
|
93
|
+
container = _render5.container;
|
|
94
|
+
const img = container.querySelector('img');
|
|
95
|
+
const style = getComputedStyle(img);
|
|
96
|
+
expect(style.filter).toContain('blur');
|
|
97
|
+
});
|
|
98
|
+
it('should render a grayscale filter', async () => {
|
|
99
|
+
const _render6 = (0, _react2.render)(_Img4 || (_Img4 = /*#__PURE__*/_react.default.createElement(_index.Img, {
|
|
100
|
+
src: image,
|
|
101
|
+
withGrayscale: true
|
|
102
|
+
}))),
|
|
103
|
+
container = _render6.container;
|
|
104
|
+
const img = container.querySelector('img');
|
|
105
|
+
const style = getComputedStyle(img);
|
|
106
|
+
expect(style.filter).toContain('grayscale');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// // If component renders as simple image
|
|
110
|
+
it('should display block-level when display="block"', async () => {
|
|
111
|
+
const _render7 = (0, _react2.render)(_Img5 || (_Img5 = /*#__PURE__*/_react.default.createElement(_index.Img, {
|
|
112
|
+
src: image,
|
|
113
|
+
display: "block"
|
|
114
|
+
}))),
|
|
115
|
+
container = _render7.container;
|
|
116
|
+
const img = container.querySelector('img');
|
|
117
|
+
const style = getComputedStyle(img);
|
|
118
|
+
expect(style.display).toBe('block');
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// // If component has an overlay and renders as image inside containing element
|
|
122
|
+
it('should display block-level with overlay when display="block"', async () => {
|
|
123
|
+
const _render8 = (0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.Img, {
|
|
124
|
+
src: image,
|
|
125
|
+
display: "block",
|
|
126
|
+
overlay: {
|
|
127
|
+
color: 'tomato',
|
|
128
|
+
opacity: 7
|
|
129
|
+
}
|
|
130
|
+
})),
|
|
131
|
+
container = _render8.container;
|
|
132
|
+
const img = container.querySelector('img');
|
|
133
|
+
const imgContainer = container.querySelector('[class*="-img__container"]');
|
|
134
|
+
const imgStyle = getComputedStyle(img);
|
|
135
|
+
const imgContainerStyle = getComputedStyle(imgContainer);
|
|
136
|
+
expect(imgStyle.display).toBe('block');
|
|
137
|
+
expect(imgContainerStyle.display).toBe('block');
|
|
138
|
+
});
|
|
139
|
+
it('should apply CSS object-fit: cover when constrain="cover"', async () => {
|
|
140
|
+
const _render9 = (0, _react2.render)(/*#__PURE__*/_react.default.createElement("div", {
|
|
141
|
+
style: {
|
|
142
|
+
width: 16,
|
|
143
|
+
height: 16
|
|
144
|
+
}
|
|
145
|
+
}, _Img6 || (_Img6 = /*#__PURE__*/_react.default.createElement(_index.Img, {
|
|
146
|
+
src: image,
|
|
147
|
+
constrain: "cover"
|
|
148
|
+
})))),
|
|
149
|
+
container = _render9.container;
|
|
150
|
+
const img = container.querySelector('img');
|
|
151
|
+
const imgStyle = getComputedStyle(img);
|
|
152
|
+
expect(imgStyle.objectFit).toBe('cover');
|
|
153
|
+
});
|
|
154
|
+
it('should apply CSS object-fit: contain when constrain="contain"', async () => {
|
|
155
|
+
const _render10 = (0, _react2.render)(/*#__PURE__*/_react.default.createElement("div", {
|
|
156
|
+
style: {
|
|
157
|
+
width: 16,
|
|
158
|
+
height: 16
|
|
159
|
+
}
|
|
160
|
+
}, _Img7 || (_Img7 = /*#__PURE__*/_react.default.createElement(_index.Img, {
|
|
161
|
+
src: image,
|
|
162
|
+
constrain: "contain"
|
|
163
|
+
})))),
|
|
164
|
+
container = _render10.container;
|
|
165
|
+
const img = container.querySelector('img');
|
|
166
|
+
const imgStyle = getComputedStyle(img);
|
|
167
|
+
expect(imgStyle.objectFit).toBe('contain');
|
|
168
|
+
});
|
|
169
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-img",
|
|
3
|
-
"version": "10.6.
|
|
3
|
+
"version": "10.6.1-snapshot-1",
|
|
4
4
|
"description": "An accessible image component.",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -24,19 +24,23 @@
|
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@babel/runtime": "^7.25.6",
|
|
27
|
-
"@instructure/console": "10.6.
|
|
28
|
-
"@instructure/emotion": "10.6.
|
|
29
|
-
"@instructure/shared-types": "10.6.
|
|
30
|
-
"@instructure/ui-dom-utils": "10.6.
|
|
31
|
-
"@instructure/ui-react-utils": "10.6.
|
|
32
|
-
"@instructure/ui-testable": "10.6.
|
|
33
|
-
"@instructure/ui-view": "10.6.
|
|
27
|
+
"@instructure/console": "10.6.1-snapshot-1",
|
|
28
|
+
"@instructure/emotion": "10.6.1-snapshot-1",
|
|
29
|
+
"@instructure/shared-types": "10.6.1-snapshot-1",
|
|
30
|
+
"@instructure/ui-dom-utils": "10.6.1-snapshot-1",
|
|
31
|
+
"@instructure/ui-react-utils": "10.6.1-snapshot-1",
|
|
32
|
+
"@instructure/ui-testable": "10.6.1-snapshot-1",
|
|
33
|
+
"@instructure/ui-view": "10.6.1-snapshot-1",
|
|
34
34
|
"prop-types": "^15.8.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@instructure/ui-
|
|
38
|
-
"@instructure/ui-
|
|
39
|
-
"@instructure/ui-test-utils": "10.6.
|
|
37
|
+
"@instructure/ui-axe-check": "10.6.1-snapshot-1",
|
|
38
|
+
"@instructure/ui-babel-preset": "10.6.1-snapshot-1",
|
|
39
|
+
"@instructure/ui-test-utils": "10.6.1-snapshot-1",
|
|
40
|
+
"@testing-library/jest-dom": "^6.4.6",
|
|
41
|
+
"@testing-library/react": "^16.0.1",
|
|
42
|
+
"@testing-library/user-event": "^14.5.2",
|
|
43
|
+
"vitest": "^2.1.1"
|
|
40
44
|
},
|
|
41
45
|
"peerDependencies": {
|
|
42
46
|
"react": ">=16.8 <=18"
|
|
@@ -0,0 +1,155 @@
|
|
|
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
|
+
import React from 'react'
|
|
25
|
+
import { render } from '@testing-library/react'
|
|
26
|
+
import type { MockInstance } from 'vitest'
|
|
27
|
+
import { vi } from 'vitest'
|
|
28
|
+
|
|
29
|
+
import '@testing-library/jest-dom'
|
|
30
|
+
import { runAxeCheck } from '@instructure/ui-axe-check'
|
|
31
|
+
import { Img } from '../index'
|
|
32
|
+
|
|
33
|
+
describe('<Img />', () => {
|
|
34
|
+
const image =
|
|
35
|
+
'data:image/gif;base64,R0lGODlhFAAUAJEAAP/9/fYQEPytrflWViH5BAAAAAAALAAAAAAUABQAQAJKhI+pGe09lnhBnEETfodatVHNh1BR+ZzH9LAOCYrVYpiAfWWJOxrC/5MASbyZT4d6AUIBlUYGoR1FsAXUuTN5YhxAEYbrpKRkQwEAOw=='
|
|
36
|
+
let consoleWarningMock: ReturnType<typeof vi.spyOn>
|
|
37
|
+
let consoleErrorMock: ReturnType<typeof vi.spyOn>
|
|
38
|
+
|
|
39
|
+
beforeEach(() => {
|
|
40
|
+
// Mocking console to prevent test output pollution and expect for messages
|
|
41
|
+
consoleWarningMock = vi
|
|
42
|
+
.spyOn(console, 'warn')
|
|
43
|
+
.mockImplementation(() => {}) as MockInstance
|
|
44
|
+
consoleErrorMock = vi
|
|
45
|
+
.spyOn(console, 'error')
|
|
46
|
+
.mockImplementation(() => {}) as MockInstance
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
afterEach(() => {
|
|
50
|
+
consoleWarningMock.mockRestore()
|
|
51
|
+
consoleErrorMock.mockRestore()
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
describe('for a11y', () => {
|
|
55
|
+
it('should meet a11y standards', async () => {
|
|
56
|
+
const { container } = render(<Img src={image} />)
|
|
57
|
+
const axeCheck = await runAxeCheck(container)
|
|
58
|
+
|
|
59
|
+
expect(axeCheck).toBe(true)
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('should render an empty alt attribute by default', async () => {
|
|
63
|
+
const { container } = render(<Img src={image} />)
|
|
64
|
+
const img = container.querySelector('img')
|
|
65
|
+
|
|
66
|
+
expect(img).toHaveAttribute('alt', '')
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('should render the provided alt attribute', async () => {
|
|
70
|
+
const altValue = 'Foo'
|
|
71
|
+
const { container } = render(<Img src={image} alt={altValue} />)
|
|
72
|
+
const img = container.querySelector('img')
|
|
73
|
+
|
|
74
|
+
expect(img).toHaveAttribute('alt', altValue)
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
it('should render an overlay color', async () => {
|
|
79
|
+
const { container } = render(
|
|
80
|
+
<Img src={image} overlay={{ color: '#ff0000', opacity: 7 }} />
|
|
81
|
+
)
|
|
82
|
+
const overlay = container.querySelector('[class*="-img__overlay"]')
|
|
83
|
+
|
|
84
|
+
expect(overlay).toBeInTheDocument()
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('should render a blur filter', async () => {
|
|
88
|
+
const { container } = render(<Img src={image} withBlur={true} />)
|
|
89
|
+
|
|
90
|
+
const img = container.querySelector('img')!
|
|
91
|
+
const style = getComputedStyle(img)
|
|
92
|
+
|
|
93
|
+
expect(style.filter).toContain('blur')
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
it('should render a grayscale filter', async () => {
|
|
97
|
+
const { container } = render(<Img src={image} withGrayscale={true} />)
|
|
98
|
+
|
|
99
|
+
const img = container.querySelector('img')!
|
|
100
|
+
const style = getComputedStyle(img)
|
|
101
|
+
|
|
102
|
+
expect(style.filter).toContain('grayscale')
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
// // If component renders as simple image
|
|
106
|
+
it('should display block-level when display="block"', async () => {
|
|
107
|
+
const { container } = render(<Img src={image} display="block" />)
|
|
108
|
+
const img = container.querySelector('img')!
|
|
109
|
+
const style = getComputedStyle(img)
|
|
110
|
+
|
|
111
|
+
expect(style.display).toBe('block')
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
// // If component has an overlay and renders as image inside containing element
|
|
115
|
+
it('should display block-level with overlay when display="block"', async () => {
|
|
116
|
+
const { container } = render(
|
|
117
|
+
<Img
|
|
118
|
+
src={image}
|
|
119
|
+
display="block"
|
|
120
|
+
overlay={{ color: 'tomato', opacity: 7 }}
|
|
121
|
+
/>
|
|
122
|
+
)
|
|
123
|
+
const img = container.querySelector('img')!
|
|
124
|
+
const imgContainer = container.querySelector('[class*="-img__container"]')!
|
|
125
|
+
const imgStyle = getComputedStyle(img)
|
|
126
|
+
const imgContainerStyle = getComputedStyle(imgContainer)
|
|
127
|
+
|
|
128
|
+
expect(imgStyle.display).toBe('block')
|
|
129
|
+
expect(imgContainerStyle.display).toBe('block')
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
it('should apply CSS object-fit: cover when constrain="cover"', async () => {
|
|
133
|
+
const { container } = render(
|
|
134
|
+
<div style={{ width: 16, height: 16 }}>
|
|
135
|
+
<Img src={image} constrain="cover" />
|
|
136
|
+
</div>
|
|
137
|
+
)
|
|
138
|
+
const img = container.querySelector('img')!
|
|
139
|
+
const imgStyle = getComputedStyle(img)
|
|
140
|
+
|
|
141
|
+
expect(imgStyle.objectFit).toBe('cover')
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
it('should apply CSS object-fit: contain when constrain="contain"', async () => {
|
|
145
|
+
const { container } = render(
|
|
146
|
+
<div style={{ width: 16, height: 16 }}>
|
|
147
|
+
<Img src={image} constrain="contain" />
|
|
148
|
+
</div>
|
|
149
|
+
)
|
|
150
|
+
const img = container.querySelector('img')!
|
|
151
|
+
const imgStyle = getComputedStyle(img)
|
|
152
|
+
|
|
153
|
+
expect(imgStyle.objectFit).toBe('contain')
|
|
154
|
+
})
|
|
155
|
+
})
|
package/tsconfig.build.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
{ "path": "../ui-testable/tsconfig.build.json" },
|
|
16
16
|
{ "path": "../ui-view/tsconfig.build.json" },
|
|
17
17
|
{ "path": "../ui-babel-preset/tsconfig.build.json" },
|
|
18
|
-
{ "path": "../ui-test-
|
|
19
|
-
{ "path": "../ui-
|
|
18
|
+
{ "path": "../ui-test-utils/tsconfig.build.json" },
|
|
19
|
+
{ "path": "../ui-axe-check/tsconfig.build.json" }
|
|
20
20
|
]
|
|
21
21
|
}
|