2017-11-29 08:14:56 -05:00
|
|
|
/**
|
|
|
|
* Help component
|
|
|
|
*/
|
|
|
|
import React from 'react';
|
|
|
|
import { shallow } from 'enzyme';
|
2017-12-01 14:04:01 -05:00
|
|
|
import SyntaxHighlighter from 'react-syntax-highlighter/dist/light';
|
2017-11-29 08:14:56 -05:00
|
|
|
import Help from '../../../src/webui/src/components/Help';
|
|
|
|
|
2017-12-01 14:04:01 -05:00
|
|
|
describe('<Help /> component', () => {
|
2017-11-29 08:14:56 -05:00
|
|
|
beforeEach(() => {
|
|
|
|
/**
|
|
|
|
* @see https://github.com/facebook/jest/issues/890
|
|
|
|
*/
|
|
|
|
Object.defineProperty(window.location, 'origin', {
|
|
|
|
writable: true,
|
|
|
|
value: 'http://example.com'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('should set html from props with / base path', () => {
|
|
|
|
Object.defineProperty(window.location, 'pathname', {
|
|
|
|
writable: true,
|
|
|
|
value: '/'
|
|
|
|
});
|
|
|
|
const wrapper = shallow(<Help />);
|
2017-12-01 14:04:01 -05:00
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('#adduser')
|
|
|
|
.find(SyntaxHighlighter)
|
|
|
|
.dive()
|
|
|
|
.text()
|
|
|
|
).toEqual('npm adduser --registry http://example.com');
|
2017-12-02 09:01:06 -05:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
2017-11-29 08:14:56 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should set html from props with someOtherPath', () => {
|
|
|
|
Object.defineProperty(window.location, 'pathname', {
|
|
|
|
writable: true,
|
|
|
|
value: '/someOtherPath'
|
|
|
|
});
|
|
|
|
const wrapper = shallow(<Help />);
|
2017-12-01 14:04:01 -05:00
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('#publish')
|
|
|
|
.find(SyntaxHighlighter)
|
|
|
|
.dive()
|
|
|
|
.text()
|
|
|
|
).toEqual('npm publish --registry http://example.com/someOtherPath');
|
2017-12-02 09:01:06 -05:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
2017-11-29 08:14:56 -05:00
|
|
|
});
|
|
|
|
});
|