This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
forked from openshift/console
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alec Merdler
committed
Oct 27, 2017
1 parent
f3f47d6
commit 2e65245
Showing
12 changed files
with
230 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* eslint-disable no-undef, no-unused-vars */ | ||
|
||
import * as React from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
import { shallow, ShallowWrapper } from 'enzyme'; | ||
|
||
import { NavTitle, NavTitleProps, BreadCrumbs, BreadCrumbsProps } from '../../../public/components/utils/nav-title'; | ||
import { ResourceIcon } from '../../../public/components/utils'; | ||
|
||
describe(BreadCrumbs.displayName, () => { | ||
let wrapper: ShallowWrapper<BreadCrumbsProps>; | ||
let breadcrumbs: BreadCrumbsProps['breadcrumbs']; | ||
|
||
beforeEach(() => { | ||
breadcrumbs = [ | ||
{name: 'pods', path: '/pods'}, | ||
{name: 'containers', path: '/pods'}, | ||
]; | ||
wrapper = shallow(<BreadCrumbs breadcrumbs={breadcrumbs} />); | ||
}); | ||
|
||
it('renders link for each given breadcrumb', () => { | ||
const links: ShallowWrapper<any> = wrapper.find(Link); | ||
|
||
expect(links.length).toEqual(breadcrumbs.length); | ||
|
||
breadcrumbs.forEach((crumb, i) => { | ||
expect(links.at(i).props().to).toEqual(crumb.path); | ||
expect(links.at(i).childAt(0).text()).toEqual(crumb.name); | ||
}); | ||
}); | ||
|
||
it('renders separator between each breadcrumb link', () => { | ||
const separators = wrapper.find('.co-m-nav-title__breadcrumbs__seperator'); | ||
|
||
expect(separators.length).toEqual(breadcrumbs.length - 1); | ||
|
||
separators.forEach((separator) => { | ||
expect(separator.text()).toEqual('/'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe(NavTitle.displayName, () => { | ||
let wrapper: ShallowWrapper<NavTitleProps>; | ||
|
||
beforeEach(() => { | ||
wrapper = shallow(<NavTitle obj={null} />); | ||
}); | ||
|
||
it('renders resource icon if given `kind`', () => { | ||
const kind = 'Pod'; | ||
wrapper.setProps({kind}); | ||
const icon = wrapper.find(ResourceIcon); | ||
|
||
expect(icon.exists()).toBe(true); | ||
expect(icon.props().kind).toEqual(kind); | ||
}); | ||
|
||
it('renders custom title component if given', () => { | ||
const title = <span>My Custom Title</span>; | ||
wrapper.setProps({title}); | ||
|
||
expect(wrapper.find('.co-m-page-title').contains(title)).toBe(true); | ||
}); | ||
|
||
it('renders breadcrumbs if given `breadcrumbs`', () => { | ||
const breadcrumbs = []; | ||
wrapper.setProps({breadcrumbs}); | ||
|
||
expect(wrapper.find(BreadCrumbs).exists()).toBe(true); | ||
expect(wrapper.find(BreadCrumbs).props().breadcrumbs).toEqual(breadcrumbs); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* eslint-disable no-undef, no-unused-vars */ | ||
|
||
import * as React from 'react'; | ||
import { match } from 'react-router-dom'; | ||
|
||
import { Firehose, VertNav, NavTitle } from '../utils'; | ||
|
||
export const DetailsPage: React.StatelessComponent<DetailsPageProps> = (props) => <Firehose resources={[{ | ||
kind: props.kind, | ||
name: props.name, | ||
namespace: props.namespace, | ||
isList: false, | ||
prop: 'obj', | ||
}]}> | ||
<NavTitle detail={true} title={props.name} menuActions={props.menuActions} kind={props.kind} breadcrumbs={props.breadcrumbs} /> | ||
<VertNav pages={props.pages} className={`co-m-${props.kind}`} match={props.match} label={props.label || props.kind.label}/> | ||
</Firehose>; | ||
|
||
export type DetailsPageProps = { | ||
match: match<any>; | ||
title?: string | JSX.Element; | ||
menuActions?: any[]; | ||
pages: any[]; | ||
kind: string | any; | ||
label?: string; | ||
name?: string; | ||
namespace?: string; | ||
isList: boolean; | ||
breadcrumbs?: {name: string, path: string}[]; | ||
}; | ||
|
||
DetailsPage.displayName = 'DetailsPage'; |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* eslint-disable no-undef, no-unused-vars */ | ||
|
||
import * as React from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
import * as classNames from'classnames'; | ||
import * as _ from 'lodash'; | ||
|
||
import { ActionsMenu, kindObj, ResourceIcon } from './index'; | ||
import { ClusterServiceVersionLogo, K8sResourceKind } from '../cloud-services'; | ||
|
||
export const BreadCrumbs: React.StatelessComponent<BreadCrumbsProps> = ({breadcrumbs}) => ( | ||
<div className="co-m-nav-title__breadcrumbs"> | ||
{ breadcrumbs.map((crumb, i, {length}) => { | ||
const isLast = i === length - 1; | ||
|
||
return <div key={i}> | ||
<Link className={classNames('co-m-nav-title__breadcrumbs__link', {'co-m-nav-title__breadcrumbs__link--end': isLast})} to={crumb.path}>{crumb.name}</Link> | ||
{ !isLast && <span className="co-m-nav-title__breadcrumbs__seperator">/</span> } | ||
</div>; | ||
}) } | ||
</div>); | ||
|
||
export const NavTitle: React.StatelessComponent<NavTitleProps> = ({kind, detail, title, menuActions, obj, breadcrumbs, children}) => { | ||
const data = _.get<K8sResourceKind>(obj, 'data'); | ||
const hasLogo = !_.isEmpty(data) && _.has(data, 'spec.icon'); | ||
const logo = hasLogo | ||
? <ClusterServiceVersionLogo icon={_.get(data, 'spec.icon', [])[0]} displayName={data.spec.displayName} version={data.spec.version} provider={data.spec.provider} /> | ||
: <div>{ kind && <ResourceIcon kind={kind} className="co-m-page-title__icon" /> } <span>{title}</span></div>; | ||
|
||
return <div className={classNames('row', detail ? 'co-m-nav-title__detail' : 'co-m-nav-title')}> | ||
<div className="col-xs-12"> | ||
{ breadcrumbs && <BreadCrumbs breadcrumbs={breadcrumbs} />} | ||
<h1 className={classNames('co-m-page-title', {'co-m-page-title--detail': detail}, {'co-m-page-title--logo': hasLogo}, {'co-m-page-title--breadcrumbs': breadcrumbs})}> | ||
{logo} | ||
{ menuActions && !_.isEmpty(data) && !_.has(data.metadata, 'deletionTimestamp') && <ActionsMenu actions={menuActions.map(a => a(kindObj(kind), data))} /> } | ||
</h1> | ||
{children} | ||
</div> | ||
</div>; | ||
}; | ||
|
||
export type NavTitleProps = { | ||
kind?: string; | ||
detail?: boolean; | ||
title?: string | JSX.Element; | ||
menuActions?: any[]; | ||
obj?: {data: K8sResourceKind}; | ||
breadcrumbs?: {name: string, path: string}[]; | ||
}; | ||
|
||
export type BreadCrumbsProps = { | ||
breadcrumbs: {name: string, path: string}[]; | ||
}; | ||
|
||
NavTitle.displayName = 'NavTitle'; | ||
BreadCrumbs.displayName = 'BreadCrumbs'; |