Skip to content

Commit

Permalink
fix(response-body): show download button both for non-empty Blob and …
Browse files Browse the repository at this point in the history
…string responses (#9343)

Co-authored-by: Vladimír Gorej <vladimir.gorej@gmail.com>

Refs #9298
  • Loading branch information
Omikorin authored Nov 9, 2023
1 parent 2a4afd9 commit f803fa3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/core/components/response-body.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ export default class ResponseBody extends React.PureComponent {

if (
(/^application\/octet-stream/i.test(contentType) ||
(headers["Content-Disposition"] && /attachment/i.test(headers["Content-Disposition"])) ||
(headers["content-disposition"] && /attachment/i.test(headers["content-disposition"])) ||
(headers["Content-Description"] && /File Transfer/i.test(headers["Content-Description"])) ||
(headers["content-description"] && /File Transfer/i.test(headers["content-description"]))) &&
content.size > 0
(headers["Content-Disposition"] && /attachment/i.test(headers["Content-Disposition"])) ||
(headers["content-disposition"] && /attachment/i.test(headers["content-disposition"])) ||
(headers["Content-Description"] && /File Transfer/i.test(headers["Content-Description"])) ||
(headers["content-description"] && /File Transfer/i.test(headers["content-description"]))) &&
(content.size > 0 || content.length > 0)
) {
// Download

Expand Down
14 changes: 11 additions & 3 deletions test/unit/components/response-body.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,33 @@ describe("<ResponseBody />", function () {
it("renders ResponseBody as 'image/svg'", function () {
props.contentType = "image/svg"
const wrapper = shallow(<ResponseBody {...props} />)
console.warn(wrapper.debug())
expect(wrapper.find("highlightCodeComponent").length).toEqual(0)
})

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

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

it("should render Download file link for non-empty text response", function () {
props.contentType = "text/plain"
props.content = "test text"
props.headers = {
"Content-Disposition": "attachment; filename=\"test.txt\"",
}
const wrapper = shallow(<ResponseBody {...props} />)
expect(wrapper.text()).toMatch(/Download file/)
})

it("should not render Download file link for empty response", function () {
props.contentType = "application/octet-stream"
props.content = new Blob()
Expand Down

0 comments on commit f803fa3

Please sign in to comment.