Skip to content

Commit f803fa3

Browse files
authored
fix(response-body): show download button both for non-empty Blob and string responses (#9343)
Co-authored-by: Vladimír Gorej <[email protected]> Refs #9298
1 parent 2a4afd9 commit f803fa3

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/core/components/response-body.jsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ export default class ResponseBody extends React.PureComponent {
6060

6161
if (
6262
(/^application\/octet-stream/i.test(contentType) ||
63-
(headers["Content-Disposition"] && /attachment/i.test(headers["Content-Disposition"])) ||
64-
(headers["content-disposition"] && /attachment/i.test(headers["content-disposition"])) ||
65-
(headers["Content-Description"] && /File Transfer/i.test(headers["Content-Description"])) ||
66-
(headers["content-description"] && /File Transfer/i.test(headers["content-description"]))) &&
67-
content.size > 0
63+
(headers["Content-Disposition"] && /attachment/i.test(headers["Content-Disposition"])) ||
64+
(headers["content-disposition"] && /attachment/i.test(headers["content-disposition"])) ||
65+
(headers["Content-Description"] && /File Transfer/i.test(headers["Content-Description"])) ||
66+
(headers["content-description"] && /File Transfer/i.test(headers["content-description"]))) &&
67+
(content.size > 0 || content.length > 0)
6868
) {
6969
// Download
7070

test/unit/components/response-body.jsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,33 @@ describe("<ResponseBody />", function () {
2828
it("renders ResponseBody as 'image/svg'", function () {
2929
props.contentType = "image/svg"
3030
const wrapper = shallow(<ResponseBody {...props} />)
31-
console.warn(wrapper.debug())
3231
expect(wrapper.find("highlightCodeComponent").length).toEqual(0)
3332
})
3433

3534
it("should render a copyable highlightCodeComponent for text types", function () {
3635
props.contentType = "text/plain"
3736
props.content = "test text"
3837
const wrapper = shallow(<ResponseBody {...props} />)
39-
console.warn(wrapper.debug())
4038
expect(wrapper.find("highlightCodeComponent[canCopy]").length).toEqual(1)
4139
})
4240

43-
it("should render Download file link for non-empty response", function () {
41+
it("should render Download file link for non-empty Blob response", function () {
4442
props.contentType = "application/octet-stream"
4543
props.content = new Blob(["\"test\""], { type: props.contentType })
4644
const wrapper = shallow(<ResponseBody {...props} />)
4745
expect(wrapper.text()).toMatch(/Download file/)
4846
})
4947

48+
it("should render Download file link for non-empty text response", function () {
49+
props.contentType = "text/plain"
50+
props.content = "test text"
51+
props.headers = {
52+
"Content-Disposition": "attachment; filename=\"test.txt\"",
53+
}
54+
const wrapper = shallow(<ResponseBody {...props} />)
55+
expect(wrapper.text()).toMatch(/Download file/)
56+
})
57+
5058
it("should not render Download file link for empty response", function () {
5159
props.contentType = "application/octet-stream"
5260
props.content = new Blob()

0 commit comments

Comments
 (0)