Commit 31c1555b authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Make AnnotationsExporter not depend on SidebarStore

parent 8ad4483e
...@@ -84,7 +84,8 @@ function ExportAnnotations({ ...@@ -84,7 +84,8 @@ function ExportAnnotations({
); );
// User whose annotations are going to be exported. // User whose annotations are going to be exported.
const currentUser = store.profile().userid; const profile = store.profile();
const currentUser = profile.userid;
const allAnnotationsOption: Omit<UserAnnotations, 'userid'> = useMemo( const allAnnotationsOption: Omit<UserAnnotations, 'userid'> = useMemo(
() => ({ () => ({
annotations: exportableAnnotations, annotations: exportableAnnotations,
...@@ -131,8 +132,10 @@ function ExportAnnotations({ ...@@ -131,8 +132,10 @@ function ExportAnnotations({
switch (format) { switch (format) {
case 'json': { case 'json': {
const exportData = const exportData = annotationsExporter.buildJSONExportContent(
annotationsExporter.buildJSONExportContent(annotationsToExport); annotationsToExport,
{ profile },
);
downloadJSONFile(exportData, filename); downloadJSONFile(exportData, filename);
break; break;
} }
......
import { trimAndDedent } from '../../shared/trim-and-dedent'; import { trimAndDedent } from '../../shared/trim-and-dedent';
import type { APIAnnotationData } from '../../types/api'; import type { APIAnnotationData, Profile } from '../../types/api';
import { import {
documentMetadata, documentMetadata,
isReply, isReply,
...@@ -9,7 +9,6 @@ import { ...@@ -9,7 +9,6 @@ import {
import { annotationDisplayName } from '../helpers/annotation-user'; import { annotationDisplayName } from '../helpers/annotation-user';
import { stripInternalProperties } from '../helpers/strip-internal-properties'; import { stripInternalProperties } from '../helpers/strip-internal-properties';
import { VersionData } from '../helpers/version-data'; import { VersionData } from '../helpers/version-data';
import type { SidebarStore } from '../store';
export type JSONExportContent = { export type JSONExportContent = {
export_date: string; export_date: string;
...@@ -18,6 +17,11 @@ export type JSONExportContent = { ...@@ -18,6 +17,11 @@ export type JSONExportContent = {
annotations: APIAnnotationData[]; annotations: APIAnnotationData[];
}; };
export type JSONExportOptions = {
profile: Profile;
now?: Date;
};
export type TextExportOptions = { export type TextExportOptions = {
defaultAuthority?: string; defaultAuthority?: string;
displayNamesEnabled?: boolean; displayNamesEnabled?: boolean;
...@@ -31,18 +35,14 @@ export type TextExportOptions = { ...@@ -31,18 +35,14 @@ export type TextExportOptions = {
* @inject * @inject
*/ */
export class AnnotationsExporter { export class AnnotationsExporter {
private _store: SidebarStore;
constructor(store: SidebarStore) {
this._store = store;
}
buildJSONExportContent( buildJSONExportContent(
annotations: APIAnnotationData[], annotations: APIAnnotationData[],
/* istanbul ignore next - test seam */ {
now = new Date(), profile,
/* istanbul ignore next - test seam */
now = new Date(),
}: JSONExportOptions,
): JSONExportContent { ): JSONExportContent {
const profile = this._store.profile();
const versionData = new VersionData(profile, []); const versionData = new VersionData(profile, []);
return { return {
......
...@@ -6,40 +6,41 @@ import { ...@@ -6,40 +6,41 @@ import {
import { AnnotationsExporter } from '../annotations-exporter'; import { AnnotationsExporter } from '../annotations-exporter';
describe('AnnotationsExporter', () => { describe('AnnotationsExporter', () => {
let fakeStore;
let now; let now;
let exporter; let exporter;
beforeEach(() => { beforeEach(() => {
fakeStore = {
profile: sinon.stub().returns({ userid: 'userId' }),
};
now = new Date(); now = new Date();
exporter = new AnnotationsExporter();
exporter = new AnnotationsExporter(fakeStore);
}); });
it('generates JSON content with provided annotations', () => { describe('buildJSONExportContent', () => {
const firstBaseAnnotation = publicAnnotation(); it('generates JSON content with provided annotations', () => {
const secondBaseAnnotation = publicAnnotation(); const profile = { userid: 'userId' };
const annotations = [ const firstBaseAnnotation = publicAnnotation();
{ const secondBaseAnnotation = publicAnnotation();
...firstBaseAnnotation, const annotations = [
$tag: '', {
}, ...firstBaseAnnotation,
{ $tag: '',
...secondBaseAnnotation, },
$highlight: true, {
}, ...secondBaseAnnotation,
]; $highlight: true,
},
const result = exporter.buildJSONExportContent(annotations, now); ];
assert.deepEqual(result, { const result = exporter.buildJSONExportContent(annotations, {
export_date: now.toISOString(), now,
export_userid: 'userId', profile,
client_version: '__VERSION__', });
annotations: [firstBaseAnnotation, secondBaseAnnotation],
assert.deepEqual(result, {
export_date: now.toISOString(),
export_userid: 'userId',
client_version: '__VERSION__',
annotations: [firstBaseAnnotation, secondBaseAnnotation],
});
}); });
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment