describe('<AboutPage />', () => { it('should have a header called \'About\'', () => { const wrapper = shallow(<AboutPage />); const actual = wrapper.find('h2').text(); const expected = 'About'; expect(actual).toEqual(expected); }); it('should have a header with \'alt-header\' class', () => { const wrapper = shallow(<AboutPage />); const actual = wrapper.find('h2').prop('className'); const expected = 'alt-header'; expect(actual).toEqual(expected); }); it('should link to an unknown route path', () => { const wrapper = shallow(<AboutPage />); const actual = wrapper.findWhere(n => n.prop('to') === '/badlink').length; const expected = 1; expect(actual).toEqual(expected); }); });
describe('ChangeAccountType Component', () => { const comp = ( <Provider store={mockStore}> <ChangeAccountType /> </Provider> ) it('should match snapshot', () => { const tree = create(comp).toJSON() expect(tree).toMatchSnapshot() }) const simulate = (wrapper, type) => wrapper.find('select').simulate('change', { target: { value: type }, }) it('should change accountType when select is changed', () => { const wrapper = shallow(<PureChangeAccountType />) simulate(wrapper, 'private') expect(wrapper.find('.type_indicator').text()).toEqual('private') // simulate again simulate(wrapper, 'public') expect(wrapper.find('.type_indicator').text()).toEqual('public') }) })
describe('MapConversations Component', () => { let mockFn = jest.fn() it('should match snapshot', () => { const tree = create( <Provider store={mockStore}> <MapConversations showConversation={mockFn} /> </Provider> ).toJSON() expect(tree).toMatchSnapshot() }) it('should match snapshot when conversations.length == 0', () => { Message.conversations = [] const wrapper = shallow( <PureMapConversations showConversation={mockFn} conversations={Message.conversations} /> ) expect(wrapper.find('.con_count').text()).toEqual('No conversations') expect(wrapper.find('Nothing').exists()).toBe(true) }) })
test('sets updatedAt time', t => { const wrapper = shallow(<NumberWidget socket={mockServer} name="Test" title="Number" />); const mockDate = '12/12/1212 12:00'; wrapper.setState({ time: 2000, status: 200, updatedAt: mockDate }); t.is(wrapper.find('.widget__updatedAt').text(), mockDate); wrapper.setState({ updatedAt: undefined }); t.is(wrapper.find('.widget__updatedAt').length, 0); });
it('should render invalid cycle detected', () => { const data = { type: 'service', operations: {}, invalidCycleDetected: true }; const wrapper = shallow(<Tooltip x={1} y={1} visible type="line" data={data} />); expect(/Invalid cycle detected/.test(wrapper.find('[data-issue]').text())).to.equal(true); });
describe('<span />', () => { it('should render span', () => { const wrapper = setup(); expect(wrapper.find('span')).to.have.length(2); expect(wrapper.find('span').at(1).text()).to.equal('Boards'); }) })
test('renders sucessfully', t => { const wrapper = shallow(<BuildStatusWidget socket={mockServer} name="Test" title="BuildStatus" />); t.is(wrapper.find('.widget__title').length, 1); t.is(wrapper.find('.widget__value').length, 1); t.is(wrapper.find('.widget__title').text(), 'BuildStatus'); });
describe('<ChaosMetrics />', () => { test('Whenever no data is passed, error metric shows zero', () => { const wrapper = shallow(<ChaosMetrics apiCalls="0" apiErrors="0" apiIsAlive="0" latency="0"/>); expect(wrapper.find("[data-test-id='errorsLabel']").text()).toBe("0"); }); });
describe('Notification - change props', () => { it('should render p component', () => { const wrapper = setup(); wrapper.setProps({ errorMessages: ['There is an error'] }); expect(wrapper.find('p')).to.have.length(1); expect(wrapper.find('p').text()).to.equal('There is an error'); }) })
describe('<h3 />', () => { it('should render h3', () => { const wrapper = setupShallow(); expect(wrapper.find('h3')).to.have.length(1); }) it('should render h3 content', () => { const wrapper = setupShallow(); const boardTitle = 'Board Title'; wrapper.setProps({ boardTitle }); expect(wrapper.find('h3').text()).to.equal(boardTitle); }) })
test('sets updatedAt time', t => { const wrapper = shallow(<SparklineWidget socket={mockServer} name="Test" title="Sparky" />); const mockDate = '12/12/1212 12:00'; wrapper.setState({ time: 2000, status: 200, updatedAt: mockDate }); t.is(wrapper.find('.widget__updatedAt').text(), mockDate); wrapper.setState({ updatedAt: undefined }); t.is(wrapper.find('.widget__updatedAt').length, 0); });
test('renders sucessfully', t => { const wrapper = shallow(<TextWidget socket={mockServer} name="Test" title="Batman" />); t.is(wrapper.find('.widget__title').length, 1); t.is(wrapper.find('.widget__value').length, 1); t.is(wrapper.find('.widget__title').text(), 'Batman'); });
test('sets updatedAt time', t => { const wrapper = shallow(<BuildStatusWidget socket={mockServer} name="Test" title="Number" />); const mockDate = '12/12/1212 12:00'; wrapper.setState({ time: 2000, status: 200, updatedAt: mockDate }); t.is(wrapper.find('.widget__updatedAt').text(), mockDate); wrapper.setState({ updatedAt: undefined }); t.is(wrapper.find('.widget__updatedAt').length, 0); });