Skip to content

Commit b970d2e

Browse files
jacobseeTateDeVitoJacob See
authored
Use Case Links (#562)
* Use cases with engagement and customer name * Fix broken tests * Cleanup router test readability * Attempt to fix routing error in artifact component spec * Actually use the mock artifact array during the tests... * Get rid of unused property and whitespace that makes everything angry Co-authored-by: TateDeVito <[email protected]> Co-authored-by: Jacob See <[email protected]>
1 parent 2992357 commit b970d2e

File tree

5 files changed

+69
-20
lines changed

5 files changed

+69
-20
lines changed

src/components/dashboard/widgets/dw_last_artifact.spec.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
import { render } from '@testing-library/react';
22
import React from 'react';
3-
import { mockEngagementUseCase } from '../../../mocks/engagement_mocks';
3+
import { createMemoryHistory } from 'history';
4+
import { Router } from 'react-router';
5+
import { mockEngagementArtifact, mockEngagementUseCase } from '../../../mocks/engagement_mocks';
46
import { DwLastArtifacts } from './dw_last_artifact';
57
import { DwLastUseCases } from './dw_last_use_cases';
68

79
describe('Last Use Cases dashboard widget', () => {
810
test('has the correct title', () => {
9-
const component = render(<DwLastArtifacts artifacts={[]} />);
11+
const component = render(
12+
<Router history={createMemoryHistory({})}>
13+
<DwLastArtifacts artifacts={[]} />
14+
</Router>
15+
);
1016
expect(component.getByText('Artifacts')).toBeDefined();
1117
});
1218
test('shows the artifacts', () => {
13-
const artifacts = new Array(10).fill(null).map(mockEngagementUseCase);
14-
const component = render(<DwLastUseCases useCases={artifacts} />);
19+
const artifacts = new Array(10).fill(null).map(mockEngagementArtifact);
20+
const component = render(
21+
<Router history={createMemoryHistory({})}>
22+
<DwLastArtifacts artifacts={artifacts} />
23+
</Router>
24+
);
1525
for (let artifact of artifacts) {
1626
expect(component.getByText(artifact.description)).toBeDefined();
1727
}

src/components/dashboard/widgets/dw_last_use_cases.spec.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
import { render } from '@testing-library/react';
22
import React from 'react';
3+
import { createMemoryHistory } from 'history';
4+
import { Router } from 'react-router';
35
import { mockEngagementUseCase } from '../../../mocks/engagement_mocks';
46
import { DwLastUseCases } from './dw_last_use_cases';
57

68
describe('Last Use Cases dashboard widget', () => {
79
test('has the correct title', () => {
8-
const component = render(<DwLastUseCases useCases={[]} />);
9-
expect(component.getByText('Use Cases')).toBeDefined();
10+
const component = render(
11+
<Router history={createMemoryHistory({})}>
12+
<DwLastUseCases useCases={[]} />
13+
</Router>
14+
);
15+
expect(component.getAllByText('Use Cases')).toBeDefined();
1016
});
1117
test('shows the use cases', () => {
1218
const useCases = new Array(10).fill(null).map(mockEngagementUseCase);
13-
const component = render(<DwLastUseCases useCases={useCases} />);
19+
const component = render(
20+
<Router history={createMemoryHistory({})}>
21+
<DwLastUseCases useCases={useCases} />
22+
</Router>
23+
);
1424
for (let useCase of useCases) {
1525
expect(component.getByText(useCase.description)).toBeDefined();
1626
}

src/components/dashboard/widgets/dw_last_use_cases.tsx

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,51 @@ import {
88
TextContent,
99
TextVariants,
1010
} from '@patternfly/react-core';
11-
import {ReactComponent as AtomIcon} from '../../../assets/images/atom-alt.svg';
12-
import { Table, TableBody, TableHeader } from '@patternfly/react-table';
11+
import { ReactComponent as AtomIcon } from '../../../assets/images/atom-alt.svg';
12+
import {
13+
Table,
14+
TableBody,
15+
TableHeader,
16+
} from '@patternfly/react-table';
1317
import { EngagementUseCase } from '../../../schemas/engagement';
1418
import CustomRowWrapper from '../../../components/custom_row_wrapper/custom_row_wrapper';
19+
import { Link } from 'react-router-dom';
1520
export interface DwLastUseCasesProps {
1621
useCases: EngagementUseCase[];
1722
}
18-
const columns = ['Use Case'];
23+
const columns = [
24+
'Use Cases',
25+
];
1926
export const DwLastUseCases = (props: DwLastUseCasesProps) => {
2027
const rows = props.useCases.map(useCase => {
2128
return [
2229
{
23-
title: useCase?.description,
24-
// <Button variant={ButtonVariant.link} onClick={() => {}} isInline>
25-
// {useCase?.description}
26-
// </Button>
30+
title: <div><div><b>Engagement:</b> <Link to={`/app/engagements/${useCase.engagement_uuid}`}>{ useCase?.customer_name + ' - ' + useCase?.project_name }</Link></div><div>{useCase?.description}</div></div>,
2731
},
2832
];
2933
});
3034
return (
3135
<Card>
3236
<CardHeader>
33-
<AtomIcon
37+
<AtomIcon
3438
width="25"
3539
fill="#EC7A0A"
3640
stroke="#EC7A0A"
37-
style={{marginRight:"5px"}}
41+
style={{ marginRight: '5px' }}
3842
></AtomIcon>
3943
<TextContent>
40-
<Text component={TextVariants.h2}>Use Cases <span style={{fontSize:"12px", color:"#999999", verticalAlign:"middle"}}>(last 5)</span></Text>
44+
<Text component={TextVariants.h2}>
45+
Use Cases{' '}
46+
<span
47+
style={{
48+
fontSize: '12px',
49+
color: '#999999',
50+
verticalAlign: 'middle',
51+
}}
52+
>
53+
(last 5)
54+
</span>
55+
</Text>
4156
</TextContent>
4257
</CardHeader>
4358
<CardBody>
@@ -46,7 +61,10 @@ export const DwLastUseCases = (props: DwLastUseCasesProps) => {
4661
rows={rows}
4762
cells={columns}
4863
gridBreakPoint={'grid-lg'}
49-
rowWrapper={({trRef, rowProps, ...props}) => <CustomRowWrapper trref={trRef} rowprops={rowProps} {...props}/>} >
64+
rowWrapper={({ trRef, rowProps, ...props }) => (
65+
<CustomRowWrapper trref={trRef} rowprops={rowProps} {...props} />
66+
)}
67+
>
5068
<TableHeader />
5169
<TableBody />
5270
</Table>

src/packages/api_v1_sdk/apiv1_use_cases_service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ export class Apiv1UseCasesService implements UseCaseService {
4040
return {
4141
id: apiResponseObject['uuid'],
4242
description: apiResponseObject['description'],
43+
engagement_uuid: apiResponseObject['engagement_uuid'],
44+
project_name: apiResponseObject['name'],
45+
customer_name: apiResponseObject['customer_name'],
4346
};
4447
};
4548
async getUseCases(filter?: UseCaseFilter): Promise<EngagementUseCase[]> {

src/schemas/engagement.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ export interface EngagementUseCase {
6161
description?: string;
6262
id: string;
6363
engagement_uuid: string;
64+
project_name?: string;
65+
customer_name?: string;
6466
}
6567

6668
export interface Artifact {
@@ -264,11 +266,17 @@ export abstract class Engagement {
264266
: null,
265267
status: ClusterStatus.fromFake(staticData, options),
266268
use_cases: staticData
267-
? [{ id: '1', description: 'an engagement use case', engagement_uuid: '475hf89-578978972897-8979879' }]
269+
? [
270+
{
271+
id: '1',
272+
description: 'an engagement use case',
273+
engagement_uuid: '475hf89-578978972897-8979879',
274+
},
275+
]
268276
: new Array(3).fill(null).map(() => ({
269277
description: faker.lorem.sentence(),
270278
id: faker.random.uuid().toString(),
271-
engagement_uuid: "475hf89-578978972897-8979879"
279+
engagement_uuid: '475hf89-578978972897-8979879',
272280
})),
273281
...getStatusDeterminers(),
274282
uuid: staticData ? 'uuid' : faker.random.uuid(),

0 commit comments

Comments
 (0)