-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Shota Matsushita
committed
Nov 23, 2016
1 parent
45cf6e9
commit 6e35133
Showing
9 changed files
with
174 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import test from 'ava'; | ||
import reducer, { INITIAL_STATE } from '../../App/Reducers/InputReducer'; | ||
import Actions from '../../App/Actions/Creators'; | ||
|
||
test('changeLeft', (t) => { | ||
const input = 'New Text'; | ||
const state = reducer(INITIAL_STATE, Actions.inputLeftChange(input)); | ||
t.is(state.left, input); | ||
t.is(state.right, INITIAL_STATE.right); | ||
t.is(state.language, INITIAL_STATE.language); | ||
t.is(state.theme, INITIAL_STATE.theme); | ||
}); | ||
|
||
test('changeRight', (t) => { | ||
const input = 'New Text'; | ||
const state = reducer(INITIAL_STATE, Actions.inputRightChange(input)); | ||
t.is(state.left, INITIAL_STATE.left); | ||
t.is(state.right, input); | ||
t.is(state.language, INITIAL_STATE.language); | ||
t.is(state.theme, INITIAL_STATE.theme); | ||
}); | ||
|
||
test('changeLanguage', (t) => { | ||
const language = 'java'; | ||
const state = reducer(INITIAL_STATE, Actions.inputLanguageChange(language)); | ||
t.is(state.left, INITIAL_STATE.left); | ||
t.is(state.right, INITIAL_STATE.right); | ||
t.is(state.language, language); | ||
t.is(state.theme, INITIAL_STATE.theme); | ||
}); | ||
|
||
test('changeTheme', (t) => { | ||
const theme = 'monokai'; | ||
const state = reducer(INITIAL_STATE, Actions.inputThemeChange(theme)); | ||
t.is(state.left, INITIAL_STATE.left); | ||
t.is(state.right, INITIAL_STATE.right); | ||
t.is(state.language, INITIAL_STATE.language); | ||
t.is(state.theme, theme); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import test from 'ava'; | ||
import reducer, { INITIAL_STATE } from '../../App/Reducers/OutputReducer'; | ||
import Actions from '../../App/Actions/Creators'; | ||
|
||
test('outputResult', (t) => { | ||
const raw = 'raw output'; | ||
const contents = '<html>contents</html>'; | ||
const state = reducer(INITIAL_STATE, Actions.outputDiffResult(raw, contents)); | ||
t.is(state.raw, raw); | ||
t.is(state.contents, contents); | ||
t.is(state.format, INITIAL_STATE.format); | ||
t.is(state.split, INITIAL_STATE.split); | ||
}); | ||
|
||
test('changeFormat', (t) => { | ||
const format = 0; | ||
const state = reducer(INITIAL_STATE, Actions.outputFormatChange(format)); | ||
t.is(state.raw, INITIAL_STATE.raw); | ||
t.is(state.contents, INITIAL_STATE.contents); | ||
t.is(state.format, format); | ||
t.is(state.split, INITIAL_STATE.split); | ||
}); | ||
|
||
test('changeSplit', (t) => { | ||
const split = 'side-by-side'; | ||
const state = reducer(INITIAL_STATE, Actions.outputSplitChange(split)); | ||
t.is(state.raw, INITIAL_STATE.raw); | ||
t.is(state.contents, INITIAL_STATE.contents); | ||
t.is(state.format, INITIAL_STATE.format); | ||
t.is(state.split, split); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import test from 'ava'; | ||
import { take, select, fork } from 'redux-saga/effects'; | ||
import { left, right } from '../../App/Selectors/Input'; | ||
import { format, split } from '../../App/Selectors/Output'; | ||
import Types from '../../App/Actions/Types'; | ||
import { leftWatcher, rightWatcher, formatWatcher, splitWatcher, worker } from '../../App/Sagas/InputSaga'; | ||
|
||
// 呼び出すたびにGeneratorのstepを1つ進める | ||
const stepper = fn => mock => fn.next(mock).value; | ||
|
||
test('leftWatcher step test', (t) => { | ||
const step = stepper(leftWatcher()); | ||
// takeEveryのステップとworker起動のテスト | ||
t.deepEqual(step(), take(Types.INPUT_LEFT_CHANGE)); | ||
t.deepEqual(step(), fork(worker, undefined)); | ||
t.deepEqual(step(), take(Types.INPUT_LEFT_CHANGE)); | ||
}); | ||
|
||
test('rightWatcher step test', (t) => { | ||
const step = stepper(rightWatcher()); | ||
t.deepEqual(step(), take(Types.INPUT_RIGHT_CHANGE)); | ||
t.deepEqual(step(), fork(worker, undefined)); | ||
t.deepEqual(step(), take(Types.INPUT_RIGHT_CHANGE)); | ||
}); | ||
|
||
test('formatWatcher step test', (t) => { | ||
const step = stepper(formatWatcher()); | ||
t.deepEqual(step(), take(Types.OUTPUT_FORMAT_CHANGE)); | ||
t.deepEqual(step(), fork(worker, undefined)); | ||
t.deepEqual(step(), take(Types.OUTPUT_FORMAT_CHANGE)); | ||
}); | ||
|
||
test('splitWatcher step test', (t) => { | ||
const step = stepper(splitWatcher()); | ||
t.deepEqual(step(), take(Types.OUTPUT_SPLIT_CHANGE)); | ||
t.deepEqual(step(), fork(worker, undefined)); | ||
t.deepEqual(step(), take(Types.OUTPUT_SPLIT_CHANGE)); | ||
}); | ||
|
||
test('worker step test', (t) => { | ||
const step = stepper(worker()); | ||
t.deepEqual(step(), select(left)); | ||
t.deepEqual(step(), select(right)); | ||
t.deepEqual(step(), select(format)); | ||
t.deepEqual(step(), select(split)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import test from 'ava'; | ||
import proxyquire from 'proxyquire'; | ||
import DIFF_FORMAT from '../../App/Config/DiffFormat'; | ||
|
||
test('createDiff() フォーマットがunifiedならコンテンツはunified生データが返却される', (t) => { | ||
const diffStub = { | ||
createPatch() { | ||
return 'rawDiff'; | ||
}, | ||
}; | ||
const createDiffMock = proxyquire('../../App/Services/CalculateDiff', { | ||
diff: diffStub, | ||
}); | ||
const expected = ['rawDiff', 'rawDiff']; | ||
t.deepEqual(createDiffMock.createDiff('left', 'right', DIFF_FORMAT.unified, 'line-by-line'), expected); | ||
}); | ||
|
||
test('createDiff() フォーマットがhtmlならコンテンツはhtml変換後のデータが返却される', (t) => { | ||
const diffStub = { | ||
createPatch() { | ||
return 'rawDiff'; | ||
}, | ||
}; | ||
const diff2htmlStub = { | ||
Diff2Html: { | ||
getPrettyHtml() { | ||
return '<html>contents</html>'; | ||
}, | ||
}, | ||
}; | ||
const createDiffMock = proxyquire('../../App/Services/CalculateDiff', { | ||
diff: diffStub, | ||
diff2html: diff2htmlStub, | ||
}); | ||
const expected = ['rawDiff', '<html>contents</html>']; | ||
t.deepEqual(createDiffMock.createDiff('left', 'right', DIFF_FORMAT.html, 'line-by-line'), expected); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters