@naturacosmeticos/natds-react
Version:
A collection of components from Natura Design System for React
116 lines • 7.47 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable max-lines-per-function */
var React = __importStar(require("react"));
var react_1 = require("@testing-library/react");
var _1 = __importDefault(require("."));
var renderWithTheme_1 = __importDefault(require("../../helpers/renderWithTheme"));
jest.mock('../Ripple/Ripple');
var buttonProps = {
onClick: function () { return ''; },
children: 'button'
};
describe('Button component', function () {
it('should render correctly with default props', function () {
var _a = (0, renderWithTheme_1.default)(React.createElement(_1.default, __assign({}, buttonProps))), styles = _a.styles, component = _a.component;
expect([styles.toString(), component.container]).toMatchSnapshot();
});
it('should call onClick', function () {
var onClickMock = jest.fn();
var getByTestId = (0, renderWithTheme_1.default)(React.createElement(_1.default, __assign({}, buttonProps, { onClick: onClickMock, testID: "btn-enable" }))).component.getByTestId;
react_1.fireEvent.click(getByTestId('btn-enable'));
expect(onClickMock).toHaveBeenCalled();
});
it('should not call onClick when is disabled', function () {
var onClickMock = jest.fn();
var getByTestId = (0, renderWithTheme_1.default)(React.createElement(_1.default, __assign({}, buttonProps, { disabled: true, onClick: onClickMock, testID: "btn-disabled" }))).component.getByTestId;
react_1.fireEvent.click(getByTestId('btn-disabled'));
expect(getByTestId('btn-disabled')).toBeDisabled();
expect(onClickMock).not.toHaveBeenCalled();
});
it('should render correctly when the size is semi', function () {
var _a = (0, renderWithTheme_1.default)(React.createElement(_1.default, __assign({}, buttonProps, { size: "semi" }))), styles = _a.styles, component = _a.component;
expect([styles.toString(), component.container]).toMatchSnapshot();
});
it('should render correctly when the size is medium', function () {
var _a = (0, renderWithTheme_1.default)(React.createElement(_1.default, __assign({}, buttonProps, { size: "medium" }))), styles = _a.styles, component = _a.component;
expect([styles.toString(), component.container]).toMatchSnapshot();
});
it('should render correctly when the fullWidth is true', function () {
var _a = (0, renderWithTheme_1.default)(React.createElement(_1.default, __assign({}, buttonProps, { fullWidth: true }))), styles = _a.styles, component = _a.component;
expect([styles.toString(), component.container]).toMatchSnapshot();
});
it('should render correctly when the variant is contained and disabled is true', function () {
var _a = (0, renderWithTheme_1.default)(React.createElement(_1.default, __assign({}, buttonProps, { disabled: true, testID: "btn-disabled" }))), styles = _a.styles, component = _a.component;
expect(component.getByTestId('btn-disabled')).toBeDisabled();
expect([styles.toString(), component.container]).toMatchSnapshot();
});
it('should render correctly when the variant is outlined', function () {
var _a = (0, renderWithTheme_1.default)(React.createElement(_1.default, __assign({}, buttonProps, { variant: "outlined" }))), styles = _a.styles, component = _a.component;
expect([styles.toString(), component.container]).toMatchSnapshot();
});
it('should render correctly when the variant is text', function () {
var _a = (0, renderWithTheme_1.default)(React.createElement(_1.default, __assign({}, buttonProps, { variant: "text" }))), styles = _a.styles, component = _a.component;
expect([styles.toString(), component.container]).toMatchSnapshot();
});
it('should render correctly when the variant is text and is disabled', function () {
var _a = (0, renderWithTheme_1.default)(React.createElement(_1.default, __assign({}, buttonProps, { variant: "text", disabled: true }))), styles = _a.styles, component = _a.component;
expect([styles.toString(), component.container]).toMatchSnapshot();
});
it('should render correctly when the variant is outlined and is disabled', function () {
var _a = (0, renderWithTheme_1.default)(React.createElement(_1.default, __assign({}, buttonProps, { variant: "outlined", disabled: true }))), styles = _a.styles, component = _a.component;
expect([styles.toString(), component.container]).toMatchSnapshot();
});
it('should render icon to the right as default when the showIcon is true', function () {
var _a = (0, renderWithTheme_1.default)(React.createElement(_1.default, __assign({}, buttonProps, { showIcon: true, iconName: "outlined-default-mockup" }))), styles = _a.styles, component = _a.component;
expect([styles.toString(), component.container]).toMatchSnapshot();
});
it('should render icon to the left when the showIcon is true and iconPosition is left', function () {
var _a = (0, renderWithTheme_1.default)(React.createElement(_1.default, __assign({}, buttonProps, { showIcon: true, iconPosition: "left", iconName: "outlined-default-mockup" }))), styles = _a.styles, component = _a.component;
expect(component.getByTestId('icon-outlined-default-mockup')).toBeTruthy();
expect([styles.toString(), component.container]).toMatchSnapshot();
});
it('should render correctly with the given icon name', function () {
var _a = (0, renderWithTheme_1.default)(React.createElement(_1.default, __assign({}, buttonProps, { showIcon: true, iconName: "filled-action-check" }))), styles = _a.styles, component = _a.component;
expect(component.getByTestId('icon-filled-action-check')).toBeTruthy();
expect([styles.toString(), component.container]).toMatchSnapshot();
});
});
//# sourceMappingURL=Button.test.js.map