Skip to content

Commit

Permalink
Merge pull request #38 from aepyornis/fix37
Browse files Browse the repository at this point in the history
Fix the annotation visibility toggle
  • Loading branch information
jessp authored Jul 10, 2016
2 parents 0fba366 + 6881b1d commit 0d2eebe
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 3 deletions.
29 changes: 29 additions & 0 deletions app/models/__tests__/Annotation-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
jest.unmock('../Annotation');

import Annotation from '../Annotation';

describe('Annotation', ()=>{

describe('defaults', ()=>{
it('returns an object', ()=> expect(typeof Annotation.defaults()).toEqual('object') );
});

describe('setDefaults', ()=> {

it('provides defaults when given an empty object', () =>{
const a = Annotation.setDefaults({});
expect(a.header).toEqual("Untitled Annotation");
expect(a.text).toEqual('');
expect(a.nodeIds).toEqual([]);
expect(a.captionIds).toEqual([]);
expect(a.edgeIds).toEqual([]);
expect(a.id).toBeDefined();
});

it('merges defaults when provided an annotation object', ()=>{
expect(Annotation.setDefaults({header: "new header"}).header).toEqual('new header');
expect(Annotation.setDefaults({header: "new header"}).nodeIds).toEqual([]);
});
});

});
53 changes: 53 additions & 0 deletions app/reducers/__tests__/annotations-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
jest.unmock("../annotations");
jest.unmock('../../actions');
jest.unmock("../../models/Annotation");
jest.unmock("lodash");

import reducer from "../annotations";
import {loadAnnotations, toggleAnnotations} from '../../actions';

describe("annotations reducer", ()=>{

it("should return initial state", () => {
expect(reducer(undefined, {})).toEqual({list:[], visible: true, currentIndex: 0});
});

it('stores the annotations in state.list when LOAD_ANNOTATIONS is triggered', () =>{
let annotations = [{
id: '123',
header: "header",
text: "some text here",
nodeIds: ["x1","33180","15957"],
edgeIds: [],
captionIds: []
}];


expect(reducer(undefined, loadAnnotations(annotations))).toEqual({
list: [{
id: '123',
header: "header",
text: "some text here",
nodeIds: ["x1","33180","15957"],
edgeIds: [],
captionIds: []
}],
visible: true,
currentIndex: 0
});

});

describe('TOGGLE_ANNOTATIONS', ()=>{

it('flips the visible state from false to true', ()=>{
expect( reducer({visible: false}, toggleAnnotations({})) ).toEqual({visible: true});
});

it('flips the visible state from true to false', ()=>{
expect( reducer({visible: true}, toggleAnnotations({})) ).toEqual({visible: false});
});

});

});
4 changes: 2 additions & 2 deletions app/reducers/annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default function annotations(state = initState, action) {
});

case TOGGLE_ANNOTATIONS:
let visible = typeof action.value == "undefined" ? !state.visible : action.value;
let visible = !state.visible;
return merge({}, state, { visible });

case SWAP_NODE_HIGHLIGHT:
Expand Down Expand Up @@ -122,4 +122,4 @@ export default function annotations(state = initState, action) {
default:
return state;
}
};
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"prod-build": "NODE_ENV=production webpack --display-modules --config webpack.prod.config.js --output-filename=oligrapher.js",
"min-build": "NODE_ENV=production webpack -p --optimize-dedupe --display-modules --config webpack.prod.config.js --output-filename=oligrapher.min.js",
"build-all": "npm run prod-build && npm run min-build",
"test": "jest"
"test": "jest",
"test:watch": "jest --watch"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit 0d2eebe

Please sign in to comment.