describe("LoadingSpinner component", () => { it("should render correctly", () => { const wrapper = shallow(<LoadingSpinner customClassName="test-class"/>); expect(shallowToJson(wrapper)).toMatchSnapshot(); expect(wrapper.find('div').length).toBe(1); expect(wrapper.find('div').text()).toBe('...loading'); expect(wrapper.find('div').prop('className')).toBe('test-class'); }); });
describe('Default', () => { it('renders with footer', () => { const component = shallow(<Default title="Title" displayFooter><Child /></Default>); expect(shallowToJson(component)).toMatchSnapshot(); }); it('renders without footer', () => { const component = shallow(<Default title="Title" displayFooter={false}><Child /></Default>); expect(shallowToJson(component)).toMatchSnapshot(); }); });
describe('TodoList', () => { it('renders without crashing', () => { const component = shallow(<TodoList />); expect(shallowToJson(component)).toMatchSnapshot(); }); it('renders with default props', () => { const component = shallow(<TodoList {...defaultProps} />); expect(shallowToJson(component)).toMatchSnapshot(); }); });
describe("User component", () => { it("should render correctly when data is fetching", () => { const wrapper = shallow(<User fetching={true} />); expect(shallowToJson(wrapper)).toMatchSnapshot(); expect(wrapper.find('LoadingSpinnerStyled').length).toBe(1); }); it("should render correctly when some error", () => { const wrapper = shallow(<User errorFlag={true} />); expect(shallowToJson(wrapper)).toMatchSnapshot(); expect(wrapper.find('ErrorStyled').length).toBe(1); }); it("should render correctly when no error and data fetching is done", () => { const wrapper = shallow(<User userDetails={{}} />); expect(shallowToJson(wrapper)).toMatchSnapshot(); expect(wrapper.find('UserView').length).toBe(1); expect(wrapper.find('UserView').prop('userDetails')).toEqual({}); }); });
describe("UserView component", () => { it("should render correctly", () => { const wrapper = shallow(<UserView userDetails={{ firstName: 'test firstName', lastName: 'test lastName'}} />); expect(shallowToJson(wrapper)).toMatchSnapshot(); expect(wrapper.find('h3').length).toBe(1); expect(wrapper.find('div').length).toBe(2); expect(wrapper.find('span').length).toBe(2); expect(wrapper.find('label').length).toBe(2); expect(wrapper.find('h3').text()).toEqual('User Details:'); expect(wrapper.find('span').at(0).text()).toEqual('test firstName'); expect(wrapper.find('span').at(1).text()).toEqual('test lastName'); }); });
describe('AddTodo', () => { it('renders without crashing', () => { const component = shallow(<AddTodo />); expect(shallowToJson(component)).toMatchSnapshot(); }); });
describe('TodoListItem', () => { it('renders with only required props', () => { const component = shallow(<TodoListItem {...requiredProps} />); expect(shallowToJson(component)).toMatchSnapshot(); }); it('renders with only all props', () => { const component = shallow(<TodoListItem {...allProps} />); expect(shallowToJson(component)).toMatchSnapshot(); }); });
describe('Header', () => { it('renders without crashing', () => { const component = shallow(<Header {...defaultProps}>Test</Header>); expect(shallowToJson(component)).toMatchSnapshot(); }); });
describe('SimpleMenu', () => { it('renders without crashing', () => { const component = shallow(<SimpleMenu {...defaultProps} />); expect(shallowToJson(component)).toMatchSnapshot(); }); });
describe('TodoApp', () => { it('renders without crashing', () => { const component = shallow(<Todos />); expect(shallowToJson(component)).toMatchSnapshot(); }); });
describe("User component", () => { it("should render correctly when data is fetching", () => { const wrapper = shallow(<User fetching={true} />); expect(shallowToJson(wrapper)).toMatchSnapshot(); expect(wrapper.find('Styled(LoadingSpinner)').length).toBe(1); }); it("should render correctly when some error", () => { const wrapper = shallow(<User errorFlag={true} />); expect(shallowToJson(wrapper)).toMatchSnapshot(); expect(wrapper.find('styled.div').length).toBe(1); }); it("should render correctly when no error and data fetching is done", () => { const wrapper = shallow(<User userDetails={{}} />); expect(shallowToJson(wrapper)).toMatchSnapshot(); expect(wrapper.find('UserView').length).toBe(1); expect(wrapper.find('UserView').prop('userDetails')).toEqual({}); }); });