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-16 21:34:05 -04:00
|
|
|
handleClickRegistration: jest.fn()
|
2019-09-26 09:29:02 -04:00
|
|
|
};
|
|
|
|
const navWrapper = getNavigationWrapper(props);
|
|
|
|
const navInstance = navWrapper.instance();
|
|
|
|
|
2019-10-16 17:59:15 -04:00
|
|
|
// simulate click, with mocked event
|
|
|
|
navWrapper.find('a.registrationLink').simulate('click', {preventDefault () {}});
|
2019-10-16 21:34:05 -04:00
|
|
|
expect(navInstance.props.handleClickRegistration).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-16 21:34:05 -04:00
|
|
|
handleClickRegistration: jest.fn()
|
2019-09-26 09:29:02 -04:00
|
|
|
};
|
|
|
|
const navWrapper = getNavigationWrapper(props);
|
|
|
|
const navInstance = navWrapper.instance();
|
|
|
|
|
2019-10-16 17:59:15 -04:00
|
|
|
navWrapper.find('a.registrationLink').simulate('click', {preventDefault () {}});
|
2019-10-16 21:34:05 -04:00
|
|
|
expect(navInstance.props.handleClickRegistration).toHaveBeenCalled();
|
2019-09-26 09:29:02 -04:00
|
|
|
});
|
|
|
|
});
|