@instructure/ui-testable
Advanced tools
Comparing version
@@ -6,11 +6,14 @@ # Change Log | ||
<a name="5.39.0-rc.5"></a> | ||
# [5.39.0-rc.5](https://github.com/instructure/instructure-ui/compare/v5.38.0...v5.39.0-rc.5) (2019-01-08) | ||
<a name="5.39.0-rc.6"></a> | ||
# [5.39.0-rc.6](https://github.com/instructure/instructure-ui/compare/v5.38.0...v5.39.0-rc.6) (2019-01-08) | ||
**Note:** Version bump only for package @instructure/ui-testable | ||
### Features | ||
* **ui-decorator:** add a ui-decorator package/util ([8179186](https://github.com/instructure/instructure-ui/commit/8179186)) | ||
<a name="5.38.0"></a> | ||
@@ -17,0 +20,0 @@ # [5.38.0](https://github.com/instructure/instructure-ui/compare/v5.37.0...v5.38.0) (2019-01-04) |
211
es/index.js
@@ -29,128 +29,123 @@ 'use strict'; | ||
var _uiDecorator = require('@instructure/ui-decorator'); | ||
var _uiDecorator2 = _interopRequireDefault(_uiDecorator); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function testable() { | ||
return function (ComposedComponent) { | ||
var _class, _temp; | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2015 - present Instructure, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
var displayName = ComposedComponent.displayName || ComposedComponent.name; | ||
var locator = { | ||
attribute: 'data-uid', | ||
value: displayName | ||
}; | ||
var selector = '[' + locator.attribute + '~="' + locator.value + '"]'; | ||
exports.default = (0, _uiDecorator2.default)(function (ComposedComponent) { | ||
var _class, _temp; | ||
var TestableComponent = (_temp = _class = function (_ComposedComponent) { | ||
(0, _inherits3.default)(TestableComponent, _ComposedComponent); | ||
var displayName = ComposedComponent.displayName || ComposedComponent.name; | ||
var locator = { | ||
attribute: 'data-uid', | ||
value: displayName | ||
}; | ||
var selector = '[' + locator.attribute + '~="' + locator.value + '"]'; | ||
var TestableComponent = (_temp = _class = function (_ComposedComponent) { | ||
(0, _inherits3.default)(TestableComponent, _ComposedComponent); | ||
function TestableComponent() { | ||
(0, _classCallCheck3.default)(this, TestableComponent); | ||
return (0, _possibleConstructorReturn3.default)(this, (TestableComponent.__proto__ || Object.getPrototypeOf(TestableComponent)).apply(this, arguments)); | ||
} | ||
function TestableComponent() { | ||
(0, _classCallCheck3.default)(this, TestableComponent); | ||
return (0, _possibleConstructorReturn3.default)(this, (TestableComponent.__proto__ || Object.getPrototypeOf(TestableComponent)).apply(this, arguments)); | ||
} | ||
(0, _createClass3.default)(TestableComponent, [{ | ||
key: 'componentDidMount', | ||
value: function componentDidMount() { | ||
if ((0, _get6.default)(TestableComponent.prototype.__proto__ || Object.getPrototypeOf(TestableComponent.prototype), 'componentDidMount', this)) { | ||
var _get2; | ||
(0, _createClass3.default)(TestableComponent, [{ | ||
key: 'componentDidMount', | ||
value: function componentDidMount() { | ||
if ((0, _get6.default)(TestableComponent.prototype.__proto__ || Object.getPrototypeOf(TestableComponent.prototype), 'componentDidMount', this)) { | ||
var _get2; | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
(_get2 = (0, _get6.default)(TestableComponent.prototype.__proto__ || Object.getPrototypeOf(TestableComponent.prototype), 'componentDidMount', this)).call.apply(_get2, [this].concat(args)); | ||
} | ||
this.appendLocatorAttribute(); | ||
(_get2 = (0, _get6.default)(TestableComponent.prototype.__proto__ || Object.getPrototypeOf(TestableComponent.prototype), 'componentDidMount', this)).call.apply(_get2, [this].concat(args)); | ||
} | ||
}, { | ||
key: 'componentDidUpdate', | ||
value: function componentDidUpdate() { | ||
if ((0, _get6.default)(TestableComponent.prototype.__proto__ || Object.getPrototypeOf(TestableComponent.prototype), 'componentDidUpdate', this)) { | ||
var _get3; | ||
this.appendLocatorAttribute(); | ||
} | ||
}, { | ||
key: 'componentDidUpdate', | ||
value: function componentDidUpdate() { | ||
if ((0, _get6.default)(TestableComponent.prototype.__proto__ || Object.getPrototypeOf(TestableComponent.prototype), 'componentDidUpdate', this)) { | ||
var _get3; | ||
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
(_get3 = (0, _get6.default)(TestableComponent.prototype.__proto__ || Object.getPrototypeOf(TestableComponent.prototype), 'componentDidUpdate', this)).call.apply(_get3, [this].concat(args)); | ||
} | ||
this.appendLocatorAttribute(); | ||
(_get3 = (0, _get6.default)(TestableComponent.prototype.__proto__ || Object.getPrototypeOf(TestableComponent.prototype), 'componentDidUpdate', this)).call.apply(_get3, [this].concat(args)); | ||
} | ||
}, { | ||
key: 'componentWillUnmount', | ||
value: function componentWillUnmount() { | ||
this._testableUnmounted = true; | ||
if ((0, _get6.default)(TestableComponent.prototype.__proto__ || Object.getPrototypeOf(TestableComponent.prototype), 'componentWillUnmount', this)) { | ||
var _get4; | ||
this.appendLocatorAttribute(); | ||
} | ||
}, { | ||
key: 'componentWillUnmount', | ||
value: function componentWillUnmount() { | ||
this._testableUnmounted = true; | ||
if ((0, _get6.default)(TestableComponent.prototype.__proto__ || Object.getPrototypeOf(TestableComponent.prototype), 'componentWillUnmount', this)) { | ||
var _get4; | ||
for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
args[_key3] = arguments[_key3]; | ||
} | ||
for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
args[_key3] = arguments[_key3]; | ||
} | ||
(_get4 = (0, _get6.default)(TestableComponent.prototype.__proto__ || Object.getPrototypeOf(TestableComponent.prototype), 'componentWillUnmount', this)).call.apply(_get4, [this].concat(args)); | ||
} | ||
clearTimeout(this.locatorTimeout); | ||
(_get4 = (0, _get6.default)(TestableComponent.prototype.__proto__ || Object.getPrototypeOf(TestableComponent.prototype), 'componentWillUnmount', this)).call.apply(_get4, [this].concat(args)); | ||
} | ||
}, { | ||
key: 'appendLocatorAttribute', | ||
value: function appendLocatorAttribute() { | ||
var _this2 = this; | ||
clearTimeout(this.locatorTimeout); | ||
} | ||
}, { | ||
key: 'appendLocatorAttribute', | ||
value: function appendLocatorAttribute() { | ||
var _this2 = this; | ||
this.locatorTimeout = setTimeout(function () { | ||
var node = void 0; | ||
if (_this2._testableUnmounted) { | ||
return; | ||
this.locatorTimeout = setTimeout(function () { | ||
var node = void 0; | ||
if (_this2._testableUnmounted) { | ||
return; | ||
} | ||
try { | ||
// Use this.DOMNode for components that render as non-native Portals... | ||
node = (0, _reactDom.findDOMNode)(_this2) || _this2.DOMNode; | ||
} catch (e) { | ||
console.warn('[ui-testable] Could not append locator attribute: ' + e); | ||
} | ||
if (node && node.getAttribute) { | ||
var attribute = node.getAttribute(locator.attribute); | ||
var values = typeof attribute === 'string' ? attribute.split(/\s+/) : []; | ||
if (!values.includes(locator.value)) { | ||
values.push(locator.value); | ||
} | ||
try { | ||
// Use this.DOMNode for components that render as non-native Portals... | ||
node = (0, _reactDom.findDOMNode)(_this2) || _this2.DOMNode; | ||
} catch (e) { | ||
console.warn('[ui-testable] Could not append locator attribute: ' + e); | ||
} | ||
if (node && node.getAttribute) { | ||
var attribute = node.getAttribute(locator.attribute); | ||
var values = typeof attribute === 'string' ? attribute.split(/\s+/) : []; | ||
if (!values.includes(locator.value)) { | ||
values.push(locator.value); | ||
} | ||
node.setAttribute(locator.attribute, values.join(' ')); | ||
} | ||
}); | ||
} | ||
}]); | ||
return TestableComponent; | ||
}(ComposedComponent), _class.displayName = displayName, _class.selector = selector, _temp); | ||
node.setAttribute(locator.attribute, values.join(' ')); | ||
} | ||
}); | ||
} | ||
}]); | ||
return TestableComponent; | ||
}; | ||
} /* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2015 - present Instructure, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
}(ComposedComponent), _class.selector = selector, _temp); | ||
exports.default = testable; | ||
return TestableComponent; | ||
}); |
211
lib/index.js
@@ -29,128 +29,123 @@ 'use strict'; | ||
var _uiDecorator = require('@instructure/ui-decorator'); | ||
var _uiDecorator2 = _interopRequireDefault(_uiDecorator); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function testable() { | ||
return function (ComposedComponent) { | ||
var _class, _temp; | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2015 - present Instructure, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
var displayName = ComposedComponent.displayName || ComposedComponent.name; | ||
var locator = { | ||
attribute: 'data-uid', | ||
value: displayName | ||
}; | ||
var selector = '[' + locator.attribute + '~="' + locator.value + '"]'; | ||
exports.default = (0, _uiDecorator2.default)(function (ComposedComponent) { | ||
var _class, _temp; | ||
var TestableComponent = (_temp = _class = function (_ComposedComponent) { | ||
(0, _inherits3.default)(TestableComponent, _ComposedComponent); | ||
var displayName = ComposedComponent.displayName || ComposedComponent.name; | ||
var locator = { | ||
attribute: 'data-uid', | ||
value: displayName | ||
}; | ||
var selector = '[' + locator.attribute + '~="' + locator.value + '"]'; | ||
var TestableComponent = (_temp = _class = function (_ComposedComponent) { | ||
(0, _inherits3.default)(TestableComponent, _ComposedComponent); | ||
function TestableComponent() { | ||
(0, _classCallCheck3.default)(this, TestableComponent); | ||
return (0, _possibleConstructorReturn3.default)(this, (TestableComponent.__proto__ || Object.getPrototypeOf(TestableComponent)).apply(this, arguments)); | ||
} | ||
function TestableComponent() { | ||
(0, _classCallCheck3.default)(this, TestableComponent); | ||
return (0, _possibleConstructorReturn3.default)(this, (TestableComponent.__proto__ || Object.getPrototypeOf(TestableComponent)).apply(this, arguments)); | ||
} | ||
(0, _createClass3.default)(TestableComponent, [{ | ||
key: 'componentDidMount', | ||
value: function componentDidMount() { | ||
if ((0, _get6.default)(TestableComponent.prototype.__proto__ || Object.getPrototypeOf(TestableComponent.prototype), 'componentDidMount', this)) { | ||
var _get2; | ||
(0, _createClass3.default)(TestableComponent, [{ | ||
key: 'componentDidMount', | ||
value: function componentDidMount() { | ||
if ((0, _get6.default)(TestableComponent.prototype.__proto__ || Object.getPrototypeOf(TestableComponent.prototype), 'componentDidMount', this)) { | ||
var _get2; | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
(_get2 = (0, _get6.default)(TestableComponent.prototype.__proto__ || Object.getPrototypeOf(TestableComponent.prototype), 'componentDidMount', this)).call.apply(_get2, [this].concat(args)); | ||
} | ||
this.appendLocatorAttribute(); | ||
(_get2 = (0, _get6.default)(TestableComponent.prototype.__proto__ || Object.getPrototypeOf(TestableComponent.prototype), 'componentDidMount', this)).call.apply(_get2, [this].concat(args)); | ||
} | ||
}, { | ||
key: 'componentDidUpdate', | ||
value: function componentDidUpdate() { | ||
if ((0, _get6.default)(TestableComponent.prototype.__proto__ || Object.getPrototypeOf(TestableComponent.prototype), 'componentDidUpdate', this)) { | ||
var _get3; | ||
this.appendLocatorAttribute(); | ||
} | ||
}, { | ||
key: 'componentDidUpdate', | ||
value: function componentDidUpdate() { | ||
if ((0, _get6.default)(TestableComponent.prototype.__proto__ || Object.getPrototypeOf(TestableComponent.prototype), 'componentDidUpdate', this)) { | ||
var _get3; | ||
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
(_get3 = (0, _get6.default)(TestableComponent.prototype.__proto__ || Object.getPrototypeOf(TestableComponent.prototype), 'componentDidUpdate', this)).call.apply(_get3, [this].concat(args)); | ||
} | ||
this.appendLocatorAttribute(); | ||
(_get3 = (0, _get6.default)(TestableComponent.prototype.__proto__ || Object.getPrototypeOf(TestableComponent.prototype), 'componentDidUpdate', this)).call.apply(_get3, [this].concat(args)); | ||
} | ||
}, { | ||
key: 'componentWillUnmount', | ||
value: function componentWillUnmount() { | ||
this._testableUnmounted = true; | ||
if ((0, _get6.default)(TestableComponent.prototype.__proto__ || Object.getPrototypeOf(TestableComponent.prototype), 'componentWillUnmount', this)) { | ||
var _get4; | ||
this.appendLocatorAttribute(); | ||
} | ||
}, { | ||
key: 'componentWillUnmount', | ||
value: function componentWillUnmount() { | ||
this._testableUnmounted = true; | ||
if ((0, _get6.default)(TestableComponent.prototype.__proto__ || Object.getPrototypeOf(TestableComponent.prototype), 'componentWillUnmount', this)) { | ||
var _get4; | ||
for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
args[_key3] = arguments[_key3]; | ||
} | ||
for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
args[_key3] = arguments[_key3]; | ||
} | ||
(_get4 = (0, _get6.default)(TestableComponent.prototype.__proto__ || Object.getPrototypeOf(TestableComponent.prototype), 'componentWillUnmount', this)).call.apply(_get4, [this].concat(args)); | ||
} | ||
clearTimeout(this.locatorTimeout); | ||
(_get4 = (0, _get6.default)(TestableComponent.prototype.__proto__ || Object.getPrototypeOf(TestableComponent.prototype), 'componentWillUnmount', this)).call.apply(_get4, [this].concat(args)); | ||
} | ||
}, { | ||
key: 'appendLocatorAttribute', | ||
value: function appendLocatorAttribute() { | ||
var _this2 = this; | ||
clearTimeout(this.locatorTimeout); | ||
} | ||
}, { | ||
key: 'appendLocatorAttribute', | ||
value: function appendLocatorAttribute() { | ||
var _this2 = this; | ||
this.locatorTimeout = setTimeout(function () { | ||
var node = void 0; | ||
if (_this2._testableUnmounted) { | ||
return; | ||
this.locatorTimeout = setTimeout(function () { | ||
var node = void 0; | ||
if (_this2._testableUnmounted) { | ||
return; | ||
} | ||
try { | ||
// Use this.DOMNode for components that render as non-native Portals... | ||
node = (0, _reactDom.findDOMNode)(_this2) || _this2.DOMNode; | ||
} catch (e) { | ||
console.warn('[ui-testable] Could not append locator attribute: ' + e); | ||
} | ||
if (node && node.getAttribute) { | ||
var attribute = node.getAttribute(locator.attribute); | ||
var values = typeof attribute === 'string' ? attribute.split(/\s+/) : []; | ||
if (!values.includes(locator.value)) { | ||
values.push(locator.value); | ||
} | ||
try { | ||
// Use this.DOMNode for components that render as non-native Portals... | ||
node = (0, _reactDom.findDOMNode)(_this2) || _this2.DOMNode; | ||
} catch (e) { | ||
console.warn('[ui-testable] Could not append locator attribute: ' + e); | ||
} | ||
if (node && node.getAttribute) { | ||
var attribute = node.getAttribute(locator.attribute); | ||
var values = typeof attribute === 'string' ? attribute.split(/\s+/) : []; | ||
if (!values.includes(locator.value)) { | ||
values.push(locator.value); | ||
} | ||
node.setAttribute(locator.attribute, values.join(' ')); | ||
} | ||
}); | ||
} | ||
}]); | ||
return TestableComponent; | ||
}(ComposedComponent), _class.displayName = displayName, _class.selector = selector, _temp); | ||
node.setAttribute(locator.attribute, values.join(' ')); | ||
} | ||
}); | ||
} | ||
}]); | ||
return TestableComponent; | ||
}; | ||
} /* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2015 - present Instructure, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
}(ComposedComponent), _class.selector = selector, _temp); | ||
exports.default = testable; | ||
return TestableComponent; | ||
}); |
{ | ||
"name": "@instructure/ui-testable", | ||
"version": "5.39.0-rc.5", | ||
"version": "5.39.0-rc.6", | ||
"description": "A UI component test utility made by Instructure Inc.", | ||
@@ -24,6 +24,9 @@ "author": "Instructure, Inc. Engineering and Product Design", | ||
"devDependencies": { | ||
"@instructure/ui-presets": "^5.39.0-rc.5", | ||
"@instructure/ui-test-utils": "^5.39.0-rc.5", | ||
"@instructure/ui-presets": "^5.39.0-rc.6", | ||
"@instructure/ui-test-utils": "^5.39.0-rc.6", | ||
"prop-types": "^15.6.2" | ||
}, | ||
"dependencies": { | ||
"@instructure/ui-decorator": "^5.39.0-rc.6" | ||
}, | ||
"peerDependencies": { | ||
@@ -36,3 +39,3 @@ "react": "^0.14.9 || ^15.0.0 || ^16.0.0", | ||
}, | ||
"gitHead": "7a669e544e4dad3777f2f6631ac0dd8f456796ea" | ||
"gitHead": "81791866fe7358ffb34708e21250de8546e6e5d9" | ||
} |
110
src/index.js
@@ -27,70 +27,56 @@ /* | ||
function testable () { | ||
return function (ComposedComponent) { | ||
const displayName = ComposedComponent.displayName || ComposedComponent.name | ||
const locator = { | ||
attribute: 'data-uid', | ||
value: displayName | ||
} | ||
const selector = `[${locator.attribute}~="${locator.value}"]` | ||
import decorator from '@instructure/ui-decorator' | ||
class TestableComponent extends ComposedComponent { | ||
static displayName = displayName | ||
static selector = selector | ||
componentDidMount (...args) { | ||
if (super.componentDidMount) { | ||
super.componentDidMount(...args) | ||
} | ||
this.appendLocatorAttribute() | ||
export default decorator((ComposedComponent) => { | ||
const displayName = ComposedComponent.displayName || ComposedComponent.name | ||
const locator = { | ||
attribute: 'data-uid', | ||
value: displayName | ||
} | ||
const selector = `[${locator.attribute}~="${locator.value}"]` | ||
class TestableComponent extends ComposedComponent { | ||
static selector = selector | ||
componentDidMount (...args) { | ||
if (super.componentDidMount) { | ||
super.componentDidMount(...args) | ||
} | ||
componentDidUpdate (...args) { | ||
if (super.componentDidUpdate) { | ||
super.componentDidUpdate(...args) | ||
} | ||
this.appendLocatorAttribute() | ||
this.appendLocatorAttribute() | ||
} | ||
componentDidUpdate (...args) { | ||
if (super.componentDidUpdate) { | ||
super.componentDidUpdate(...args) | ||
} | ||
componentWillUnmount (...args) { | ||
this._testableUnmounted = true | ||
if (super.componentWillUnmount) { | ||
super.componentWillUnmount(...args) | ||
this.appendLocatorAttribute() | ||
} | ||
componentWillUnmount (...args) { | ||
this._testableUnmounted = true | ||
if (super.componentWillUnmount) { | ||
super.componentWillUnmount(...args) | ||
} | ||
clearTimeout(this.locatorTimeout) | ||
} | ||
appendLocatorAttribute () { | ||
this.locatorTimeout = setTimeout(() => { | ||
let node | ||
if (this._testableUnmounted) { | ||
return | ||
} | ||
clearTimeout(this.locatorTimeout) | ||
} | ||
appendLocatorAttribute () { | ||
this.locatorTimeout = setTimeout(() => { | ||
let node | ||
if (this._testableUnmounted) { | ||
return | ||
try { | ||
// Use this.DOMNode for components that render as non-native Portals... | ||
node = findDOMNode(this) || this.DOMNode | ||
} catch (e) { | ||
console.warn(`[ui-testable] Could not append locator attribute: ${e}`) | ||
} | ||
if (node && node.getAttribute) { | ||
const attribute = node.getAttribute(locator.attribute) | ||
const values = typeof attribute === 'string' ? attribute.split(/\s+/) : [] | ||
if (!values.includes(locator.value)) { | ||
values.push(locator.value) | ||
} | ||
try { | ||
// Use this.DOMNode for components that render as non-native Portals... | ||
node = findDOMNode(this) || this.DOMNode | ||
} catch (e) { | ||
console.warn(`[ui-testable] Could not append locator attribute: ${e}`) | ||
} | ||
if (node && node.getAttribute) { | ||
const attribute = node.getAttribute(locator.attribute) | ||
const values = typeof attribute === 'string' ? attribute.split(/\s+/) : [] | ||
if (!values.includes(locator.value)) { | ||
values.push(locator.value) | ||
} | ||
node.setAttribute(locator.attribute, values.join(' ')) | ||
} | ||
}) | ||
} | ||
node.setAttribute(locator.attribute, values.join(' ')) | ||
} | ||
}) | ||
} | ||
return TestableComponent | ||
} | ||
} | ||
export default testable | ||
return TestableComponent | ||
}) |
20257
-1.36%3
50%320
-0.93%+ Added
+ Added
+ Added