Skip to content

Instantly share code, notes, and snippets.

@carlosble
Last active April 3, 2017 06:50
Show Gist options
  • Save carlosble/6e9246e00b2a8eaaafb89b1a0bb123e8 to your computer and use it in GitHub Desktop.
Save carlosble/6e9246e00b2a8eaaafb89b1a0bb123e8 to your computer and use it in GitHub Desktop.
Coarse-grained tests
import {mount} from "enzyme";
import ProfileForm from "../components/ProfileForm";
import React from "react";
import {Provider} from "react-redux";
import configureStore from "../store/configureStore";
import {mockServerApi} from "../store/serverApi";
import {createProfilePage} from "../factory";
import * as models from "../models";
import {inputById, simulateChangeInField} from "../utils/testHelper";
import notifier from "../utils/notifications";
import domAttributes from '../components/commons/domIds';
describe("The profile page", () => {
let timeout = 10;
let store, page, props, stubApi, stubProfile, spyNotifier;
/* --- forms identifiers */
let phoneFieldId = 'phone';
let saveProfileButtonId = 'save-profile';
/* --- */
function mountProfilePage() {
let ProfilePage = createProfilePage(stubApi, spyNotifier);
page = mount(
<Provider store={store}>
<ProfilePage profile={stubProfile}/>
</Provider>);
}
beforeEach((done) => {
props = {
profile: models.profile();
};
stubProfile = Object.assign(models.profile(), {
dni: '123456789H',
name: 'Bob',
surname: 'Sponge',
phone: '555123456',
email: '[email protected]'
});
spyNotifier = notifier();
stubApi = mockServerApi();
stubSeverApiForProfile(stubProfile);
store = configureStore(props);
mountProfilePage();
waitForProfileToLoad(done);
}, timeout);
function stubServerApiForProfile(stubApi, profile) {
stubApi.loadProfile = () => {
return Promise.resolve(profile);
};
}
function waitForProfileToLoad(done) {
spyNotifier.stopLoad = () => {
done();
};
}
describe('loads data from server to populate the store so that', () => {
it("shows profile name in the form", () => {
const form = page.find(ProfileForm);
expect(form.length).toBe(1);
expect(form.first().find(inputById(phoneFieldId)).props().value).toBe(stubProfile.phone);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment