@zohodesk/components
Version:
In this Package, we Provide Some Basic Components to Build Web App
266 lines • 7.81 kB
JavaScript
import React from 'react';
import Textarea from "../Textarea";
import { render } from "@testing-library/react";
describe('Textarea component', () => {
const size = ['xsmall', 'small', 'xmedium', 'medium', 'large'];
const resize = ['horizontal', 'vertical', 'both', 'none'];
const variant = ['default', 'primary'];
const borderColor = ['transparent', 'default'];
test('Should be render with the basic set of default props', () => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(Textarea, null));
expect(asFragment()).toMatchSnapshot();
});
test.each(size)('Should render size - %s', size => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(Textarea, {
size: size,
animated: true
}));
expect(asFragment()).toMatchSnapshot();
});
test('Should be render placeholder', () => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(Textarea, {
placeHolder: "TextAreaPlaceHolder"
}));
expect(asFragment()).toMatchSnapshot();
});
test('Should be render needBorder is false', () => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(Textarea, {
needBorder: false
}));
expect(asFragment()).toMatchSnapshot();
});
test('Should be render text', () => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(Textarea, {
text: "TextAreaText"
}));
expect(asFragment()).toMatchSnapshot();
});
test('Should be render isDisabled is true', () => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(Textarea, {
isDisabled: true,
needEffect: false
}));
expect(asFragment()).toMatchSnapshot();
});
test.each(resize)('Should render resize - %s', resize => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(Textarea, {
resize: resize
}));
expect(asFragment()).toMatchSnapshot();
});
test('Should be render maxLength in number', () => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(Textarea, {
maxLength: "11"
}));
expect(asFragment()).toMatchSnapshot();
});
test('Should be render maxLength in string', () => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(Textarea, {
maxLength: "Ten"
}));
expect(asFragment()).toMatchSnapshot();
});
test.each(size)('Should render animated is true - %s', size => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(Textarea, {
size: size,
animated: true
}));
expect(asFragment()).toMatchSnapshot();
});
test.each(size)('Should render animated is false - %s', size => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(Textarea, {
size: size,
animated: false
}));
expect(asFragment()).toMatchSnapshot();
});
test.each(variant)('Should render Varient - %s', variant => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(Textarea, {
variant: variant
}));
expect(asFragment()).toMatchSnapshot();
});
test('to render eleRef prop is a function', () => {
// Create a mock function
const mockEleRef = jest.fn();
render( /*#__PURE__*/React.createElement(Textarea, {
getRef: mockEleRef
}));
expect(mockEleRef).toHaveBeenCalled();
});
test('Should be render isReadOnly is true and needEffect is true', () => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(Textarea, {
isReadOnly: true,
needEffect: true
}));
expect(asFragment()).toMatchSnapshot();
});
test('Should be render isReadOnly is true and needEffect is false', () => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(Textarea, {
isReadOnly: true,
needEffect: false
}));
expect(asFragment()).toMatchSnapshot();
});
test('Should be render isReadOnly is false and needEffect is false', () => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(Textarea, {
isReadOnly: false,
needEffect: false
}));
expect(asFragment()).toMatchSnapshot();
});
test('Should be render isDisabled is true and needEffect is true', () => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(Textarea, {
isDisabled: true,
needEffect: true
}));
expect(asFragment()).toMatchSnapshot();
});
test('Should be render isDisabled is true and needEffect is false', () => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(Textarea, {
isDisabled: true,
needEffect: false
}));
expect(asFragment()).toMatchSnapshot();
});
test('Should be render isDisabled is false and needEffect is false', () => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(Textarea, {
isDisabled: false,
needEffect: false
}));
expect(asFragment()).toMatchSnapshot();
});
test('Should be render autofocus true ', () => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(Textarea, {
autoFocus: true
}));
expect(asFragment()).toMatchSnapshot();
});
test('Should be render needAppearance is false ', () => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(Textarea, {
needAppearance: false
}));
expect(asFragment()).toMatchSnapshot();
});
test('Should be render needReadOnlyStyle is false ', () => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(Textarea, {
needReadOnlyStyle: false
}));
expect(asFragment()).toMatchSnapshot();
});
test.each(borderColor)('Should render borderColor - %s', borderColor => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(Textarea, {
borderColor: borderColor
}));
expect(asFragment()).toMatchSnapshot();
});
test('Should be render htmlId ', () => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(Textarea, {
htmlId: "textAreahtmlId"
}));
expect(asFragment()).toMatchSnapshot();
});
test('rendering ally clearLabel', () => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(Textarea, {
a11y: {
ariaLabel: 'TextAreaAriaLabel',
ariaLabelledby: 'TexareaAriaLabelledby'
}
}));
expect(asFragment()).toMatchSnapshot();
});
test('Should be render customClass ', () => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(Textarea, {
customClass: "textAreaCustomClass"
}));
expect(asFragment()).toMatchSnapshot();
});
test('Should be render rows and cols ', () => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(Textarea, {
size: "default",
rows: "3",
cols: "3"
}));
expect(asFragment()).toMatchSnapshot();
});
test('Should be render rows only ', () => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(Textarea, {
size: "default",
rows: "3"
}));
expect(asFragment()).toMatchSnapshot();
});
test('Should be render cols only ', () => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(Textarea, {
size: "default",
cols: "3"
}));
expect(asFragment()).toMatchSnapshot();
});
test('Should be render custom Attributes ', () => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(Textarea, {
customAttributes: {
disabled: true
}
}));
expect(asFragment()).toMatchSnapshot();
});
});