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({
);
// 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(
() => ({
annotations: exportableAnnotations,
......@@ -131,8 +132,10 @@ function ExportAnnotations({
switch (format) {
case 'json': {
const exportData =
annotationsExporter.buildJSONExportContent(annotationsToExport);
const exportData = annotationsExporter.buildJSONExportContent(
annotationsToExport,
{ profile },
);
downloadJSONFile(exportData, filename);
break;
}
......
import { trimAndDedent } from '../../shared/trim-and-dedent';
import type { APIAnnotationData } from '../../types/api';
import type { APIAnnotationData, Profile } from '../../types/api';
import {
documentMetadata,
isReply,
......@@ -9,7 +9,6 @@ import {
import { annotationDisplayName } from '../helpers/annotation-user';
import { stripInternalProperties } from '../helpers/strip-internal-properties';
import { VersionData } from '../helpers/version-data';
import type { SidebarStore } from '../store';
export type JSONExportContent = {
export_date: string;
......@@ -18,6 +17,11 @@ export type JSONExportContent = {
annotations: APIAnnotationData[];
};
export type JSONExportOptions = {
profile: Profile;
now?: Date;
};
export type TextExportOptions = {
defaultAuthority?: string;
displayNamesEnabled?: boolean;
......@@ -31,18 +35,14 @@ export type TextExportOptions = {
* @inject
*/
export class AnnotationsExporter {
private _store: SidebarStore;
constructor(store: SidebarStore) {
this._store = store;
}
buildJSONExportContent(
annotations: APIAnnotationData[],
/* istanbul ignore next - test seam */
now = new Date(),
{
profile,
/* istanbul ignore next - test seam */
now = new Date(),
}: JSONExportOptions,
): JSONExportContent {
const profile = this._store.profile();
const versionData = new VersionData(profile, []);
return {
......
......@@ -6,40 +6,41 @@ import {
import { AnnotationsExporter } from '../annotations-exporter';
describe('AnnotationsExporter', () => {
let fakeStore;
let now;
let exporter;
beforeEach(() => {
fakeStore = {
profile: sinon.stub().returns({ userid: 'userId' }),
};
now = new Date();
exporter = new AnnotationsExporter(fakeStore);
exporter = new AnnotationsExporter();
});
it('generates JSON content with provided annotations', () => {
const firstBaseAnnotation = publicAnnotation();
const secondBaseAnnotation = publicAnnotation();
const annotations = [
{
...firstBaseAnnotation,
$tag: '',
},
{
...secondBaseAnnotation,
$highlight: true,
},
];
const result = exporter.buildJSONExportContent(annotations, now);
assert.deepEqual(result, {
export_date: now.toISOString(),
export_userid: 'userId',
client_version: '__VERSION__',
annotations: [firstBaseAnnotation, secondBaseAnnotation],
describe('buildJSONExportContent', () => {
it('generates JSON content with provided annotations', () => {
const profile = { userid: 'userId' };
const firstBaseAnnotation = publicAnnotation();
const secondBaseAnnotation = publicAnnotation();
const annotations = [
{
...firstBaseAnnotation,
$tag: '',
},
{
...secondBaseAnnotation,
$highlight: true,
},
];
const result = exporter.buildJSONExportContent(annotations, {
now,
profile,
});
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