-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
267 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
app/react/ToggledFeatures/tocGeneration/ReviewTocButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react'; | ||
import { Icon } from 'UI'; | ||
import { FeatureToggle } from 'app/components/Elements/FeatureToggle'; | ||
import { connect, ConnectedProps } from 'react-redux'; | ||
import { bindActionCreators, Dispatch } from 'redux'; | ||
import { ClientFile } from 'app/istore'; | ||
import { tocGenerationActions } from './actions'; | ||
|
||
export interface ReviewTocButtonProps { | ||
file: ClientFile; | ||
children: JSX.Element | string; | ||
} | ||
|
||
const mapDispatchToProps = (dispatch: Dispatch<{}>) => | ||
bindActionCreators({ onClick: tocGenerationActions.reviewToc }, dispatch); | ||
|
||
const connector = connect(null, mapDispatchToProps); | ||
|
||
type MappedProps = ConnectedProps<typeof connector>; | ||
type ComponentProps = ReviewTocButtonProps & MappedProps; | ||
|
||
const ReviewTocButton = ({ file, onClick, children }: ComponentProps) => ( | ||
<FeatureToggle feature="tocGeneration"> | ||
{file.generatedToc && ( | ||
<button type="button" onClick={() => onClick(file._id)} className="edit-toc btn btn-success"> | ||
<Icon icon="pencil-alt" /> | ||
<span className="btn-label">{children}</span> | ||
</button> | ||
)} | ||
</FeatureToggle> | ||
); | ||
|
||
const container = connector(ReviewTocButton); | ||
export { container as ReviewTocButton }; |
14 changes: 14 additions & 0 deletions
14
app/react/ToggledFeatures/tocGeneration/TocGeneratedLabel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React from 'react'; | ||
import { FeatureToggle } from 'app/components/Elements/FeatureToggle'; | ||
import { FileType } from 'shared/types/fileType'; | ||
|
||
export interface TocGeneratedLabelProps { | ||
file: FileType; | ||
children: JSX.Element | string; | ||
} | ||
|
||
export const TocGeneratedLabel = ({ file, children }: TocGeneratedLabelProps) => ( | ||
<FeatureToggle feature="tocGeneration"> | ||
{file.generatedToc && <span className="label-generatedToc">{children}</span>} | ||
</FeatureToggle> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { actions } from 'app/BasicReducer/reducer'; | ||
import { actions as formActions } from 'react-redux-form'; | ||
import { RequestParams } from 'app/utils/RequestParams'; | ||
import api from 'app/utils/api'; | ||
import { notificationActions } from 'app/Notifications'; | ||
|
||
const tocGenerationActions = { | ||
reviewToc(fileId: string) { | ||
return async (dispatch, getState) => { | ||
const currentDoc = getState().documentViewer.doc.toJS(); | ||
dispatch(formActions.reset('documentViewer.sidepanel.metadata')); | ||
|
||
const updatedFile = (await api.post('files/tocReviewed', new RequestParams({ fileId }))).json; | ||
//WTF | ||
updatedFile.pdfInfo = {} | ||
const doc = { | ||
...currentDoc, | ||
defaultDoc: updatedFile, | ||
documents: currentDoc.documents.map(d => { | ||
if (d._id === updatedFile._id) { | ||
return updatedFile; | ||
} | ||
return d; | ||
}), | ||
}; | ||
|
||
dispatch(notificationActions.notify('Document updated', 'success')); | ||
dispatch(formActions.reset('documentViewer.sidepanel.metadata')); | ||
dispatch(actions.set('viewer/doc', doc)); | ||
}; | ||
}, | ||
}; | ||
|
||
export { tocGenerationActions }; |
37 changes: 37 additions & 0 deletions
37
app/react/ToggledFeatures/tocGeneration/specs/ReviewTocButton.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react'; | ||
import { shallow, ShallowWrapper } from 'enzyme'; | ||
import configureStore, { MockStore, MockStoreCreator } from 'redux-mock-store'; | ||
import { Provider } from 'react-redux'; | ||
import { FileType } from 'shared/types/fileType'; | ||
import { ReviewTocButton } from '../ReviewTocButton'; | ||
|
||
describe('ReviewTocButton', () => { | ||
let component: ShallowWrapper<typeof ReviewTocButton>; | ||
|
||
const mockStoreCreator: MockStoreCreator<object> = configureStore<object>([]); | ||
const render = (file: FileType) => { | ||
const store: MockStore<object> = mockStoreCreator({}); | ||
component = shallow( | ||
<Provider store={store}> | ||
<ReviewTocButton file={file}> | ||
<span>test</span> | ||
</ReviewTocButton> | ||
</Provider> | ||
) | ||
.dive() | ||
.dive(); | ||
}; | ||
|
||
it('should render nothing if file generatedToc is false', () => { | ||
render({ generatedToc: false }); | ||
expect(component.find('button').length).toEqual(0); | ||
|
||
render({}); | ||
expect(component.find('button').length).toEqual(0); | ||
}); | ||
|
||
it('should render when generatedToc is true', () => { | ||
render({ generatedToc: true }); | ||
expect(component.find('button').length).toEqual(1); | ||
}); | ||
}); |
91 changes: 91 additions & 0 deletions
91
app/react/ToggledFeatures/tocGeneration/specs/actions.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import api from 'app/utils/api'; | ||
import backend from 'fetch-mock'; | ||
import * as notificationsTypes from 'app/Notifications/actions/actionTypes'; | ||
import { actions as relationshipActions } from 'app/Relationships'; | ||
import { APIURL } from 'app/config'; | ||
import configureMockStore from 'redux-mock-store'; | ||
import thunk from 'redux-thunk'; | ||
import Immutable from 'immutable'; | ||
import { mockID } from 'shared/uniqueID.js'; | ||
import { tocGenerationActions } from '../actions'; | ||
|
||
const middlewares = [thunk]; | ||
const mockStore = configureMockStore(middlewares); | ||
|
||
describe('reviewToc', () => { | ||
it('should store the document with the response of reviewToc', done => { | ||
mockID(); | ||
const fileId = 'fileId'; | ||
|
||
backend.post(`${APIURL}files/tocReviewed`, { | ||
body: JSON.stringify({ _id: fileId, generatedToc: false }), | ||
}); | ||
|
||
spyOn(relationshipActions, 'reloadRelationships').and.returnValue({ | ||
type: 'reloadRelationships', | ||
}); | ||
|
||
const doc = { | ||
name: 'doc', | ||
_id: 'id', | ||
sharedId: 'sharedId', | ||
defaultDoc: { | ||
_id: fileId, | ||
generatedToc: true, | ||
}, | ||
documents: [ | ||
{ | ||
_id: fileId, | ||
generatedToc: true, | ||
}, | ||
], | ||
}; | ||
|
||
const updatedEntity = { | ||
name: 'doc', | ||
_id: 'id', | ||
sharedId: 'sharedId', | ||
defaultDoc: { | ||
_id: fileId, | ||
generatedToc: false, | ||
}, | ||
documents: [ | ||
{ | ||
_id: fileId, | ||
generatedToc: false, | ||
}, | ||
], | ||
}; | ||
|
||
const expectedActions = [ | ||
{ type: 'rrf/reset', model: 'documentViewer.sidepanel.metadata' }, | ||
{ | ||
type: notificationsTypes.NOTIFY, | ||
notification: { message: 'Document updated', type: 'success', id: 'unique_id' }, | ||
}, | ||
{ type: 'rrf/reset', model: 'documentViewer.sidepanel.metadata' }, | ||
{ type: 'viewer/doc/SET', value: updatedEntity }, | ||
]; | ||
|
||
const store = mockStore({ | ||
documentViewer: { | ||
doc: Immutable.fromJS(doc), | ||
}, | ||
}); | ||
|
||
spyOn(api, 'post').and.callThrough(); | ||
store | ||
.dispatch(tocGenerationActions.reviewToc(fileId)) | ||
.then(() => { | ||
expect(api.post).toHaveBeenCalledWith('files/tocReviewed', { | ||
data: { | ||
fileId: 'fileId', | ||
}, | ||
headers: {}, | ||
}); | ||
expect(store.getActions()).toEqual(expectedActions); | ||
}) | ||
.then(done) | ||
.catch(done.fail); | ||
}); | ||
}); |
Oops, something went wrong.