import React from 'react';
import {shallow} from 'enzyme';
import {browserHistory} from 'react-router';
import withEnvironmentInQueryString from 'app/utils/withEnvironmentInQueryString';
import LatestContextStore from 'app/stores/latestContextStore';
class BasicComponent extends React.Component {
render() {
return
test component
;
}
}
const WrappedComponent = withEnvironmentInQueryString(BasicComponent);
describe('withEnvironmentInQueryString', function() {
beforeEach(function() {
browserHistory.replace = jest.fn();
LatestContextStore.onSetActiveOrganization({});
});
describe('updates environment', function() {
let wrapper;
beforeEach(function() {
LatestContextStore.onSetActiveEnvironment({
name: 'prod',
});
wrapper = shallow(
,
TestStubs.routerContext()
);
});
it('passes environment prop to component', function() {
expect(wrapper.prop('environment').name).toBe('prod');
});
it('replaces browser history', function() {
expect(browserHistory.replace).toHaveBeenCalledWith('http://lol/?environment=prod');
});
});
describe('handles correct environment value', function() {
let wrapper;
beforeEach(function() {
LatestContextStore.onSetActiveEnvironment({
name: 'prod',
});
wrapper = shallow(
,
TestStubs.routerContext()
);
});
it('passes environment prop to component', function() {
expect(wrapper.prop('environment').name).toBe('prod');
});
it('does not replace browser history', function() {
expect(browserHistory.replace).not.toHaveBeenCalled();
});
});
describe('removes invalid environment value', function() {
let wrapper;
beforeEach(function() {
LatestContextStore.onSetActiveEnvironment({name: 'staging'});
wrapper = shallow(
,
TestStubs.routerContext()
);
});
it('passes environment prop to component', function() {
expect(wrapper.prop('environment').name).toBe('staging');
});
it('replaces browser history', function() {
expect(browserHistory.replace).toHaveBeenCalledWith(
'http://lol/?environment=staging'
);
});
});
});