Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('* close modal checking inner', () => {
const component: RenderAPI = render(
,
);
fireEvent.press(component.getByTestId(showModalTestId));
fireEvent.press(component.getByTestId(hideModalTestIdInner));
const { output } = shallow(component.getByType(ModalPanel));
expect(output).toMatchSnapshot();
});
it('* emits `onChange` with correct args', () => {
const onChange = jest.fn();
const component: RenderAPI = render(
,
);
const radio: ReactTestInstance = component.getByTestId(childTestId1);
const touchable: ReactTestInstance = radio.findByType(TouchableOpacity);
fireEvent.press(touchable);
expect(onChange).toBeCalledWith(1);
});
it('* emits onChange with correct args', () => {
const onChange = jest.fn();
const component: RenderAPI = renderComponent({
checked: false,
onChange: onChange,
});
fireEvent.press(component.getByType(TouchableOpacity));
expect(onChange).toBeCalledWith(true);
});
it('* should change year to previous', () => {
const calendarRef: React.LegacyRef = React.createRef();
const application: RenderAPI = render(
,
);
const initialDate = calendarRef.current.state.visibleDate;
fireEvent.press(application.getAllByType(TouchableOpacity)[1]);
const visibleDate = calendarRef.current.state.visibleDate;
const expectedDate = new Date(initialDate.getFullYear() - 12, initialDate.getMonth(), initialDate.getDate());
expect(visibleDate).toEqual(expectedDate);
});
it('* modal default center placement calculated properly', () => {
const window: Frame = Frame.window();
const modalStyle: StyleType = {
width: 200,
height: 200,
};
const component: RenderAPI = render(
,
);
fireEvent.press(component.getByTestId(buttonShowModalTestId));
const modalInstance: any = component.getByType(Modal).instance;
const expectedStyle: StyleType = {
top: (window.size.height - modalInstance.contentSize.height) / 2,
left: (window.size.width - modalInstance.contentSize.width) / 2,
};
const baseModalStyles: StyleType[] = component.getByTestId(baseModalTestId).props.style;
const expectedStyleExist: boolean = baseModalStyles[0]
.some((style: StyleType) => stringify(style) === stringify(expectedStyle));
expect(expectedStyleExist).toBe(true);
});
it('* group menu works properly', () => {
const expectedSelectedItem: MenuItemType = { title: 'Option 32' };
const application: RenderAPI = render(
,
);
fireEvent.press(application.getAllByText('Option 3')[0]);
const { selectedIndex: selectedIndex1 } = application.getByType(Menu).props;
expect(selectedIndex1).toBeNull();
fireEvent.press(application.getAllByText('Option 32')[0]);
const { selectedIndex: selectedIndex2 } = application.getByType(Menu).props;
expect(selectedIndex2).toBe(3);
});
it('* emits onPress', () => {
const onPress = jest.fn();
const component: RenderAPI = renderComponent({
onPress: onPress,
});
fireEvent.press(component.getByType(TouchableOpacity));
expect(onPress).toBeCalled();
});
it('* able to change theme', async () => {
const component: RenderAPI = render(
,
);
const touchableComponent: ReactTestInstance = component.getByTestId(themeChangeTouchableTestId);
fireEvent.press(touchableComponent);
const themedComponent: ReactTestInstance = await waitForElement(() => {
return component.getByTestId(themeConsumerTestId);
});
const { theme: themeProp } = themedComponent.props;
expect(json(themeProp)).toEqual(json(themeInverse));
});
onPress={onRightControl2}
/>,
,
]}
/>,
);
const { output } = shallow(component.getByType(TopNavigation));
expect(output).toMatchSnapshot();
fireEvent.press(component.getByTestId(testIdLeftAction));
fireEvent.press(component.getByTestId(testIdRightAction1));
fireEvent.press(component.getByTestId(testIdRightAction2));
fireEvent.press(component.getByTestId(testIdRightAction3));
expect(onLeftControl).toHaveBeenCalled();
expect(onRightControl1).toHaveBeenCalled();
expect(onRightControl2).toHaveBeenCalled();
expect(onRightControl3).toHaveBeenCalled();
});
const component: RenderAPI = render(
,
);
const styledComponent: ReactTestInstance = component.getByTestId(styleConsumerTestId);
expect(styledComponent.props.themedStyle).toMatchSnapshot();
const touchableComponent: ReactTestInstance = component.getByTestId(styleTouchableTestId);
fireEvent.press(touchableComponent);
const styledComponentChanged: ReactTestInstance = await waitForElement(() => {
return component.getByTestId(styleConsumerTestId);
});
expect(styledComponentChanged.props.themedStyle).toMatchSnapshot();
});