From 31a45ddaaa46d2f16b05a27b949dfd4ae09fcaa4 Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Sun, 26 Mar 2017 09:34:45 +0800 Subject: [PATCH 1/4] [web] Reach 100% coverage for ducks/settings.js --- web/src/js/__tests__/ducks/settingsSpec.js | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 web/src/js/__tests__/ducks/settingsSpec.js diff --git a/web/src/js/__tests__/ducks/settingsSpec.js b/web/src/js/__tests__/ducks/settingsSpec.js new file mode 100644 index 000000000..325cc8e26 --- /dev/null +++ b/web/src/js/__tests__/ducks/settingsSpec.js @@ -0,0 +1,23 @@ +jest.unmock('../../ducks/settings') +jest.mock('../../utils') + +import reduceSettings from '../../ducks/settings' +import * as SettingsActions from '../../ducks/settings' + +describe('setting reducer', () => { + it('should return initial state', () => { + expect(reduceSettings(undefined, {})).toEqual({}) + }) + + it('should handle receive action', () => { + let action = { type: SettingsActions.RECEIVE, data: 'foo' } + expect(reduceSettings(undefined, action)).toEqual('foo') + }) + + it('should handle update action', () => { + let action = {type: SettingsActions.UPDATE, data: {id: 1} } + expect(reduceSettings(undefined, action)).toEqual({id: 1}) + + expect(reduceSettings(undefined, SettingsActions.update())).toEqual({}) + }) +}) From de9ecb7c300219282252e2b61dd687a12af5d8f5 Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Sun, 26 Mar 2017 09:36:18 +0800 Subject: [PATCH 2/4] [web] Add JS coverage to codecov. --- .travis.yml | 6 ++++-- web/package.json | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index e64bf6d45..d411ac0ba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,8 +52,10 @@ matrix: before_install: - curl -o- -L https://yarnpkg.com/install.sh | bash - export PATH=$HOME/.yarn/bin:$PATH - install: cd web && yarn - script: npm test + install: + - cd web && yarn + - yarn global add codecov + script: npm test && codecov cache: yarn: true directories: diff --git a/web/package.json b/web/package.json index f0b3ae6ad..8e4140bfa 100644 --- a/web/package.json +++ b/web/package.json @@ -13,7 +13,9 @@ ], "unmockedModulePathPatterns": [ "react" - ] + ], + "coverageDirectory":"./coverage", + "collectCoverage": true }, "dependencies": { "bootstrap": "^3.3.7", From 17ac1ff6cb854e145d52f0509f218bbb14fcb2c3 Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Sun, 26 Mar 2017 21:34:47 +0800 Subject: [PATCH 3/4] [web] Exclude src/js/filt/filt.js from coverage report. --- web/package.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/web/package.json b/web/package.json index 8e4140bfa..a1bd6561a 100644 --- a/web/package.json +++ b/web/package.json @@ -15,7 +15,10 @@ "react" ], "coverageDirectory":"./coverage", - "collectCoverage": true + "collectCoverage": true, + "coveragePathIgnorePatterns": [ + "/src/js/filt/filt.js" + ] }, "dependencies": { "bootstrap": "^3.3.7", From 9a604b5cfe8bc8af2d3a087372131ab50788e802 Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Sun, 26 Mar 2017 21:58:47 +0800 Subject: [PATCH 4/4] [web] Minor fixes for the test. --- web/package.json | 10 +++++----- web/src/js/__tests__/ducks/settingsSpec.js | 7 +++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/web/package.json b/web/package.json index a1bd6561a..90ec031ba 100644 --- a/web/package.json +++ b/web/package.json @@ -14,11 +14,11 @@ "unmockedModulePathPatterns": [ "react" ], - "coverageDirectory":"./coverage", - "collectCoverage": true, - "coveragePathIgnorePatterns": [ - "/src/js/filt/filt.js" - ] + "coverageDirectory":"./coverage", + "collectCoverage": true, + "coveragePathIgnorePatterns": [ + "/src/js/filt/filt.js" + ] }, "dependencies": { "bootstrap": "^3.3.7", diff --git a/web/src/js/__tests__/ducks/settingsSpec.js b/web/src/js/__tests__/ducks/settingsSpec.js index 325cc8e26..cb9df9189 100644 --- a/web/src/js/__tests__/ducks/settingsSpec.js +++ b/web/src/js/__tests__/ducks/settingsSpec.js @@ -1,8 +1,7 @@ jest.unmock('../../ducks/settings') jest.mock('../../utils') -import reduceSettings from '../../ducks/settings' -import * as SettingsActions from '../../ducks/settings' +import reduceSettings, * as SettingsActions from '../../ducks/settings' describe('setting reducer', () => { it('should return initial state', () => { @@ -17,7 +16,11 @@ describe('setting reducer', () => { it('should handle update action', () => { let action = {type: SettingsActions.UPDATE, data: {id: 1} } expect(reduceSettings(undefined, action)).toEqual({id: 1}) + }) +}) +describe('setting actions', () => { + it('should be possible to update setting', () => { expect(reduceSettings(undefined, SettingsActions.update())).toEqual({}) }) })