)}
</div>
<div className="big-spacer-left note">
- <BranchStatus branchLike={branchLike} />
+ <BranchStatus branchLike={branchLike} component={props.component.key} />
</div>
</Link>
</li>
<DetachIcon className="little-spacer-left" size={12} />
</a>
)}
- <BranchStatus branchLike={branchLike} />
+ <BranchStatus branchLike={branchLike} component={component.key} />
</div>
)}
</div>
<div
className="big-spacer-left note"
>
- <BranchStatus
+ <Connect(BranchStatus)
branchLike={
Object {
"isMain": true,
"name": "master",
}
}
+ component="component"
/>
</div>
</Link>
<div
className="big-spacer-left note"
>
- <BranchStatus
+ <Connect(BranchStatus)
branchLike={
Object {
"isMain": false,
"type": "SHORT",
}
}
+ component="component"
/>
</div>
</Link>
<div
className="big-spacer-left note"
>
- <BranchStatus
+ <Connect(BranchStatus)
branchLike={
Object {
"isMain": false,
"type": "SHORT",
}
}
+ component="component"
/>
</div>
</Link>
size={12}
/>
</a>
- <BranchStatus
+ <Connect(BranchStatus)
branchLike={
Object {
"analysisDate": "2018-01-01",
"url": "https://example.com/pull/1234",
}
}
+ component="my-project"
/>
</div>
</div>
<div
className="navbar-context-meta-secondary display-inline-flex-center"
>
- <BranchStatus
+ <Connect(BranchStatus)
branchLike={
Object {
"analysisDate": "2018-01-01",
"type": "SHORT",
}
}
+ component="my-project"
/>
</div>
</div>
}
render() {
- const { branchLike, isOrphan } = this.props;
+ const { branchLike, component, isOrphan } = this.props;
const indented = (isShortLivingBranch(branchLike) || isPullRequest(branchLike)) && !isOrphan;
return (
)}
</td>
<td className="thin nowrap">
- <BranchStatus branchLike={branchLike} />
+ <BranchStatus branchLike={branchLike} component={component} />
</td>
<td className="thin nowrap text-right big-spacer-left">
{branchLike.analysisDate && <DateFromNow date={branchLike.analysisDate} />}
<td
className="thin nowrap"
>
- <BranchStatus
+ <Connect(BranchStatus)
branchLike={
Object {
"isMain": true,
"name": "master",
}
}
+ component="foo"
/>
</td>
<td
<td
className="thin nowrap"
>
- <BranchStatus
+ <Connect(BranchStatus)
branchLike={
Object {
"base": "master",
"title": "Feature PR",
}
}
+ component="foo"
/>
</td>
<td
<td
className="thin nowrap"
>
- <BranchStatus
+ <Connect(BranchStatus)
branchLike={
Object {
"analysisDate": "2017-09-27T00:05:19+0000",
"type": "SHORT",
}
}
+ component="foo"
/>
</td>
<td
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import * as React from 'react';
+import { connect } from 'react-redux';
import Level from '../ui/Level';
+import { Store, getBranchStatusByBranchLike } from '../../store/rootReducer';
interface Props {
branchLike: T.BranchLike;
+ component: string;
+ status?: string;
}
-export default function BranchStatus({ branchLike }: Props) {
- if (!branchLike.status) {
+export function BranchStatus({ status }: Props) {
+ if (!status) {
return null;
}
- return <Level level={branchLike.status.qualityGateStatus} small={true} />;
+ return <Level level={status} small={true} />;
}
+
+const mapStateToProps = (state: Store, { branchLike, component }: Props) => {
+ const status = getBranchStatusByBranchLike(state, component, branchLike);
+ return { status };
+};
+
+export default connect(mapStateToProps)(BranchStatus);
*/
import * as React from 'react';
import { shallow } from 'enzyme';
-import BranchStatus from '../BranchStatus';
+import { BranchStatus } from '../BranchStatus';
+import { mockLongLivingBranch } from '../../../helpers/testMocks';
it('should render correctly', () => {
- const branch: T.MainBranch = { isMain: true, name: 'foo' };
- expect(getWrapper(branch).type()).toBeNull();
- expect(getWrapper(branch, 'OK')).toMatchSnapshot();
- expect(getWrapper(branch, 'ERROR')).toMatchSnapshot();
+ expect(shallowRender().type()).toBeNull();
+ expect(shallowRender('OK')).toMatchSnapshot();
+ expect(shallowRender('ERROR')).toMatchSnapshot();
});
-function getWrapper(branch: T.MainBranch, qualityGateStatus?: string) {
- if (qualityGateStatus) {
- branch.status = { qualityGateStatus };
- }
- return shallow(<BranchStatus branchLike={branch} />);
+function shallowRender(status?: string) {
+ return shallow(
+ <BranchStatus branchLike={mockLongLivingBranch()} component="foo" status={status} />
+ );
}