@instructure/ui-motion 8.53.2 → 8.53.3-pr-snapshot-8
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/Transition/__new-tests__/Transition.test.js +182 -0
- package/lib/Transition/__new-tests__/Transition.test.js +184 -0
- package/package.json +12 -11
- package/src/Transition/__new-tests__/Transition.test.tsx +252 -0
- package/tsconfig.build.json +0 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Transition/__new-tests__/Transition.test.d.ts +2 -0
- package/types/Transition/__new-tests__/Transition.test.d.ts.map +1 -0
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
|
+
## [8.53.3-pr-snapshot-8](https://github.com/instructure/instructure-ui/compare/v8.53.2...v8.53.3-pr-snapshot-8) (2024-02-23)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @instructure/ui-motion
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
## [8.53.2](https://github.com/instructure/instructure-ui/compare/v8.53.1...v8.53.2) (2024-02-15)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @instructure/ui-motion
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
var _div, _div2, _ExampleComponent, _div3, _div4, _Transition3, _Transition4, _div5, _div6, _div7, _div8, _div9, _div10, _div11;
|
|
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 React, { Component } from 'react';
|
|
27
|
+
import { render, waitFor, waitForElementToBeRemoved } from '@testing-library/react';
|
|
28
|
+
import '@testing-library/jest-dom';
|
|
29
|
+
import { Transition } from '../index';
|
|
30
|
+
import { getClassNames } from '../styles';
|
|
31
|
+
const COMPONENT_TEXT = 'Component Text';
|
|
32
|
+
const getClass = (type, phase) => {
|
|
33
|
+
const classNames = getClassNames(type);
|
|
34
|
+
return classNames[phase];
|
|
35
|
+
};
|
|
36
|
+
class ExampleComponent extends Component {
|
|
37
|
+
render() {
|
|
38
|
+
return _div || (_div = /*#__PURE__*/React.createElement("div", null, COMPONENT_TEXT));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
ExampleComponent.displayName = "ExampleComponent";
|
|
42
|
+
describe('<Transition />', () => {
|
|
43
|
+
const types = ['fade', 'scale', 'slide-down', 'slide-up', 'slide-left', 'slide-right'];
|
|
44
|
+
const expectTypeClass = function (type) {
|
|
45
|
+
var _Transition, _Transition2;
|
|
46
|
+
it(`should correctly apply classes for '${type}' with html element`, () => {
|
|
47
|
+
const _render = render(_Transition || (_Transition = /*#__PURE__*/React.createElement(Transition, {
|
|
48
|
+
type: type,
|
|
49
|
+
in: true
|
|
50
|
+
}, _div2 || (_div2 = /*#__PURE__*/React.createElement("div", null, "hello"))))),
|
|
51
|
+
getByText = _render.getByText;
|
|
52
|
+
const element = getByText('hello');
|
|
53
|
+
expect(element).toHaveClass(getClass(type, 'entered'));
|
|
54
|
+
});
|
|
55
|
+
it(`should correctly apply classes for '${type}' with Component`, () => {
|
|
56
|
+
const _render2 = render(_Transition2 || (_Transition2 = /*#__PURE__*/React.createElement(Transition, {
|
|
57
|
+
type: type,
|
|
58
|
+
in: true
|
|
59
|
+
}, _ExampleComponent || (_ExampleComponent = /*#__PURE__*/React.createElement(ExampleComponent, null))))),
|
|
60
|
+
getByText = _render2.getByText;
|
|
61
|
+
const element = getByText(COMPONENT_TEXT);
|
|
62
|
+
expect(element).toHaveClass(getClass(type, 'entered'));
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
types.forEach(type => {
|
|
66
|
+
expectTypeClass(type);
|
|
67
|
+
});
|
|
68
|
+
it('should correctly apply enter and exit classes', async () => {
|
|
69
|
+
const type = 'fade';
|
|
70
|
+
const _render3 = render( /*#__PURE__*/React.createElement(Transition, {
|
|
71
|
+
type: type,
|
|
72
|
+
in: true
|
|
73
|
+
}, _div3 || (_div3 = /*#__PURE__*/React.createElement("div", null, "hello")))),
|
|
74
|
+
getByText = _render3.getByText,
|
|
75
|
+
rerender = _render3.rerender;
|
|
76
|
+
const element = getByText('hello');
|
|
77
|
+
expect(element).toHaveClass(getClass(type, 'entered'));
|
|
78
|
+
rerender( /*#__PURE__*/React.createElement(Transition, {
|
|
79
|
+
type: type,
|
|
80
|
+
in: false
|
|
81
|
+
}, _div4 || (_div4 = /*#__PURE__*/React.createElement("div", null, "hello"))));
|
|
82
|
+
await waitFor(() => {
|
|
83
|
+
expect(element).toHaveClass(getClass(type, 'exited'));
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
it('should remove component from DOM when `unmountOnExit` is set', async () => {
|
|
87
|
+
const _render4 = render(_Transition3 || (_Transition3 = /*#__PURE__*/React.createElement(Transition, {
|
|
88
|
+
type: "fade",
|
|
89
|
+
in: true,
|
|
90
|
+
unmountOnExit: true
|
|
91
|
+
}, /*#__PURE__*/React.createElement("div", null, "hello")))),
|
|
92
|
+
getByText = _render4.getByText,
|
|
93
|
+
rerender = _render4.rerender;
|
|
94
|
+
expect(getByText('hello')).toBeInTheDocument();
|
|
95
|
+
rerender(_Transition4 || (_Transition4 = /*#__PURE__*/React.createElement(Transition, {
|
|
96
|
+
type: "fade",
|
|
97
|
+
in: false,
|
|
98
|
+
unmountOnExit: true
|
|
99
|
+
}, /*#__PURE__*/React.createElement("div", null, "hello"))));
|
|
100
|
+
await waitForElementToBeRemoved(() => getByText('hello'));
|
|
101
|
+
});
|
|
102
|
+
it('should not execute enter transition with `transitionEnter` set to false', async () => {
|
|
103
|
+
const onEntering = jest.fn();
|
|
104
|
+
const _render5 = render( /*#__PURE__*/React.createElement(Transition, {
|
|
105
|
+
type: "fade",
|
|
106
|
+
in: false,
|
|
107
|
+
transitionEnter: true,
|
|
108
|
+
onEntering: onEntering
|
|
109
|
+
}, _div5 || (_div5 = /*#__PURE__*/React.createElement("div", null, "hello")))),
|
|
110
|
+
rerender = _render5.rerender;
|
|
111
|
+
rerender( /*#__PURE__*/React.createElement(Transition, {
|
|
112
|
+
type: "fade",
|
|
113
|
+
in: true,
|
|
114
|
+
transitionEnter: false,
|
|
115
|
+
onEntering: onEntering
|
|
116
|
+
}, _div6 || (_div6 = /*#__PURE__*/React.createElement("div", null, "hello"))));
|
|
117
|
+
await waitFor(() => {
|
|
118
|
+
expect(onEntering).not.toHaveBeenCalled();
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
it('should not execute exit transition with `transitionExit` set to false', async () => {
|
|
122
|
+
const onExiting = jest.fn();
|
|
123
|
+
const _render6 = render( /*#__PURE__*/React.createElement(Transition, {
|
|
124
|
+
type: "fade",
|
|
125
|
+
in: true,
|
|
126
|
+
transitionExit: false,
|
|
127
|
+
onExiting: onExiting
|
|
128
|
+
}, _div7 || (_div7 = /*#__PURE__*/React.createElement("div", null, "hello")))),
|
|
129
|
+
rerender = _render6.rerender;
|
|
130
|
+
rerender( /*#__PURE__*/React.createElement(Transition, {
|
|
131
|
+
type: "fade",
|
|
132
|
+
in: false,
|
|
133
|
+
transitionExit: false,
|
|
134
|
+
onExiting: onExiting
|
|
135
|
+
}, _div8 || (_div8 = /*#__PURE__*/React.createElement("div", null, "hello"))));
|
|
136
|
+
await waitFor(() => {
|
|
137
|
+
expect(onExiting).not.toHaveBeenCalled();
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
it('should correctly call enter methods', async () => {
|
|
141
|
+
const onEnter = jest.fn();
|
|
142
|
+
const onEntering = jest.fn();
|
|
143
|
+
const onEntered = jest.fn();
|
|
144
|
+
render( /*#__PURE__*/React.createElement(Transition, {
|
|
145
|
+
type: "fade",
|
|
146
|
+
in: true,
|
|
147
|
+
onEnter: onEnter,
|
|
148
|
+
onEntering: onEntering,
|
|
149
|
+
onEntered: onEntered
|
|
150
|
+
}, _div9 || (_div9 = /*#__PURE__*/React.createElement("div", null, "hello"))));
|
|
151
|
+
await waitFor(() => {
|
|
152
|
+
expect(onEnter).toHaveBeenCalled();
|
|
153
|
+
expect(onEntering).toHaveBeenCalled();
|
|
154
|
+
expect(onEntered).toHaveBeenCalled();
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
it('should correctly call exit methods', async () => {
|
|
158
|
+
const onExit = jest.fn();
|
|
159
|
+
const onExiting = jest.fn();
|
|
160
|
+
const onExited = jest.fn();
|
|
161
|
+
const _render7 = render( /*#__PURE__*/React.createElement(Transition, {
|
|
162
|
+
type: "fade",
|
|
163
|
+
in: true,
|
|
164
|
+
onExit: onExit,
|
|
165
|
+
onExiting: onExiting,
|
|
166
|
+
onExited: onExited
|
|
167
|
+
}, _div10 || (_div10 = /*#__PURE__*/React.createElement("div", null, "hello")))),
|
|
168
|
+
rerender = _render7.rerender;
|
|
169
|
+
rerender( /*#__PURE__*/React.createElement(Transition, {
|
|
170
|
+
type: "fade",
|
|
171
|
+
in: false,
|
|
172
|
+
onExit: onExit,
|
|
173
|
+
onExiting: onExiting,
|
|
174
|
+
onExited: onExited
|
|
175
|
+
}, _div11 || (_div11 = /*#__PURE__*/React.createElement("div", null, "hello"))));
|
|
176
|
+
await waitFor(() => {
|
|
177
|
+
expect(onExit).toHaveBeenCalled();
|
|
178
|
+
expect(onExiting).toHaveBeenCalled();
|
|
179
|
+
expect(onExited).toHaveBeenCalled();
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
});
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
5
|
+
var _react2 = require("@testing-library/react");
|
|
6
|
+
require("@testing-library/jest-dom");
|
|
7
|
+
var _index = require("../index");
|
|
8
|
+
var _styles = require("../styles");
|
|
9
|
+
var _div, _div2, _ExampleComponent, _div3, _div4, _Transition3, _Transition4, _div5, _div6, _div7, _div8, _div9, _div10, _div11;
|
|
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
|
+
const COMPONENT_TEXT = 'Component Text';
|
|
34
|
+
const getClass = (type, phase) => {
|
|
35
|
+
const classNames = (0, _styles.getClassNames)(type);
|
|
36
|
+
return classNames[phase];
|
|
37
|
+
};
|
|
38
|
+
class ExampleComponent extends _react.Component {
|
|
39
|
+
render() {
|
|
40
|
+
return _div || (_div = /*#__PURE__*/_react.default.createElement("div", null, COMPONENT_TEXT));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
ExampleComponent.displayName = "ExampleComponent";
|
|
44
|
+
describe('<Transition />', () => {
|
|
45
|
+
const types = ['fade', 'scale', 'slide-down', 'slide-up', 'slide-left', 'slide-right'];
|
|
46
|
+
const expectTypeClass = function (type) {
|
|
47
|
+
var _Transition, _Transition2;
|
|
48
|
+
it(`should correctly apply classes for '${type}' with html element`, () => {
|
|
49
|
+
const _render = (0, _react2.render)(_Transition || (_Transition = /*#__PURE__*/_react.default.createElement(_index.Transition, {
|
|
50
|
+
type: type,
|
|
51
|
+
in: true
|
|
52
|
+
}, _div2 || (_div2 = /*#__PURE__*/_react.default.createElement("div", null, "hello"))))),
|
|
53
|
+
getByText = _render.getByText;
|
|
54
|
+
const element = getByText('hello');
|
|
55
|
+
expect(element).toHaveClass(getClass(type, 'entered'));
|
|
56
|
+
});
|
|
57
|
+
it(`should correctly apply classes for '${type}' with Component`, () => {
|
|
58
|
+
const _render2 = (0, _react2.render)(_Transition2 || (_Transition2 = /*#__PURE__*/_react.default.createElement(_index.Transition, {
|
|
59
|
+
type: type,
|
|
60
|
+
in: true
|
|
61
|
+
}, _ExampleComponent || (_ExampleComponent = /*#__PURE__*/_react.default.createElement(ExampleComponent, null))))),
|
|
62
|
+
getByText = _render2.getByText;
|
|
63
|
+
const element = getByText(COMPONENT_TEXT);
|
|
64
|
+
expect(element).toHaveClass(getClass(type, 'entered'));
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
types.forEach(type => {
|
|
68
|
+
expectTypeClass(type);
|
|
69
|
+
});
|
|
70
|
+
it('should correctly apply enter and exit classes', async () => {
|
|
71
|
+
const type = 'fade';
|
|
72
|
+
const _render3 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Transition, {
|
|
73
|
+
type: type,
|
|
74
|
+
in: true
|
|
75
|
+
}, _div3 || (_div3 = /*#__PURE__*/_react.default.createElement("div", null, "hello")))),
|
|
76
|
+
getByText = _render3.getByText,
|
|
77
|
+
rerender = _render3.rerender;
|
|
78
|
+
const element = getByText('hello');
|
|
79
|
+
expect(element).toHaveClass(getClass(type, 'entered'));
|
|
80
|
+
rerender( /*#__PURE__*/_react.default.createElement(_index.Transition, {
|
|
81
|
+
type: type,
|
|
82
|
+
in: false
|
|
83
|
+
}, _div4 || (_div4 = /*#__PURE__*/_react.default.createElement("div", null, "hello"))));
|
|
84
|
+
await (0, _react2.waitFor)(() => {
|
|
85
|
+
expect(element).toHaveClass(getClass(type, 'exited'));
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
it('should remove component from DOM when `unmountOnExit` is set', async () => {
|
|
89
|
+
const _render4 = (0, _react2.render)(_Transition3 || (_Transition3 = /*#__PURE__*/_react.default.createElement(_index.Transition, {
|
|
90
|
+
type: "fade",
|
|
91
|
+
in: true,
|
|
92
|
+
unmountOnExit: true
|
|
93
|
+
}, /*#__PURE__*/_react.default.createElement("div", null, "hello")))),
|
|
94
|
+
getByText = _render4.getByText,
|
|
95
|
+
rerender = _render4.rerender;
|
|
96
|
+
expect(getByText('hello')).toBeInTheDocument();
|
|
97
|
+
rerender(_Transition4 || (_Transition4 = /*#__PURE__*/_react.default.createElement(_index.Transition, {
|
|
98
|
+
type: "fade",
|
|
99
|
+
in: false,
|
|
100
|
+
unmountOnExit: true
|
|
101
|
+
}, /*#__PURE__*/_react.default.createElement("div", null, "hello"))));
|
|
102
|
+
await (0, _react2.waitForElementToBeRemoved)(() => getByText('hello'));
|
|
103
|
+
});
|
|
104
|
+
it('should not execute enter transition with `transitionEnter` set to false', async () => {
|
|
105
|
+
const onEntering = jest.fn();
|
|
106
|
+
const _render5 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Transition, {
|
|
107
|
+
type: "fade",
|
|
108
|
+
in: false,
|
|
109
|
+
transitionEnter: true,
|
|
110
|
+
onEntering: onEntering
|
|
111
|
+
}, _div5 || (_div5 = /*#__PURE__*/_react.default.createElement("div", null, "hello")))),
|
|
112
|
+
rerender = _render5.rerender;
|
|
113
|
+
rerender( /*#__PURE__*/_react.default.createElement(_index.Transition, {
|
|
114
|
+
type: "fade",
|
|
115
|
+
in: true,
|
|
116
|
+
transitionEnter: false,
|
|
117
|
+
onEntering: onEntering
|
|
118
|
+
}, _div6 || (_div6 = /*#__PURE__*/_react.default.createElement("div", null, "hello"))));
|
|
119
|
+
await (0, _react2.waitFor)(() => {
|
|
120
|
+
expect(onEntering).not.toHaveBeenCalled();
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
it('should not execute exit transition with `transitionExit` set to false', async () => {
|
|
124
|
+
const onExiting = jest.fn();
|
|
125
|
+
const _render6 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Transition, {
|
|
126
|
+
type: "fade",
|
|
127
|
+
in: true,
|
|
128
|
+
transitionExit: false,
|
|
129
|
+
onExiting: onExiting
|
|
130
|
+
}, _div7 || (_div7 = /*#__PURE__*/_react.default.createElement("div", null, "hello")))),
|
|
131
|
+
rerender = _render6.rerender;
|
|
132
|
+
rerender( /*#__PURE__*/_react.default.createElement(_index.Transition, {
|
|
133
|
+
type: "fade",
|
|
134
|
+
in: false,
|
|
135
|
+
transitionExit: false,
|
|
136
|
+
onExiting: onExiting
|
|
137
|
+
}, _div8 || (_div8 = /*#__PURE__*/_react.default.createElement("div", null, "hello"))));
|
|
138
|
+
await (0, _react2.waitFor)(() => {
|
|
139
|
+
expect(onExiting).not.toHaveBeenCalled();
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
it('should correctly call enter methods', async () => {
|
|
143
|
+
const onEnter = jest.fn();
|
|
144
|
+
const onEntering = jest.fn();
|
|
145
|
+
const onEntered = jest.fn();
|
|
146
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Transition, {
|
|
147
|
+
type: "fade",
|
|
148
|
+
in: true,
|
|
149
|
+
onEnter: onEnter,
|
|
150
|
+
onEntering: onEntering,
|
|
151
|
+
onEntered: onEntered
|
|
152
|
+
}, _div9 || (_div9 = /*#__PURE__*/_react.default.createElement("div", null, "hello"))));
|
|
153
|
+
await (0, _react2.waitFor)(() => {
|
|
154
|
+
expect(onEnter).toHaveBeenCalled();
|
|
155
|
+
expect(onEntering).toHaveBeenCalled();
|
|
156
|
+
expect(onEntered).toHaveBeenCalled();
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
it('should correctly call exit methods', async () => {
|
|
160
|
+
const onExit = jest.fn();
|
|
161
|
+
const onExiting = jest.fn();
|
|
162
|
+
const onExited = jest.fn();
|
|
163
|
+
const _render7 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Transition, {
|
|
164
|
+
type: "fade",
|
|
165
|
+
in: true,
|
|
166
|
+
onExit: onExit,
|
|
167
|
+
onExiting: onExiting,
|
|
168
|
+
onExited: onExited
|
|
169
|
+
}, _div10 || (_div10 = /*#__PURE__*/_react.default.createElement("div", null, "hello")))),
|
|
170
|
+
rerender = _render7.rerender;
|
|
171
|
+
rerender( /*#__PURE__*/_react.default.createElement(_index.Transition, {
|
|
172
|
+
type: "fade",
|
|
173
|
+
in: false,
|
|
174
|
+
onExit: onExit,
|
|
175
|
+
onExiting: onExiting,
|
|
176
|
+
onExited: onExited
|
|
177
|
+
}, _div11 || (_div11 = /*#__PURE__*/_react.default.createElement("div", null, "hello"))));
|
|
178
|
+
await (0, _react2.waitFor)(() => {
|
|
179
|
+
expect(onExit).toHaveBeenCalled();
|
|
180
|
+
expect(onExiting).toHaveBeenCalled();
|
|
181
|
+
expect(onExited).toHaveBeenCalled();
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-motion",
|
|
3
|
-
"version": "8.53.
|
|
3
|
+
"version": "8.53.3-pr-snapshot-8",
|
|
4
4
|
"description": "A UI component library made by Instructure Inc.",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -23,19 +23,20 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@instructure/ui-babel-preset": "8.53.
|
|
27
|
-
"@instructure/ui-test-locator": "8.53.
|
|
28
|
-
"@instructure/ui-
|
|
29
|
-
"@
|
|
26
|
+
"@instructure/ui-babel-preset": "8.53.3-pr-snapshot-8",
|
|
27
|
+
"@instructure/ui-test-locator": "8.53.3-pr-snapshot-8",
|
|
28
|
+
"@instructure/ui-themes": "8.53.3-pr-snapshot-8",
|
|
29
|
+
"@testing-library/jest-dom": "^6.1.4",
|
|
30
|
+
"@testing-library/react": "^14.0.0"
|
|
30
31
|
},
|
|
31
32
|
"dependencies": {
|
|
32
33
|
"@babel/runtime": "^7.23.2",
|
|
33
|
-
"@instructure/emotion": "8.53.
|
|
34
|
-
"@instructure/shared-types": "8.53.
|
|
35
|
-
"@instructure/ui-dom-utils": "8.53.
|
|
36
|
-
"@instructure/ui-react-utils": "8.53.
|
|
37
|
-
"@instructure/ui-testable": "8.53.
|
|
38
|
-
"@instructure/ui-utils": "8.53.
|
|
34
|
+
"@instructure/emotion": "8.53.3-pr-snapshot-8",
|
|
35
|
+
"@instructure/shared-types": "8.53.3-pr-snapshot-8",
|
|
36
|
+
"@instructure/ui-dom-utils": "8.53.3-pr-snapshot-8",
|
|
37
|
+
"@instructure/ui-react-utils": "8.53.3-pr-snapshot-8",
|
|
38
|
+
"@instructure/ui-testable": "8.53.3-pr-snapshot-8",
|
|
39
|
+
"@instructure/ui-utils": "8.53.3-pr-snapshot-8",
|
|
39
40
|
"prop-types": "^15.8.1"
|
|
40
41
|
},
|
|
41
42
|
"peerDependencies": {
|
|
@@ -0,0 +1,252 @@
|
|
|
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 React, { Component } from 'react'
|
|
26
|
+
import {
|
|
27
|
+
render,
|
|
28
|
+
waitFor,
|
|
29
|
+
waitForElementToBeRemoved
|
|
30
|
+
} from '@testing-library/react'
|
|
31
|
+
import '@testing-library/jest-dom'
|
|
32
|
+
|
|
33
|
+
import { Transition } from '../index'
|
|
34
|
+
import { getClassNames } from '../styles'
|
|
35
|
+
|
|
36
|
+
import type { TransitionStyle, TransitionType } from '../props'
|
|
37
|
+
|
|
38
|
+
const COMPONENT_TEXT = 'Component Text'
|
|
39
|
+
|
|
40
|
+
const getClass = (
|
|
41
|
+
type: TransitionType,
|
|
42
|
+
phase: keyof TransitionStyle['classNames']
|
|
43
|
+
) => {
|
|
44
|
+
const classNames = getClassNames(type)
|
|
45
|
+
return classNames[phase]
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
class ExampleComponent extends Component {
|
|
49
|
+
render() {
|
|
50
|
+
return <div>{COMPONENT_TEXT}</div>
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
describe('<Transition />', () => {
|
|
55
|
+
const types: TransitionType[] = [
|
|
56
|
+
'fade',
|
|
57
|
+
'scale',
|
|
58
|
+
'slide-down',
|
|
59
|
+
'slide-up',
|
|
60
|
+
'slide-left',
|
|
61
|
+
'slide-right'
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
const expectTypeClass = function (type: TransitionType) {
|
|
65
|
+
it(`should correctly apply classes for '${type}' with html element`, () => {
|
|
66
|
+
const { getByText } = render(
|
|
67
|
+
<Transition type={type} in={true}>
|
|
68
|
+
<div>hello</div>
|
|
69
|
+
</Transition>
|
|
70
|
+
)
|
|
71
|
+
const element = getByText('hello')
|
|
72
|
+
|
|
73
|
+
expect(element).toHaveClass(getClass(type, 'entered'))
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
it(`should correctly apply classes for '${type}' with Component`, () => {
|
|
77
|
+
const { getByText } = render(
|
|
78
|
+
<Transition type={type} in={true}>
|
|
79
|
+
<ExampleComponent />
|
|
80
|
+
</Transition>
|
|
81
|
+
)
|
|
82
|
+
const element = getByText(COMPONENT_TEXT)
|
|
83
|
+
|
|
84
|
+
expect(element).toHaveClass(getClass(type, 'entered'))
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
types.forEach((type) => {
|
|
89
|
+
expectTypeClass(type)
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it('should correctly apply enter and exit classes', async () => {
|
|
93
|
+
const type = 'fade'
|
|
94
|
+
|
|
95
|
+
const { getByText, rerender } = render(
|
|
96
|
+
<Transition type={type} in={true}>
|
|
97
|
+
<div>hello</div>
|
|
98
|
+
</Transition>
|
|
99
|
+
)
|
|
100
|
+
const element = getByText('hello')
|
|
101
|
+
|
|
102
|
+
expect(element).toHaveClass(getClass(type, 'entered'))
|
|
103
|
+
|
|
104
|
+
rerender(
|
|
105
|
+
<Transition type={type} in={false}>
|
|
106
|
+
<div>hello</div>
|
|
107
|
+
</Transition>
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
await waitFor(() => {
|
|
111
|
+
expect(element).toHaveClass(getClass(type, 'exited'))
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
it('should remove component from DOM when `unmountOnExit` is set', async () => {
|
|
116
|
+
const { getByText, rerender } = render(
|
|
117
|
+
<Transition type="fade" in={true} unmountOnExit={true}>
|
|
118
|
+
<div>hello</div>
|
|
119
|
+
</Transition>
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
expect(getByText('hello')).toBeInTheDocument()
|
|
123
|
+
|
|
124
|
+
rerender(
|
|
125
|
+
<Transition type="fade" in={false} unmountOnExit={true}>
|
|
126
|
+
<div>hello</div>
|
|
127
|
+
</Transition>
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
await waitForElementToBeRemoved(() => getByText('hello'))
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
it('should not execute enter transition with `transitionEnter` set to false', async () => {
|
|
134
|
+
const onEntering = jest.fn()
|
|
135
|
+
|
|
136
|
+
const { rerender } = render(
|
|
137
|
+
<Transition
|
|
138
|
+
type="fade"
|
|
139
|
+
in={false}
|
|
140
|
+
transitionEnter={true}
|
|
141
|
+
onEntering={onEntering}
|
|
142
|
+
>
|
|
143
|
+
<div>hello</div>
|
|
144
|
+
</Transition>
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
rerender(
|
|
148
|
+
<Transition
|
|
149
|
+
type="fade"
|
|
150
|
+
in={true}
|
|
151
|
+
transitionEnter={false}
|
|
152
|
+
onEntering={onEntering}
|
|
153
|
+
>
|
|
154
|
+
<div>hello</div>
|
|
155
|
+
</Transition>
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
await waitFor(() => {
|
|
159
|
+
expect(onEntering).not.toHaveBeenCalled()
|
|
160
|
+
})
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
it('should not execute exit transition with `transitionExit` set to false', async () => {
|
|
164
|
+
const onExiting = jest.fn()
|
|
165
|
+
|
|
166
|
+
const { rerender } = render(
|
|
167
|
+
<Transition
|
|
168
|
+
type="fade"
|
|
169
|
+
in={true}
|
|
170
|
+
transitionExit={false}
|
|
171
|
+
onExiting={onExiting}
|
|
172
|
+
>
|
|
173
|
+
<div>hello</div>
|
|
174
|
+
</Transition>
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
rerender(
|
|
178
|
+
<Transition
|
|
179
|
+
type="fade"
|
|
180
|
+
in={false}
|
|
181
|
+
transitionExit={false}
|
|
182
|
+
onExiting={onExiting}
|
|
183
|
+
>
|
|
184
|
+
<div>hello</div>
|
|
185
|
+
</Transition>
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
await waitFor(() => {
|
|
189
|
+
expect(onExiting).not.toHaveBeenCalled()
|
|
190
|
+
})
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
it('should correctly call enter methods', async () => {
|
|
194
|
+
const onEnter = jest.fn()
|
|
195
|
+
const onEntering = jest.fn()
|
|
196
|
+
const onEntered = jest.fn()
|
|
197
|
+
|
|
198
|
+
render(
|
|
199
|
+
<Transition
|
|
200
|
+
type="fade"
|
|
201
|
+
in={true}
|
|
202
|
+
onEnter={onEnter}
|
|
203
|
+
onEntering={onEntering}
|
|
204
|
+
onEntered={onEntered}
|
|
205
|
+
>
|
|
206
|
+
<div>hello</div>
|
|
207
|
+
</Transition>
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
await waitFor(() => {
|
|
211
|
+
expect(onEnter).toHaveBeenCalled()
|
|
212
|
+
expect(onEntering).toHaveBeenCalled()
|
|
213
|
+
expect(onEntered).toHaveBeenCalled()
|
|
214
|
+
})
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
it('should correctly call exit methods', async () => {
|
|
218
|
+
const onExit = jest.fn()
|
|
219
|
+
const onExiting = jest.fn()
|
|
220
|
+
const onExited = jest.fn()
|
|
221
|
+
|
|
222
|
+
const { rerender } = render(
|
|
223
|
+
<Transition
|
|
224
|
+
type="fade"
|
|
225
|
+
in={true}
|
|
226
|
+
onExit={onExit}
|
|
227
|
+
onExiting={onExiting}
|
|
228
|
+
onExited={onExited}
|
|
229
|
+
>
|
|
230
|
+
<div>hello</div>
|
|
231
|
+
</Transition>
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
rerender(
|
|
235
|
+
<Transition
|
|
236
|
+
type="fade"
|
|
237
|
+
in={false}
|
|
238
|
+
onExit={onExit}
|
|
239
|
+
onExiting={onExiting}
|
|
240
|
+
onExited={onExited}
|
|
241
|
+
>
|
|
242
|
+
<div>hello</div>
|
|
243
|
+
</Transition>
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
await waitFor(() => {
|
|
247
|
+
expect(onExit).toHaveBeenCalled()
|
|
248
|
+
expect(onExiting).toHaveBeenCalled()
|
|
249
|
+
expect(onExited).toHaveBeenCalled()
|
|
250
|
+
})
|
|
251
|
+
})
|
|
252
|
+
})
|
package/tsconfig.build.json
CHANGED
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
"references": [
|
|
10
10
|
{ "path": "../ui-babel-preset/tsconfig.build.json" },
|
|
11
11
|
{ "path": "../ui-test-locator/tsconfig.build.json" },
|
|
12
|
-
{ "path": "../ui-test-utils/tsconfig.build.json" },
|
|
13
12
|
{ "path": "../ui-themes/tsconfig.build.json" },
|
|
14
13
|
{ "path": "../emotion/tsconfig.build.json" },
|
|
15
14
|
{ "path": "../shared-types/tsconfig.build.json" },
|