maisonsport-common-ui
Version:
Suite of styled-components to be consumed by the React-Native App and by the Web (via React-Native for Web)
140 lines (117 loc) • 5.43 kB
JavaScript
"use strict";
var _react = _interopRequireDefault(require("react"));
var _reactNative = require("@testing-library/react-native");
var _index = _interopRequireWildcard(require("./index"));
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const options = [{
value: 'en',
label: 'English'
}];
const placeholderText = 'Placeholder texteroony';
describe('SelectBox', () => {
test('@prop: placeholder', () => {
const {
getByTestId
} = (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
placeholder: placeholderText,
value: "",
options: options,
onSelect: () => {}
}));
const selectText = getByTestId(_index.selectBoxSelectedValueText);
expect(selectText.children[0]).toEqual(placeholderText);
});
test('@prop: value', () => {
const selectedOption = options[0];
const {
getByTestId
} = (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
placeholder: placeholderText,
value: selectedOption.value,
options: options,
onSelect: () => {}
}));
const selectText = getByTestId(_index.selectBoxSelectedValueText);
expect(selectText.children[0]).toEqual(selectedOption.label);
});
test('@prop: onSelect', () => {
const onPress = jest.fn();
const {
getByTestId
} = (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
placeholder: placeholderText,
value: "",
options: options,
onSelect: onPress
}));
const selectBox = getByTestId(_index.selectBoxID);
_reactNative.fireEvent.press(selectBox);
const option = getByTestId("".concat(_index.selectBoxOption, "_").concat(options[0].value));
_reactNative.fireEvent.press(option);
expect(onPress).toHaveBeenCalledWith(options[0].value);
});
test('Pressing on the SelectBox should toggle the menu.', () => {
const {
getByTestId
} = (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
placeholder: placeholderText,
value: "",
options: options,
onSelect: () => {}
}));
const selectBox = getByTestId(_index.selectBoxID);
expect(() => getByTestId(_index.selectBoxOptionsContainer)).toThrow();
_reactNative.fireEvent.press(selectBox);
expect(getByTestId(_index.selectBoxOptionsContainer)).toBeTruthy();
_reactNative.fireEvent.press(selectBox);
expect(() => getByTestId(_index.selectBoxOptionsContainer)).toThrow();
});
test('Choosing an Option should close the menu.', () => {
const {
getByTestId
} = (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
placeholder: placeholderText,
value: "",
options: options,
onSelect: () => {}
}));
const selectBox = getByTestId(_index.selectBoxID);
_reactNative.fireEvent.press(selectBox);
const option = getByTestId("".concat(_index.selectBoxOption, "_").concat(options[0].value));
_reactNative.fireEvent.press(option);
expect(() => getByTestId(_index.selectBoxOptionsContainer)).toThrow();
});
test('The selected Option should have a check icon.', () => {
const selectedValue = options[0].value;
const {
getByTestId
} = (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
placeholder: placeholderText,
value: selectedValue,
options: options,
onSelect: () => {}
}));
const selectBox = getByTestId(_index.selectBoxID);
_reactNative.fireEvent.press(selectBox);
const checkMark = getByTestId("".concat(_index.selectBoxOptionCheckID, "_").concat(selectedValue));
expect(checkMark).toBeTruthy();
});
test('SelectBox Option should display option.label', () => {
const selectedOption = options[0];
const {
getByTestId
} = (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
placeholder: placeholderText,
value: selectedOption.value,
options: options,
onSelect: () => {}
}));
const selectBox = getByTestId(_index.selectBoxID);
_reactNative.fireEvent.press(selectBox);
const optionText = getByTestId("".concat(_index.selectBoxOptionTextID, "_").concat(selectedOption.value));
expect(optionText.children[0]).toBe(selectedOption.label);
});
});
//# sourceMappingURL=selectbox.test.js.map