Skip to content

Commit

Permalink
Refactor: applying pierres feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
mekkyz committed Sep 18, 2023
1 parent afa4114 commit 03c15b8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -498,23 +498,35 @@ ResearchPlanDetailsAttachments.propTypes = {
).isRequired,
attachments: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.number.isRequired,
id: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number
]).isRequired,
aasm_state: PropTypes.string.isRequired,
content_type: PropTypes.string.isRequired,
filename: PropTypes.string.isRequired,
filesize: PropTypes.number.isRequired,
identifier: PropTypes.string.isRequired,
identifier: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number
]).isRequired,
thumb: PropTypes.bool.isRequired
})
)
}).isRequired,
attachments: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.number.isRequired,
id: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number
]).isRequired,
aasm_state: PropTypes.string.isRequired,
content_type: PropTypes.string.isRequired,
filename: PropTypes.string.isRequired,
filesize: PropTypes.number.isRequired,
identifier: PropTypes.string.isRequired,
identifier: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number
]).isRequired,
thumb: PropTypes.bool.isRequired
})),
onDrop: PropTypes.func.isRequired,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global describe, context, it */
/* global describe, context, it, beforeEach, afterEach */

import React from 'react';
import expect from 'expect';
Expand All @@ -17,12 +17,24 @@ import uuid from 'uuid';
import ElementStore from 'src/stores/alt/stores/ElementStore';

import ResearchPlanDetails from 'src/apps/mydb/elements/details/researchPlans/ResearchPlanDetails';
import sinon from 'sinon';
import CommentActions from 'src/stores/alt/actions/CommentActions';

Enzyme.configure({
adapter: new Adapter(),
});

describe('ResearchPlanDetails', async () => {
let stub;

beforeEach(() => {
stub = sinon.stub(CommentActions, 'fetchComments');
stub.returns(Promise.resolve());
});
afterEach(() => {
stub.restore();
});

const FIELD_ID_IMAGE = 'entry-001';
const FIELD_ID_NO_IMAGE = 'entry-002';
describe('.handleBodyChange', async () => {
Expand All @@ -35,8 +47,7 @@ describe('ResearchPlanDetails', async () => {
<ResearchPlanDetails
researchPlan={researchPlanWithImage}
toggleFullScreen={() => {}}
/>,
{ disableLifecycleMethods: true }
/>
);
wrapper.instance().handleBodyChange({}, 'nonExistingFieldId', []);

Expand All @@ -54,8 +65,7 @@ describe('ResearchPlanDetails', async () => {
<ResearchPlanDetails
researchPlan={researchPlanWithoutImage}
toggleFullScreen={() => {}}
/>,
{ disableLifecycleMethods: true }
/>
);

wrapper.instance().handleBodyChange(
Expand Down Expand Up @@ -101,8 +111,7 @@ describe('ResearchPlanDetails', async () => {
<ResearchPlanDetails
researchPlan={researchPlanWithImage}
toggleFullScreen={() => {}}
/>,
{ disableLifecycleMethods: true }
/>
);

wrapper
Expand Down Expand Up @@ -146,8 +155,7 @@ describe('ResearchPlanDetails', async () => {
<ResearchPlanDetails
researchPlan={researchPlanWithImage}
toggleFullScreen={() => {}}
/>,
{ disableLifecycleMethods: true }
/>
);

wrapper
Expand Down Expand Up @@ -187,8 +195,7 @@ describe('ResearchPlanDetails', async () => {
<ResearchPlanDetails
researchPlan={researchPlanWithImage}
toggleFullScreen={() => {}}
/>,
{ disableLifecycleMethods: true }
/>
);

wrapper
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global describe, it, beforeEach, afterEach */
/* global describe, it */

import React from 'react';
import expect from 'expect';
Expand All @@ -18,25 +18,12 @@ import ResearchPlanDetailsAttachments from
Enzyme.configure({ adapter: new Adapter() });

describe('ResearchPlanDetailsAttachments', async () => {
let stub;
beforeEach(() => { stub = sinon.stub(console, 'error'); });
afterEach(() => { stub.restore(); });

describe('.createAttachmentPreviews()', async () => {
describe('.when preview was changed', async () => {
it('new preview is rendered', async () => {
const researchPlanWithAttachment = await ResearchPlanFactory.build(
'with attachment_not_in_body'
);

// Convert id to number
if (researchPlanWithAttachment.attachments) {
researchPlanWithAttachment.attachments.forEach((attachment) => {
attachment.id = Number(attachment.id);
attachment.identifier = String(attachment.identifier);
});
}

sinon
.stub(EditorFetcher, 'initial')
.callsFake(() => new Promise(() => {}));
Expand Down

0 comments on commit 03c15b8

Please sign in to comment.