import OverviewApp from './OverviewApp';
import EmptyOverview from './EmptyOverview';
import { getBranchName, isShortLivingBranch } from '../../../helpers/branches';
-import { getProjectBranchUrl } from '../../../helpers/urls';
-import SourceViewer from '../../../components/SourceViewer/SourceViewer';
+import { getProjectBranchUrl, getCodeUrl } from '../../../helpers/urls';
/*::
type Props = {
branch?: { name: string },
component: {
analysisDate?: string,
+ breadcrumbs: Array<{ key: string }>,
id: string,
key: string,
qualifier: string,
};
componentDidMount() {
+ const { branch, component } = this.props;
+
if (this.isPortfolio()) {
this.context.router.replace({
pathname: '/portfolio',
- query: { id: this.props.component.key }
+ query: { id: component.key }
});
- }
- if (isShortLivingBranch(this.props.branch) && !this.isFile()) {
- this.context.router.replace(getProjectBranchUrl(this.props.component.key, this.props.branch));
+ } else if (this.isFile()) {
+ this.context.router.replace(
+ getCodeUrl(component.breadcrumbs[0].key, getBranchName(branch), component.key)
+ );
+ } else if (isShortLivingBranch(branch)) {
+ this.context.router.replace(getProjectBranchUrl(component.key, branch));
}
}
render() {
const { branch, component } = this.props;
- if (this.isPortfolio() || (isShortLivingBranch(branch) && !this.isFile())) {
+ if (this.isPortfolio() || this.isFile() || isShortLivingBranch(branch)) {
return null;
}
- if (['FIL', 'UTS'].includes(component.qualifier)) {
- return (
- <div className="page page-limited">
- <SourceViewer branch={branch && getBranchName(branch)} component={component.key} />
- </div>
- );
- }
-
if (!component.analysisDate) {
return <EmptyOverview component={component} />;
}
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import React from 'react';
-import { shallow } from 'enzyme';
+import { mount, shallow } from 'enzyme';
import App from '../App';
import OverviewApp from '../OverviewApp';
import EmptyOverview from '../EmptyOverview';
expect(output.type()).toBe(EmptyOverview);
});
-it('renders SourceViewer with branch', () => {
+it('redirects on Code page for files', () => {
const branch = { isMain: false, name: 'b' };
- const component = { key: 'foo', qualifier: 'FIL' };
- expect(shallow(<App branch={branch} component={component} />)).toMatchSnapshot();
+ const component = {
+ breadcrumbs: [{ key: 'project' }, { key: 'foo' }],
+ key: 'foo',
+ qualifier: 'FIL'
+ };
+ const replace = jest.fn();
+ mount(<App branch={branch} component={component} />, { context: { router: { replace } } });
+ expect(replace).toBeCalledWith({
+ pathname: '/code',
+ query: { branch: 'b', id: 'project', selected: 'foo' }
+ });
});