Store x position into marks

jh-changes
Shin'ya Ueoka 6 years ago
parent e6d990966a
commit f66e75575d
  1. 3
      src/content/actions/mark.js
  2. 2
      src/content/reducers/mark.js
  3. 3
      test/content/actions/mark.test.js
  4. 8
      test/content/reducers/mark.test.js

@ -12,10 +12,11 @@ const cancel = () => {
return { type: actions.MARK_CANCEL }; return { type: actions.MARK_CANCEL };
}; };
const setLocal = (key, y) => { const setLocal = (key, x, y) => {
return { return {
type: actions.MARK_SET_LOCAL, type: actions.MARK_SET_LOCAL,
key, key,
x,
y, y,
}; };
}; };

@ -16,7 +16,7 @@ export default function reducer(state = defaultState, action = {}) {
return { ...state, setMode: false, jumpMode: false }; return { ...state, setMode: false, jumpMode: false };
case actions.MARK_SET_LOCAL: { case actions.MARK_SET_LOCAL: {
let marks = { ...state.marks }; let marks = { ...state.marks };
marks[action.key] = { y: action.y }; marks[action.key] = { x: action.x, y: action.y };
return { ...state, setMode: false, marks }; return { ...state, setMode: false, marks };
} }
default: default:

@ -25,9 +25,10 @@ describe('mark actions', () => {
describe('setLocal', () => { describe('setLocal', () => {
it('create setLocal action', () => { it('create setLocal action', () => {
let action = markActions.setLocal('a', 30); let action = markActions.setLocal('a', 20, 30);
expect(action.type).to.equal(actions.MARK_SET_LOCAL); expect(action.type).to.equal(actions.MARK_SET_LOCAL);
expect(action.key).to.equal('a'); expect(action.key).to.equal('a');
expect(action.x).to.equal(20);
expect(action.y).to.equal(30); expect(action.y).to.equal(30);
}); });
}); });

@ -31,9 +31,11 @@ describe("mark reducer", () => {
}); });
it('stores local mark', () => { it('stores local mark', () => {
let action = { type: actions.MARK_SET_LOCAL, key: 'a', y: 10 }; let action = { type: actions.MARK_SET_LOCAL, key: 'a', x: 20, y: 30};
let state = reducer(undefined, action); let state = reducer({ setMode: true }, action);
expect(state.setMode).to.be.false;
expect(state.marks['a']).to.be.an('object') expect(state.marks['a']).to.be.an('object')
expect(state.marks['a'].y).to.equal(10) expect(state.marks['a'].x).to.equal(20)
expect(state.marks['a'].y).to.equal(30)
}); });
}); });