Created
April 28, 2018 09:17
-
-
Save shalkam/e5e00b4596fdd5133ada1e54333ac512 to your computer and use it in GitHub Desktop.
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
import "regenerator-runtime/runtime"; | |
import React from "react"; | |
import { shallow, mount } from "enzyme"; | |
import sinon from "sinon"; | |
import { reducer as formReducer } from "redux-form"; | |
import { createStore, combineReducers } from "redux"; | |
import { Provider } from "react-redux"; | |
import userReducer from "../../redux/user-reducer"; | |
import ReserveRedux, { Reserve } from "./reserve"; | |
describe("user dashboard reserve form", () => { | |
let subject = null; | |
let submitting; | |
let store; | |
let reset; | |
let action; | |
let onActionResponse; | |
let handleSubmit; | |
let getRates; | |
beforeEach(() => { | |
submitting = false; | |
reset = sinon.spy(); | |
getRates = sinon.spy(); | |
onActionResponse = Promise.resolve(); | |
handleSubmit = fn => fn; | |
}); | |
const buildSubject = () => { | |
action = sinon.stub().returns(onActionResponse); | |
const props = { | |
initialValues: { reservationData: {} }, | |
actions: { reserve: action, getRates }, | |
pending: 0, | |
submitting, | |
fields: {}, | |
handleSubmit, | |
reset, | |
rates: {}, | |
destroy: () => {} | |
}; | |
return shallow(<Reserve {...props} />); | |
}; | |
const buildSubjectWithRedux = () => { | |
action = sinon.stub().returns(onActionResponse); | |
store = createStore( | |
combineReducers({ | |
app: (state = {}) => ({ | |
...state, | |
user: { data: { reservationData: {} } } | |
}), | |
form: formReducer, | |
user: userReducer | |
}) | |
); | |
const props = {}; | |
return mount( | |
<Provider store={store}> | |
<ReserveRedux {...props} /> | |
</Provider> | |
); | |
}; | |
it("calls action reserve on submit", () => { | |
subject = buildSubject(); | |
subject.find("form").simulate("submit"); | |
expect(action.callCount).toEqual(1); | |
expect(getRates.callCount).toEqual(1); | |
}); | |
it("button gets loading state on submit", () => { | |
subject = buildSubjectWithRedux(); | |
const form = subject.find("form"); | |
const currencyButton = subject.find("label").first(); | |
currencyButton.simulate("click"); | |
form.simulate("submit"); | |
expect(subject.find(".btn.loading").exists()).toEqual(true); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment