Skip to content

Commit 185a6fd

Browse files
authored
[fix-6165]: Hide PDFs from forward to external (#3017)
* Hide PDFs when forwarding melding to external * Add ExplanationSection tests * Add forwardToExternal test * Simplify changes to fixture * Revert change to fixture, fix tests instead * Fix typo
1 parent a96b914 commit 185a6fd

File tree

7 files changed

+108
-25
lines changed

7 files changed

+108
-25
lines changed

app.base.json

+6-15
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"showThorButton": false,
2121
"showVulaanControls": false,
2222
"useProjectenSignalType": false,
23-
"enableForwardIncidentToExternal": false,
23+
"enableForwardIncidentToExternal": true,
2424
"showMainCategories": false,
2525
"showStandardTextAdminV1": true,
2626
"showStandardTextAdminV2": false,
@@ -72,21 +72,12 @@
7272
"municipality": "amsterdam",
7373
"options": {
7474
"crs": "EPSG:28992",
75-
"center": [
76-
52.3731081,
77-
4.8932945
78-
],
75+
"center": [52.3731081, 4.8932945],
7976
"maxBounds": [
80-
[
81-
52.25168,
82-
4.64034
83-
],
84-
[
85-
52.50536,
86-
5.10737
87-
]
77+
[52.25168, 4.64034],
78+
[52.50536, 5.10737]
8879
],
89-
"maxNumberOfAssets" : {
80+
"maxNumberOfAssets": {
9081
"straatverlichting": 3,
9182
"klokken": 1,
9283
"afvalContainer": 5,
@@ -181,7 +172,7 @@
181172
}
182173
},
183174
"frontPageAlert": {
184-
"text":""
175+
"text": ""
185176
},
186177
"additionalCode": {
187178
"css": ""

internals/mocks/fixtures/attachments.json

+14
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@
5353
"created_by": "me",
5454
"public": true,
5555
"caption": ""
56+
},
57+
{
58+
"_display": "Attachment object (983)",
59+
"_links": {
60+
"self": {
61+
"href": "http://localhost:8000/signals/v1/private/signals/63/attachments/88"
62+
}
63+
},
64+
"location": "https://not-an-image.pdf",
65+
"is_image": false,
66+
"created_at": "2022-06-10T11:51:24.281272+02:00",
67+
"created_by": "me",
68+
"public": true,
69+
"caption": ""
5670
}
5771
]
5872
}

src/signals/incident-management/containers/IncidentDetail/components/Attachments/Attachments.test.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ describe('Attachments', () => {
503503
)
504504
)
505505

506-
expect(screen.getAllByTitle(/bijlage verwijderen/i)).toHaveLength(3)
506+
expect(screen.getAllByTitle(/bijlage verwijderen/i)).toHaveLength(4)
507507
})
508508

509509
it('shows the delete button when allowed from others and for normal incidents', () => {
@@ -529,7 +529,7 @@ describe('Attachments', () => {
529529
)
530530
)
531531

532-
expect(screen.getAllByTitle(/bijlage verwijderen/i)).toHaveLength(3)
532+
expect(screen.getAllByTitle(/bijlage verwijderen/i)).toHaveLength(4)
533533
})
534534

535535
it('shows the delete button when allowed from others and for child incidents', () => {
@@ -555,7 +555,7 @@ describe('Attachments', () => {
555555
)
556556
)
557557

558-
expect(screen.getAllByTitle(/bijlage verwijderen/i)).toHaveLength(3)
558+
expect(screen.getAllByTitle(/bijlage verwijderen/i)).toHaveLength(4)
559559
})
560560

561561
it('shows the delete button when allowed from others and for parent incidents', () => {
@@ -581,7 +581,7 @@ describe('Attachments', () => {
581581
)
582582
)
583583

584-
expect(screen.getAllByTitle(/bijlage verwijderen/i)).toHaveLength(3)
584+
expect(screen.getAllByTitle(/bijlage verwijderen/i)).toHaveLength(4)
585585
})
586586

587587
it('shows the delete button when its your own attachment and allowed for normal incidents', () => {

src/signals/incident-management/containers/IncidentDetail/components/ForwardToExternal/ForwardToExternal.test.tsx

+19
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,25 @@ describe('ForwardToExternal', () => {
215215
})
216216
expect(closeSpy).toHaveBeenCalled()
217217
})
218+
219+
it('only shows image attachments', async () => {
220+
render(
221+
withAppContext(
222+
<IncidentDetailContext.Provider
223+
value={{
224+
update: jest.fn(),
225+
attachments: attachmentsFixture,
226+
}}
227+
>
228+
<ForwardToExternal onClose={jest.fn()} />
229+
</IncidentDetailContext.Provider>
230+
)
231+
)
232+
233+
const images = screen.getAllByRole('img')
234+
235+
expect(images).toHaveLength(3)
236+
})
218237
})
219238
})
220239
})

src/signals/incident-management/containers/IncidentDetail/components/ForwardToExternal/ForwardToExternal.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ const ForwardToExternal = ({ onClose }: ForwardToExternalProps) => {
135135
}
136136
}, [emailTemplateError, storeDispatch])
137137

138+
// Only show image attachments, pdf attachments are not supported
139+
const imageAttachments = attachments?.results.filter(
140+
(attachment) => attachment.is_image
141+
)
142+
138143
return (
139144
<Form
140145
ref={formRef}
@@ -182,11 +187,11 @@ const ForwardToExternal = ({ onClose }: ForwardToExternalProps) => {
182187
</ErrorWrapper>
183188
</StyledSection>
184189

185-
{attachments?.count ? (
190+
{imageAttachments && imageAttachments.length > 0 ? (
186191
<StyledSection>
187192
<StyledParagraph strong>Foto&apos;s</StyledParagraph>
188193
<ImageWrapper>
189-
{attachments.results.map((attachment) => (
194+
{imageAttachments.map((attachment) => (
190195
<Image
191196
key={attachment.location}
192197
src={attachment.location}

src/signals/incident/containers/ExternalReplyContainer/components/ExplanationSection/ExplanationSection.test.tsx

+47
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,51 @@ describe('ExplanationSection', () => {
6969

7070
expect(selectFileSpy).toHaveBeenCalledWith(file)
7171
})
72+
73+
it('shows a section with only text', () => {
74+
render(<ExplanationSection title="Foo" text={'Bar\nBaz'} />)
75+
76+
const heading = screen.getByRole('heading', { name: 'Foo' })
77+
78+
expect(heading).toBeInTheDocument()
79+
})
80+
81+
it('shows a section with only files', () => {
82+
render(<ExplanationSection title="Foo" text={null} files={files} />)
83+
84+
const heading = screen.getByRole('heading', { name: 'Foo' })
85+
86+
expect(heading).toBeInTheDocument()
87+
})
88+
89+
it('does not show when there is no text and files', () => {
90+
render(<ExplanationSection title="Foo" text={null} />)
91+
92+
const heading = screen.queryByRole('heading', { name: 'Foo' })
93+
94+
expect(heading).not.toBeInTheDocument()
95+
})
96+
97+
it('does not show when there is no text and only PDF files', () => {
98+
const pdfFiles = [{ description: 'pdf', file: 'file.pdf' }]
99+
100+
render(<ExplanationSection title="Foo" text={null} files={pdfFiles} />)
101+
102+
const heading = screen.queryByRole('heading', { name: 'Foo' })
103+
104+
expect(heading).not.toBeInTheDocument()
105+
})
106+
107+
it('filters out PDF files', () => {
108+
const filesWithPdf = [
109+
{ description: 'image', file: 'file.jpg' },
110+
{ description: 'pdf', file: 'file.pdf' },
111+
]
112+
113+
render(<ExplanationSection title="Foo" text={null} files={filesWithPdf} />)
114+
115+
const images = screen.getAllByRole('img')
116+
117+
expect(images).toHaveLength(1)
118+
})
72119
})

src/signals/incident/containers/ExternalReplyContainer/components/ExplanationSection/ExplanationSection.tsx

+11-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Heading, themeSpacing } from '@amsterdam/asc-ui'
44
import styled from 'styled-components'
55

66
import Paragraph from 'components/Paragraph'
7+
import { isPdf } from 'signals/incident-management/containers/IncidentDetail/utils/isPdf'
78

89
type File = {
910
description: string
@@ -56,7 +57,13 @@ const ExplanationSection = ({
5657
onSelectFile(file)
5758
}
5859
}
59-
return (
60+
61+
// Only show image files, pdf files are not supported
62+
const imageFiles = files.filter(({ file }) => !isPdf(file))
63+
64+
const showSection = text || imageFiles.length > 0
65+
66+
return showSection ? (
6067
<Section className={className}>
6168
<StyledHeading forwardedAs="h4">{title}</StyledHeading>
6269

@@ -67,9 +74,9 @@ const ExplanationSection = ({
6774
</Paragraph>
6875
))}
6976

70-
{files.length > 0 ? (
77+
{imageFiles.length > 0 ? (
7178
<ImageWrapper>
72-
{files.map((file) => (
79+
{imageFiles.map((file) => (
7380
<Image
7481
tabIndex={0}
7582
onKeyDown={handleImageKeyPress(file)}
@@ -86,7 +93,7 @@ const ExplanationSection = ({
8693
</ImageWrapper>
8794
) : null}
8895
</Section>
89-
)
96+
) : null
9097
}
9198

9299
export default ExplanationSection

0 commit comments

Comments
 (0)