Skip to content

Instantly share code, notes, and snippets.

@masonforest
Created November 30, 2016 16:59
Show Gist options
  • Save masonforest/ec05d32ad37f41637ae8c19ac25b5ac9 to your computer and use it in GitHub Desktop.
Save masonforest/ec05d32ad37f41637ae8c19ac25b5ac9 to your computer and use it in GitHub Desktop.
import React from 'react';
import { Provider } from 'react-redux';
import ContactsContainer from './ContactsContainer';
import ContactsComponent from 'components/Contacts';
import { mountWithIntl } from 'helpers/intl-enzyme-test-helper';
import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import { FULL_SCREEN_MODAL_ACTION_OPEN } from 'modules/FullScreenModal';
import { CONTACT_MODAL } from 'modules/ContactModal';
import { SCHEDULE_MODAL } from 'modules/ScheduleModal';
import { START_CALL_MODAL, VIDEO_CALL, AUDIO_CALL } from 'modules/StartCallModal';
import {
actions,
CONTACTS_FILTER_OPTION_ALL,
CONTACTS_FILTER_OPTION_MY_CONTACTS,
CONTACTS_FILTER_OPTION_AVAILABLE,
CONTACTS_FILTER_CHANGE,
SELECT_CONTACT,
CHAT_WITH,
ROOM_SYSTEMS_FILTER_OPTION_ALL,
MEETINGS_FILTER_OPTION_ALL
} from 'modules/Contact';
describe('(Container) ContactsContainer', () => {
let _wrapper;
it('Should render', (done) => {
const mockStore = configureStore([thunk]);
const store = mockStore({
app: {
contacts: {
filters: {
contacts: CONTACTS_FILTER_OPTION_ALL,
roomSystems: ROOM_SYSTEMS_FILTER_OPTION_ALL,
meetings: MEETINGS_FILTER_OPTION_ALL
}
}
},
nucleus: {
contacts: {
revision: 0,
records: {
1: {
contactType: 'STANDARD',
usageType: 'PERSONAL',
name: 'John Doe'
}
}
}
}
});
_wrapper = mountWithIntl(
<Provider store={store}>
<ContactsContainer />
</Provider>
);
// Get copy of props
let _props = Object.assign({}, _wrapper.find(ContactsComponent).props());
expect(_props.filter).to.equal(CONTACTS_FILTER_OPTION_ALL);
expect(_props.contacts.length).to.equal(1);
expect(_props.contacts[0].name).to.equal('John Doe');
expect(_props.contacts[0].isUser).to.equal(true);
expect(_props.contacts[0].isMeeting).to.equal(false);
expect(_props.contacts[0].isRoomSystem).to.equal(false);
done();
});
it('Should provide personal contacts', (done) => {
const mockStore = configureStore([thunk]);
const store = mockStore({
app: {
contacts: {
filters: {
contacts: CONTACTS_FILTER_OPTION_MY_CONTACTS,
roomSystems: ROOM_SYSTEMS_FILTER_OPTION_ALL,
meetings: MEETINGS_FILTER_OPTION_ALL
}
}
},
nucleus: {
contacts: {
revision: 0,
records: {
1: {
contactType: 'STANDARD',
usageType: 'PERSONAL',
category: 'PERSONAL',
name: 'John Doe'
},
2: {
contactType: 'STANDARD',
usageType: 'PERSONAL',
name: 'Jane Doe'
}
}
}
}
});
_wrapper = mountWithIntl(
<Provider store={store}>
<ContactsContainer />
</Provider>
);
// Get copy of props
let _props = Object.assign({}, _wrapper.find(ContactsComponent).props());
expect(_props.filter).to.equal(CONTACTS_FILTER_OPTION_MY_CONTACTS);
expect(_props.contacts.length).to.equal(1);
expect(_props.contacts[0].name).to.equal('John Doe');
expect(_props.contacts[0].isUser).to.equal(true);
expect(_props.contacts[0].isMeeting).to.equal(false);
expect(_props.contacts[0].isRoomSystem).to.equal(false);
done();
});
it('Should provide available contacts', (done) => {
const mockStore = configureStore([thunk]);
const store = mockStore({
app: {
contacts: {
filters: {
contacts: CONTACTS_FILTER_OPTION_AVAILABLE,
roomSystems: ROOM_SYSTEMS_FILTER_OPTION_ALL,
meetings: MEETINGS_FILTER_OPTION_ALL
}
}
},
nucleus: {
chat: {
presence: {
usersPresence: {
'[email protected]': {
status: 'available'
}
}
}
},
provisioning: {
sip_enablePublishPresence: '1'
},
contacts: {
revision: 0,
records: {
1: {
contactType: 'STANDARD',
usageType: 'PERSONAL',
category: 'PERSONAL',
name: 'John Doe',
extension: '123456',
state: 'AVAILABLE'
},
2: {
contactType: 'STANDARD',
usageType: 'PERSONAL',
name: 'Jane Doe',
extension: '123458'
}
}
}
}
});
_wrapper = mountWithIntl(
<Provider store={store}>
<ContactsContainer />
</Provider>
);
// Get copy of props
let _props = Object.assign({}, _wrapper.find(ContactsComponent).props());
expect(_props.filter).to.equal(CONTACTS_FILTER_OPTION_AVAILABLE);
expect(_props.contacts.length).to.equal(1);
expect(_props.contacts[0].name).to.equal('John Doe');
expect(_props.contacts[0].isUser).to.equal(true);
expect(_props.contacts[0].isMeeting).to.equal(false);
expect(_props.contacts[0].isRoomSystem).to.equal(false);
done();
});
it.only('Should dispatch actions', () => {
const mockStore = configureStore([thunk]);
const store = mockStore({
app: {
contacts: {
filters: {
contacts: CONTACTS_FILTER_OPTION_ALL,
roomSystems: ROOM_SYSTEMS_FILTER_OPTION_ALL,
meetings: MEETINGS_FILTER_OPTION_ALL
}
}
},
nucleus: {
// cluster: 'somecluster',
cluster: {
nodes: [{ systemId: 'node1' }],
selectedNode: 'node1',
},
contacts: {
revision: 0,
records: {
1: {
contactType: 'STANDARD',
usageType: 'PERSONAL',
name: 'John Doe'
}
}
}
}
})
_wrapper = mountWithIntl(
<Provider store={store}>
<ContactsContainer />
</Provider>
);
// Get copy of props
let _props = Object.assign({}, _wrapper.find(ContactsComponent).props());
_props.handleFilterChange('onefilter', 1);
_props.handleCreateContact();
_props.handleSelectContact();
_props.handleSelectContact({ id: 123 });
_props.handleEdit('susan');
_props.handleDelete('erica');
_props.handleFavoriteToggle('bob', true);
_props.handleVideoCall(456);
_props.handleAudioCall(789);
_props.handleChat(555);
_props.handleSchedule(999);
expect(store.getActions()).to.deep.equal([
{
type: SELECT_CONTACT,
payload: {
id: undefined
}
},
{
type: CONTACTS_FILTER_CHANGE,
payload: { type: 'onefilter', value: 1 }
},
{
type: FULL_SCREEN_MODAL_ACTION_OPEN,
payload: {
subComponentType: CONTACT_MODAL,
modalProps: {
isCreate: true
}
}
},
{
type: SELECT_CONTACT,
payload: {
id: undefined
}
},
{
type: SELECT_CONTACT,
payload: {
id: 123
}
},
{
type: FULL_SCREEN_MODAL_ACTION_OPEN,
payload: {
subComponentType: CONTACT_MODAL,
modalProps: {
contact: 'susan'
}
}
},
{
type: FULL_SCREEN_MODAL_ACTION_OPEN,
payload: {
subComponentType: CONTACT_MODAL,
modalProps: {
contact: 'erica',
isDelete: true
}
}
},
{
type: FULL_SCREEN_MODAL_ACTION_OPEN,
payload: {
subComponentType: START_CALL_MODAL,
modalProps: {
id: 456,
type: VIDEO_CALL
}
}
},
{
type: FULL_SCREEN_MODAL_ACTION_OPEN,
payload: {
subComponentType: START_CALL_MODAL,
modalProps: {
id: 789,
type: AUDIO_CALL
}
}
},
{
type: CHAT_WITH,
payload: {
extension: 555
}
},
{
type: FULL_SCREEN_MODAL_ACTION_OPEN,
payload: {
subComponentType: SCHEDULE_MODAL,
modalProps: 999
}
}
]);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment