Skip to content

Commit

Permalink
補上一個 commit 的測試
Browse files Browse the repository at this point in the history
這個 commit 可以看到我花那麼多 code 讓語意清楚的效果:這些修改只動到了自
己,修改 AuthForm 和 OrderForm 並不會讓 App 的測試碼也要跟著改動。
  • Loading branch information
Ronmi committed Jul 25, 2016
1 parent fbc9a12 commit 5cc64d9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
18 changes: 9 additions & 9 deletions ui/test/AppTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ describe("<App />", () => {
describe("structure", () => {
it("shows only AuthForm if not logged in", () => {
let api = new FakeAPI();
let wrapper = shallow(<App api={api} errHandler={()=>{}} />);
let wrapper = shallow(<App api={api} alert={()=>{}} />);
expect(wrapper.find("AuthForm")).to.have.length(1);
});
it("shows OrderForm, CurrencySelector and OrderList after loggedin", () => {
let api = new FakeAPI();
let wrapper = shallow(<App api={api} errHandler={()=>{}} />);
let wrapper = shallow(<App api={api} alert={()=>{}} />);
wrapper.setState({authed: true, code: "", data: []});
wrapper.update();
expect(wrapper.find("OrderForm")).to.have.length(1);
Expand All @@ -62,7 +62,7 @@ describe("<App />", () => {
let api = new FakeAPI();
api.will.success();
sinon.spy(api, "Auth");
let wrapper = shallow(<App api={api} errHandler={()=>{}} />);
let wrapper = shallow(<App api={api} alert={()=>{}} />);
helper.emitPincode(wrapper).then(
check(done, () => {
expect(api.Auth).has.been.calledOnce;
Expand All @@ -75,7 +75,7 @@ describe("<App />", () => {
let api = new FakeAPI();
api.will.fail();
sinon.spy(api, "Auth");
let wrapper = shallow(<App api={api} errHandler={()=>{}} />);
let wrapper = shallow(<App api={api} alert={()=>{}} />);
helper.emitPincode(wrapper).then(
() => { done(new Error("Unexpected api success with api.Auth")); },
check(done, () => {
Expand All @@ -88,7 +88,7 @@ describe("<App />", () => {
api.will.success();
api.fakeData = [{when: 1, foreign: 1, local: -1, code: "USD"}];
sinon.spy(api, "ListAll");
let wrapper = shallow(<App api={api} errHandler={()=>{}} />);
let wrapper = shallow(<App api={api} alert={()=>{}} />);
helper.emitPincode(wrapper).then(
check(done, () => {
expect(api.ListAll).has.been.calledOnce;
Expand All @@ -101,7 +101,7 @@ describe("<App />", () => {
let api = new FakeAPI();
api.will.success();
sinon.spy(api, "Add");
let wrapper = shallow(<App api={api} errHandler={()=>{}} />);
let wrapper = shallow(<App api={api} alert={()=>{}} />);
helper.emitPincode(wrapper).then(
check(done, () => {
wrapper.update();
Expand All @@ -119,7 +119,7 @@ describe("<App />", () => {
let order = {when:1, local: -1, foreign: 1, code: "USD"}
let api = new FakeAPI();
api.will.success();
let wrapper = shallow(<App api={api} errHandler={()=>{}} />);
let wrapper = shallow(<App api={api} alert={()=>{}} />);
helper.emitPincode(wrapper).then(
check(done, () => {
wrapper.update();
Expand All @@ -138,7 +138,7 @@ describe("<App />", () => {
let order = {when:1, local: -1, foreign: 1, code: "USD"}
let api = new FakeAPI();
api.will.success();
let wrapper = shallow(<App api={api} errHandler={()=>{}} />);
let wrapper = shallow(<App api={api} alert={()=>{}} />);
helper.emitPincode(wrapper).then(
() => {
wrapper.update();
Expand All @@ -160,7 +160,7 @@ describe("<App />", () => {
let api = new FakeAPI();
sinon.spy(api, "List");
api.will.success();
let wrapper = shallow(<App api={api} errHandler={()=>{}} />);
let wrapper = shallow(<App api={api} alert={()=>{}} />);
helper.emitPincode(wrapper).then(
() => {
wrapper.update();
Expand Down
6 changes: 3 additions & 3 deletions ui/test/components/AuthFormTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import AuthForm from "../../src/components/AuthForm";
let expect = chai.expect;

describe("<AuthForm />", () => {
let wrapper = shallow(<AuthForm submitPincode={() => {}} error={() => {}} />);
let wrapper = shallow(<AuthForm submitPincode={() => {}} formatError={() => {}} />);
it("is a form", () => {
expect(wrapper.is("form")).to.be.true;
});
Expand All @@ -21,7 +21,7 @@ describe("<AuthForm />", () => {
});
it("emits submitPincode event when submitting 6 digit", () => {
let s = sinon.spy();
let wrapper = shallow(<AuthForm submitPincode={s} error={() => {}} />);
let wrapper = shallow(<AuthForm submitPincode={s} formatError={() => {}} />);
wrapper.find('input[name="pin"]').simulate("change", {target: {value: 123456}});
wrapper.find("form").simulate("submit", {preventDefault: function(){}});

Expand All @@ -30,7 +30,7 @@ describe("<AuthForm />", () => {
it("emits only error event when submitting wrong format", () => {
let s = sinon.spy();
let e = sinon.spy();
let wrapper = shallow(<AuthForm submitPincode={s} error={e} />);
let wrapper = shallow(<AuthForm submitPincode={s} formatError={e} />);
wrapper.find('input[name="pin"]').simulate("change", {target: {value: 1234567}});
wrapper.find("form").simulate("submit", {preventDefault: function(){}});

Expand Down
20 changes: 10 additions & 10 deletions ui/test/components/OrderFormTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ describe("<OrderForm />", () => {
EV(wrapper.find('input[name="foreign"]'), "change", 100);
wrapper.find('CurrencySelector').prop("codeSelected")("USD");
};
it("emits only an error event when date format is invalid", () => {
it("emits only an format error event when date format is invalid", () => {
let e = sinon.spy();
let s = sinon.spy();
let wrapper = shallow(<OrderForm submitOrder={s} error={e} />);
let wrapper = shallow(<OrderForm submitOrder={s} formatError={e} />);

preset(wrapper);
EV(wrapper.find('input[name="when"]'), "change", "fail");
Expand All @@ -87,10 +87,10 @@ describe("<OrderForm />", () => {
expect(e).to.be.calledOnce;
expect(s).not.to.be.called;
});
it("emits only an error event when foreign currency format is invalid", () => {
it("emits only an format error event when foreign currency format is invalid", () => {
let e = sinon.spy();
let s = sinon.spy();
let wrapper = shallow(<OrderForm submitOrder={s} error={e} />);
let wrapper = shallow(<OrderForm submitOrder={s} formatError={e} />);

preset(wrapper);
EV(wrapper.find('input[name="foreign"]'), "change", "fail");
Expand All @@ -99,10 +99,10 @@ describe("<OrderForm />", () => {
expect(e).to.be.calledOnce;
expect(s).not.to.be.called;
});
it("emits only an error event when local currency format is invalid", () => {
it("emits only an format error event when local currency format is invalid", () => {
let e = sinon.spy();
let s = sinon.spy();
let wrapper = shallow(<OrderForm submitOrder={s} error={e} />);
let wrapper = shallow(<OrderForm submitOrder={s} formatError={e} />);

preset(wrapper);
EV(wrapper.find('input[name="local"]'), "change", "fail");
Expand All @@ -111,10 +111,10 @@ describe("<OrderForm />", () => {
expect(e).to.be.calledOnce;
expect(s).not.to.be.called;
});
it("emits only an error event when both local and foreign currency are positive", () => {
it("emits only an format error event when both local and foreign currency are positive", () => {
let e = sinon.spy();
let s = sinon.spy();
let wrapper = shallow(<OrderForm submitOrder={s} error={e} />);
let wrapper = shallow(<OrderForm submitOrder={s} formatError={e} />);

preset(wrapper);
EV(wrapper.find('input[name="local"]'), "change", 3300);
Expand All @@ -123,10 +123,10 @@ describe("<OrderForm />", () => {
expect(e).to.be.calledOnce;
expect(s).not.to.be.called;
});
it("emits only an error event when both local and foreign currency are negative", () => {
it("emits only an format error event when both local and foreign currency are negative", () => {
let e = sinon.spy();
let s = sinon.spy();
let wrapper = shallow(<OrderForm submitOrder={s} error={e} />);
let wrapper = shallow(<OrderForm submitOrder={s} formatError={e} />);

preset(wrapper);
EV(wrapper.find('input[name="local"]'), "change", 3300);
Expand Down

0 comments on commit 5cc64d9

Please sign in to comment.