-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PSP-8320 Update Lease button location (#4338)
* Add common component for custom section headers * PSP-8320 Update Lease Button Location * Test updates
- Loading branch information
Showing
13 changed files
with
845 additions
and
182 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
source/frontend/src/components/common/SimpleSectionHeader.test.tsx
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 @@ | ||
import React from 'react'; | ||
|
||
import { render, RenderOptions, screen } from '@/utils/test-utils'; | ||
|
||
import { ISimpleSectionHeaderProps, SimpleSectionHeader } from './SimpleSectionHeader'; | ||
import { StyledAddButton } from './styles'; | ||
import { FaMoneyCheck } from 'react-icons/fa'; | ||
|
||
describe('SimpleSectionHeader component', () => { | ||
// render component under test | ||
const setup = ( | ||
renderOptions: RenderOptions & { | ||
props?: Partial<React.PropsWithChildren<ISimpleSectionHeaderProps>>; | ||
} = {}, | ||
) => { | ||
const utils = render( | ||
<SimpleSectionHeader | ||
title={renderOptions?.props?.title ?? 'TEST TITLE'} | ||
className={renderOptions?.props?.className ?? ''} | ||
> | ||
{renderOptions?.props?.children ?? null} | ||
</SimpleSectionHeader>, | ||
{ | ||
...renderOptions, | ||
}, | ||
); | ||
|
||
return { ...utils }; | ||
}; | ||
|
||
it('renders as expected', () => { | ||
const { asFragment } = setup(); | ||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
|
||
it('displays the header title', () => { | ||
setup({ props: { title: 'LOREM IPSUM' } }); | ||
expect(screen.getByText('LOREM IPSUM')).toBeVisible(); | ||
}); | ||
|
||
it('renders children sub-components on the right end of the header', () => { | ||
setup({ | ||
props: { | ||
title: 'LOREM IPSUM', | ||
children: ( | ||
<StyledAddButton> | ||
<FaMoneyCheck className="mr-2" /> | ||
Generate | ||
</StyledAddButton> | ||
), | ||
}, | ||
}); | ||
|
||
expect(screen.getByText('Generate')).toBeVisible(); | ||
}); | ||
}); |
43 changes: 43 additions & 0 deletions
43
source/frontend/src/components/common/SimpleSectionHeader.tsx
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,43 @@ | ||
import clsx from 'classnames'; | ||
import React from 'react'; | ||
import { Col, Row } from 'react-bootstrap'; | ||
import styled from 'styled-components'; | ||
|
||
import { exists } from '@/utils'; | ||
|
||
export interface ISimpleSectionHeaderProps { | ||
title: string; | ||
className?: string; | ||
} | ||
|
||
/** | ||
* Simple section header that takes a section title and optional children components. | ||
* If children components are supplied, they will be rendered on the right end of the header. | ||
* @param props customize the component by passing a title and optional class-name to modify the default component styling. | ||
* @returns The header component | ||
*/ | ||
export const SimpleSectionHeader: React.FunctionComponent< | ||
React.PropsWithChildren<ISimpleSectionHeaderProps> | ||
> = ({ title, className, children }) => { | ||
return ( | ||
<StyledRow className={clsx('no-gutters', className)}> | ||
<Col xs="auto" className="d-flex justify-content-start px-2 my-1"> | ||
{title ?? ''} | ||
</Col> | ||
{exists(children) && ( | ||
<Col xs="auto" className="d-flex justify-content-end my-1"> | ||
{children} | ||
</Col> | ||
)} | ||
</StyledRow> | ||
); | ||
}; | ||
|
||
const StyledRow = styled(Row)` | ||
justify-content: space-between; | ||
align-items: end; | ||
min-height: 4.5rem; | ||
.btn { | ||
margin: 0; | ||
} | ||
`; |
3 changes: 1 addition & 2 deletions
3
source/frontend/src/components/common/UserNameTooltip.test.tsx
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
35 changes: 35 additions & 0 deletions
35
source/frontend/src/components/common/__snapshots__/SimpleSectionHeader.test.tsx.snap
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,35 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`SimpleSectionHeader component > renders as expected 1`] = ` | ||
<DocumentFragment> | ||
<div | ||
class="Toastify" | ||
/> | ||
<div /> | ||
.c0 { | ||
-webkit-box-pack: justify; | ||
-webkit-justify-content: space-between; | ||
-ms-flex-pack: justify; | ||
justify-content: space-between; | ||
-webkit-align-items: end; | ||
-webkit-box-align: end; | ||
-ms-flex-align: end; | ||
align-items: end; | ||
min-height: 4.5rem; | ||
} | ||
.c0 .btn { | ||
margin: 0; | ||
} | ||
<div | ||
class="c0 no-gutters row" | ||
> | ||
<div | ||
class="d-flex justify-content-start px-2 my-1 col-auto" | ||
> | ||
TEST TITLE | ||
</div> | ||
</div> | ||
</DocumentFragment> | ||
`; |
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
57 changes: 51 additions & 6 deletions
57
source/frontend/src/features/leases/detail/LeasePages/details/LeaseDetailView.tsx
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
Oops, something went wrong.