-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reducer specs #150
Closed
Closed
Reducer specs #150
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,10 @@ build | |
# dependencies | ||
node_modules | ||
|
||
# coverage | ||
coverage | ||
.nyc_output | ||
|
||
# logs | ||
npm-debug.log | ||
|
||
|
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 |
---|---|---|
|
@@ -36,4 +36,5 @@ before_script: | |
- sleep 3 | ||
|
||
script: | ||
- npm test | ||
- npm run lint |
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,171 @@ | ||
import { describe } from 'ava-spec'; | ||
import { | ||
reducer, | ||
initialState, | ||
Session, | ||
Write | ||
} from '../../lib/reducers/sessions'; | ||
import { | ||
SESSION_ADD, | ||
SESSION_PTY_EXIT, | ||
SESSION_USER_EXIT, | ||
SESSION_PTY_DATA, | ||
SESSION_SET_ACTIVE, | ||
SESSION_CLEAR_ACTIVE, | ||
SESSION_URL_SET, | ||
SESSION_URL_UNSET, | ||
SESSION_SET_XTERM_TITLE, | ||
SESSION_SET_PROCESS_TITLE | ||
} from '../../lib/constants/sessions'; | ||
|
||
describe('Sessions reducer', () => { | ||
describe('on @@redux/INIT', it => { | ||
const state = undefined; | ||
const action = { type: '@@redux/INIT' }; | ||
|
||
it('should return initial state', t => { | ||
t.deepEqual(reducer(state, action), initialState); | ||
}); | ||
}); | ||
|
||
describe('on SESSION_ADD', it => { | ||
const state = initialState; | ||
const action = { type: SESSION_ADD, uid: 'mysession', pid: 1, shell: '/my/shell' }; | ||
|
||
it('should add a session to the state based on its uid', t => { | ||
const result = reducer(state, action); | ||
|
||
t.deepEqual(result.sessions, { | ||
mysession: { | ||
uid: 'mysession', title: '', write: null, url: null, cleared: false, shell: 'shell', pid: 1 | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
describe('on SESSION_URL_SET', it => { | ||
const uid = 'mysession'; | ||
const url = '/my/url'; | ||
const state = initialState.setIn(['sessions', uid], Session({ uid })); | ||
const action = { type: SESSION_URL_SET, uid, url }; | ||
|
||
it('should set the url on the action uid\'s session', t => { | ||
const result = reducer(state, action); | ||
|
||
t.is(result.sessions.mysession.url, url); | ||
}); | ||
}); | ||
|
||
describe('on SESSION_URL_UNSET', it => { | ||
const uid = 'mysession'; | ||
const url = '/my/url'; | ||
const state = initialState.setIn(['sessions', uid], Session({ uid, url })); | ||
const action = { type: SESSION_URL_UNSET, uid }; | ||
|
||
it('should assign url as null on the action uid\'s session', t => { | ||
const result = reducer(state, action); | ||
|
||
t.is(result.sessions.mysession.url, null); | ||
}); | ||
}); | ||
|
||
describe('on SESSION_SET_ACTIVE', it => { | ||
const uid = 'mysession'; | ||
const state = initialState.setIn(['sessions', uid], Session({ uid })); | ||
const action = { type: SESSION_SET_ACTIVE, uid }; | ||
|
||
it('should set activeUid on session based on action uid', t => { | ||
const result = reducer(state, action); | ||
|
||
t.is(result.activeUid, uid); | ||
}); | ||
}); | ||
|
||
describe('on SESSION_CLEAR_ACTIVE', it => { | ||
const uid = 'mysession'; | ||
const state = initialState | ||
.setIn(['sessions', uid], Session({ uid })) | ||
.setIn(['activeUid'], uid); | ||
const action = { type: SESSION_CLEAR_ACTIVE }; | ||
|
||
it('should set "cleared: true" on state\'s active session', t => { | ||
const result = reducer(state, action); | ||
|
||
t.true(result.sessions.mysession.cleared); | ||
}); | ||
}); | ||
|
||
describe('on SESSION_PTY_DATA', it => { | ||
const uid = 'mysession'; | ||
const data = { a: 'b' }; | ||
const state = initialState.setIn(['sessions', uid], Session({ uid })); | ||
const action = { type: SESSION_PTY_DATA, uid, data }; | ||
|
||
it('should set write on state based on action data', t => { | ||
const result = reducer(state, action); | ||
|
||
t.deepEqual(result.write, Write(action)); | ||
t.false(result.sessions.mysession.cleared); | ||
}); | ||
}); | ||
|
||
describe('on SESSION_PTY_EXIT', () => { | ||
describe('when session is on state', it => { | ||
const uid = 'mysession'; | ||
const state = initialState.setIn(['sessions', uid], Session({ uid })); | ||
const action = { type: SESSION_PTY_EXIT, uid }; | ||
|
||
it('should remove session from state', t => { | ||
const result = reducer(state, action); | ||
|
||
t.is(result.sessions.mysession, undefined); | ||
}); | ||
}); | ||
|
||
describe('when session is not on state', it => { | ||
const uid = 'mysession'; | ||
const state = initialState.setIn(['sessions', uid], Session({ uid })); | ||
const action = { type: SESSION_PTY_EXIT, uid: 'anotherUid' }; | ||
|
||
it('should return current state', t => { | ||
t.deepEqual(reducer(state, action), state); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('on SESSION_USER_EXIT', it => { | ||
const uid = 'mysession'; | ||
const state = initialState.setIn(['sessions', uid], Session({ uid })); | ||
const action = { type: SESSION_USER_EXIT, uid }; | ||
|
||
it('should remove session from state', t => { | ||
const result = reducer(state, action); | ||
|
||
t.is(result.sessions.mysession, undefined); | ||
}); | ||
}); | ||
|
||
describe('on SESSION_SET_XTERM_TITLE', it => { | ||
const uid = 'mysession'; | ||
const title = 'mytitle'; | ||
const state = initialState.setIn(['sessions', uid], Session({ uid })); | ||
const action = { type: SESSION_SET_XTERM_TITLE, uid, title }; | ||
|
||
it('should set title on session based on action uid', t => { | ||
const result = reducer(state, action); | ||
t.is(result.sessions.mysession.title, title); | ||
}); | ||
}); | ||
|
||
describe('on SESSION_SET_PROCESS_TITLE', it => { | ||
const uid = 'mysession'; | ||
const title = 'mytitle'; | ||
const state = initialState.setIn(['sessions', uid], Session({ uid })); | ||
const action = { type: SESSION_SET_PROCESS_TITLE, uid, title }; | ||
|
||
it('should set title on session based on action uid', t => { | ||
const result = reducer(state, action); | ||
t.is(result.sessions.mysession.title, title); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please pin deps? Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure! will do :)