scratch-www/test/unit/components/navigation.test.jsx

71 lines
2.2 KiB
React
Raw Normal View History

2019-09-26 09:29:02 -04:00
const React = require('react');
const {shallowWithIntl} = require('../../helpers/intl-helpers.jsx');
import configureStore from 'redux-mock-store';
const Navigation = require('../../../src/components/navigation/www/navigation.jsx');
const sessionActions = require('../../../src/redux/session.js');
describe('Navigation', () => {
const mockStore = configureStore();
let store;
beforeEach(() => {
2019-09-30 11:28:36 -04:00
store = null;
2019-09-26 09:29:02 -04:00
});
const getNavigationWrapper = props => {
const wrapper = shallowWithIntl(
<Navigation
{...props}
/>
, {context: {store}}
);
return wrapper
.dive() // unwrap redux connect(injectIntl(JoinFlow))
.dive(); // unwrap injectIntl(JoinFlow)
};
2019-10-07 16:20:40 -04:00
test('when using old join flow, clicking Join Scratch calls handleRegistrationRequested', () => {
2019-09-26 09:29:02 -04:00
store = mockStore({
navigation: {
useScratch3Registration: false
},
session: {
status: sessionActions.Status.FETCHED
},
messageCount: {
messageCount: 0
}
});
const props = {
2019-10-07 16:20:40 -04:00
handleRegistrationRequested: jest.fn()
2019-09-26 09:29:02 -04:00
};
const navWrapper = getNavigationWrapper(props);
const navInstance = navWrapper.instance();
navWrapper.find('a.registrationLink').simulate('click');
2019-10-07 16:20:40 -04:00
expect(navInstance.props.handleRegistrationRequested).toHaveBeenCalled();
2019-09-26 09:29:02 -04:00
});
2019-10-07 16:20:40 -04:00
test('when using new join flow, clicking Join Scratch calls handleRegistrationRequested', () => {
2019-09-26 09:29:02 -04:00
store = mockStore({
navigation: {
useScratch3Registration: true
},
session: {
status: sessionActions.Status.FETCHED
},
messageCount: {
messageCount: 0
}
});
const props = {
2019-10-07 16:20:40 -04:00
handleRegistrationRequested: jest.fn()
2019-09-26 09:29:02 -04:00
};
const navWrapper = getNavigationWrapper(props);
const navInstance = navWrapper.instance();
navWrapper.find('a.registrationLink').simulate('click');
2019-10-07 16:20:40 -04:00
expect(navInstance.props.handleRegistrationRequested).toHaveBeenCalled();
2019-09-26 09:29:02 -04:00
});
});