From a1ef0b697d5426fecd082a13385fb0ca51febdb2 Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Mon, 29 May 2017 20:39:10 +0800 Subject: [PATCH] [web] Add tests for js/components/EventLog/EventList.jsx --- .../components/EventLog/EventListSpec.js | 22 ++++++++++++++ .../__snapshots__/EventListSpec.js.snap | 30 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 web/src/js/__tests__/components/EventLog/EventListSpec.js create mode 100644 web/src/js/__tests__/components/EventLog/__snapshots__/EventListSpec.js.snap diff --git a/web/src/js/__tests__/components/EventLog/EventListSpec.js b/web/src/js/__tests__/components/EventLog/EventListSpec.js new file mode 100644 index 000000000..4f14dfba7 --- /dev/null +++ b/web/src/js/__tests__/components/EventLog/EventListSpec.js @@ -0,0 +1,22 @@ +import React from 'react' +import EventLogList from '../../../components/EventLog/EventList' +import TestUtils from 'react-dom/test-utils' + +describe('EventList Component', () => { + let mockEventList = [ + { id: 1, level: 'info', message: 'foo' }, + { id: 2, level: 'error', message: 'bar' } + ], + eventLogList = TestUtils.renderIntoDocument() + + it('should render correctly', () => { + expect(eventLogList.state).toMatchSnapshot() + expect(eventLogList.props).toMatchSnapshot() + }) + + it('should handle componentWillUnmount', () => { + window.removeEventListener = jest.fn() + eventLogList.componentWillUnmount() + expect(window.removeEventListener).toBeCalledWith('resize', eventLogList.onViewportUpdate) + }) +}) diff --git a/web/src/js/__tests__/components/EventLog/__snapshots__/EventListSpec.js.snap b/web/src/js/__tests__/components/EventLog/__snapshots__/EventListSpec.js.snap new file mode 100644 index 000000000..10bcb5983 --- /dev/null +++ b/web/src/js/__tests__/components/EventLog/__snapshots__/EventListSpec.js.snap @@ -0,0 +1,30 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`EventList Component should render correctly 1`] = ` +Object { + "vScroll": Object { + "end": 1, + "paddingBottom": 18, + "paddingTop": 0, + "start": 0, + }, +} +`; + +exports[`EventList Component should render correctly 2`] = ` +Object { + "events": Array [ + Object { + "id": 1, + "level": "info", + "message": "foo", + }, + Object { + "id": 2, + "level": "error", + "message": "bar", + }, + ], + "rowHeight": 18, +} +`;