Skip to content
This repository was archived by the owner on Mar 4, 2024. It is now read-only.

Commit 06cb633

Browse files
COPDS-1046: LicenceWidget must not render if licences is missing or is an empty list
1 parent 0f39988 commit 06cb633

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

__tests__/widgets/LicenceWidget.spec.tsx

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,36 @@ import { render, screen } from '@testing-library/react'
44
import { LicenceWidget } from '../../src'
55

66
describe('<LicenceWidget/>', () => {
7+
it('does not render with empty or missing licences', () => {
8+
render(
9+
<>
10+
<LicenceWidget
11+
configuration={{
12+
type: 'LicenceWidget' as const,
13+
name: 'licences',
14+
label: 'Terms of use A',
15+
details: {
16+
licences: []
17+
}
18+
}}
19+
/>
20+
<LicenceWidget
21+
configuration={{
22+
type: 'LicenceWidget' as const,
23+
name: 'licences',
24+
label: 'Terms of use B',
25+
details: {}
26+
}}
27+
/>
28+
</>
29+
)
30+
31+
// @ts-ignore
32+
expect(screen.queryByText('Terms of use A')).not.toBeInTheDocument()
33+
// @ts-ignore
34+
expect(screen.queryByText('Terms of use B')).not.toBeInTheDocument()
35+
})
36+
737
it('renders from configuration - falls back to licence id', () => {
838
const configuration = {
939
type: 'LicenceWidget' as const,
@@ -13,7 +43,7 @@ describe('<LicenceWidget/>', () => {
1343
licences: [
1444
{
1545
id: 'licence-xyz',
16-
revision: '3',
46+
revision: 3,
1747
contents_url: '',
1848
attachment_url: ''
1949
}
@@ -35,7 +65,7 @@ describe('<LicenceWidget/>', () => {
3565
licences: [
3666
{
3767
id: 'licence-xyz',
38-
revision: '3',
68+
revision: 3,
3969
label: 'Licence to use Copernicus products',
4070
contents_url: '',
4171
attachment_url: ''
@@ -58,15 +88,15 @@ describe('<LicenceWidget/>', () => {
5888
licences: [
5989
{
6090
id: 'licence-xyz',
61-
revision: '3',
91+
revision: 3,
6292
label: 'Licence to use Copernicus products',
6393
contents_url: '',
6494
attachment_url: '',
6595
accepted: true
6696
},
6797
{
6898
id: 'licence-abc',
69-
revision: '3',
99+
revision: 3,
70100
label: 'Additional licence to use non European contributions',
71101
contents_url: '',
72102
attachment_url: '',
@@ -86,6 +116,4 @@ describe('<LicenceWidget/>', () => {
86116
)
87117
screen.getByText(/accept terms/i)
88118
})
89-
90-
it.todo('enforces constraints')
91119
})

src/widgets/LicenceWidget.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export type Licence = {
1717
/**
1818
* The licence revision.
1919
*/
20-
revision: string
20+
revision: number
2121
/**
2222
* The licence label.
2323
*/
@@ -41,7 +41,7 @@ export interface LicenceWidgetConfiguration {
4141
label: string
4242
help?: string
4343
details: {
44-
licences: Licence[]
44+
licences?: Licence[] | []
4545
}
4646
}
4747

@@ -124,6 +124,8 @@ const LicenceWidget = ({
124124
)
125125
}
126126

127+
if (!licences || !licences.length) return null
128+
127129
return (
128130
<Widget data-stylizable='widget'>
129131
<WidgetHeader>

0 commit comments

Comments
 (0)