Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/form-builder/components/FormList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default class FormList extends Component {
<b className="privilege-icon" hidden={!rowItem.published}>
{this._privilegesIcon(rowItem)}</b>
<a hidden={!rowItem.published}
onClick={() => this.pdfPreview(index)}
onClick={() => this.downloadPDFFile(index)}
>
<i className="fa fa-file-pdf-o" title="Download PDF Form" />
</a>
Expand Down Expand Up @@ -88,9 +88,9 @@ export default class FormList extends Component {
console.log(formData);
try {
httpInterceptor.post(formBuilderConstants.jsonToPdfConvertionUrl, formData).then((response) => {
let fileName = response.pdfName;
const fileName = response.pdfName;
const link = formBuilderConstants.pdfDownloadUrl + fileName;
window.open(`/pdf/${fileName}`, '_self');
window.open(link, '_self');
});
} catch (error) {
console.log('error state');
Expand Down
29 changes: 29 additions & 0 deletions test/form-builder/components/FormList.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,35 @@ describe('FormList', () => {
}, 500);
});

it('should call downloadPDFFile and open the download link when PDF icon be clicked', (done) => {
const formJson = { name: 'BP', version: '1.2' };
const translations = [];
const pdfResponse = { pdfName: 'BP_1.2.pdf' };
const getStub = sinon.stub(httpInterceptor, 'get');
getStub.onFirstCall().returns(Promise.resolve(formJson))
.onSecondCall().returns(Promise.resolve(translations));
const postStub = sinon.stub(httpInterceptor, 'post').returns(Promise.resolve(pdfResponse));
const windowOpenStub = sinon.stub(window, 'open');

wrapper = shallow(<FormList data={data} handleSelectedForm={undefined} />);
const pdfElement = getItem(1, 5).find('.fa-file-pdf-o').parent();
pdfElement.simulate('click');

setTimeout(() => {
sinon.assert.calledOnce(postStub);
sinon.assert.calledWith(postStub, formBuilderConstants.jsonToPdfConvertionUrl);
sinon.assert.calledWith(
windowOpenStub,
`${formBuilderConstants.pdfDownloadUrl}${pdfResponse.pdfName}`,
'_self'
);
getStub.restore();
postStub.restore();
windowOpenStub.restore();
done();
}, 500);
});

it('should show translate button only for latest Published forms', () => {
const form = {
id: 4,
Expand Down
Loading