|
@@ -2,13 +2,28 @@ import { ContextRoot } from '../js/shared/context/root-context'
|
|
|
import FileView from '../js/features/file-view/components/file-view'
|
|
import FileView from '../js/features/file-view/components/file-view'
|
|
|
import useFetchMock from './hooks/use-fetch-mock'
|
|
import useFetchMock from './hooks/use-fetch-mock'
|
|
|
|
|
|
|
|
|
|
+const bodies = {
|
|
|
|
|
+ latex: `\\documentclass{article}
|
|
|
|
|
+\\begin{document}
|
|
|
|
|
+First document. This is a simple example, with no
|
|
|
|
|
+extra parameters or packages included.
|
|
|
|
|
+\\end{document}`,
|
|
|
|
|
+ bibtex: `@book{latexcompanion,
|
|
|
|
|
+ author = "Michel Goossens and Frank Mittelbach and Alexander Samarin",
|
|
|
|
|
+ title = "The \\LaTeX\\ Companion",
|
|
|
|
|
+ year = "1993",
|
|
|
|
|
+ publisher = "Addison-Wesley",
|
|
|
|
|
+ address = "Reading, Massachusetts"
|
|
|
|
|
+}`,
|
|
|
|
|
+ text: `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.`,
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
const setupFetchMock = fetchMock => {
|
|
const setupFetchMock = fetchMock => {
|
|
|
- fetchMock
|
|
|
|
|
|
|
+ return fetchMock
|
|
|
.head('express:/project/:project_id/file/:file_id', {
|
|
.head('express:/project/:project_id/file/:file_id', {
|
|
|
status: 201,
|
|
status: 201,
|
|
|
headers: { 'Content-Length': 10000 },
|
|
headers: { 'Content-Length': 10000 },
|
|
|
})
|
|
})
|
|
|
- .get('express:/project/:project_id/file/:file_id', 'Text file content')
|
|
|
|
|
.post('express:/project/:project_id/linked_file/:file_id/refresh', {
|
|
.post('express:/project/:project_id/linked_file/:file_id/refresh', {
|
|
|
status: 204,
|
|
status: 204,
|
|
|
})
|
|
})
|
|
@@ -24,19 +39,33 @@ const fileData = {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export const FileFromUrl = args => {
|
|
export const FileFromUrl = args => {
|
|
|
|
|
+ useFetchMock(fetchMock =>
|
|
|
|
|
+ setupFetchMock(fetchMock).get(
|
|
|
|
|
+ 'express:/project/:project_id/file/:file_id',
|
|
|
|
|
+ { body: bodies.latex }
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
return <FileView {...args} />
|
|
return <FileView {...args} />
|
|
|
}
|
|
}
|
|
|
FileFromUrl.args = {
|
|
FileFromUrl.args = {
|
|
|
file: {
|
|
file: {
|
|
|
...fileData,
|
|
...fileData,
|
|
|
linkedFileData: {
|
|
linkedFileData: {
|
|
|
- url: 'https://overleaf.com',
|
|
|
|
|
|
|
+ url: 'https://example.com/source-file.tex',
|
|
|
provider: 'url',
|
|
provider: 'url',
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export const FileFromProjectWithLinkableProjectId = args => {
|
|
export const FileFromProjectWithLinkableProjectId = args => {
|
|
|
|
|
+ useFetchMock(fetchMock =>
|
|
|
|
|
+ setupFetchMock(fetchMock).get(
|
|
|
|
|
+ 'express:/project/:project_id/file/:file_id',
|
|
|
|
|
+ { body: bodies.latex }
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
return <FileView {...args} />
|
|
return <FileView {...args} />
|
|
|
}
|
|
}
|
|
|
FileFromProjectWithLinkableProjectId.args = {
|
|
FileFromProjectWithLinkableProjectId.args = {
|
|
@@ -44,13 +73,20 @@ FileFromProjectWithLinkableProjectId.args = {
|
|
|
...fileData,
|
|
...fileData,
|
|
|
linkedFileData: {
|
|
linkedFileData: {
|
|
|
source_project_id: 'source-project-id',
|
|
source_project_id: 'source-project-id',
|
|
|
- source_entity_path: '/source-entity-path.ext',
|
|
|
|
|
|
|
+ source_entity_path: '/source-file.tex',
|
|
|
provider: 'project_file',
|
|
provider: 'project_file',
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export const FileFromProjectWithoutLinkableProjectId = args => {
|
|
export const FileFromProjectWithoutLinkableProjectId = args => {
|
|
|
|
|
+ useFetchMock(fetchMock =>
|
|
|
|
|
+ setupFetchMock(fetchMock).get(
|
|
|
|
|
+ 'express:/project/:project_id/file/:file_id',
|
|
|
|
|
+ { body: bodies.latex }
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
return <FileView {...args} />
|
|
return <FileView {...args} />
|
|
|
}
|
|
}
|
|
|
FileFromProjectWithoutLinkableProjectId.args = {
|
|
FileFromProjectWithoutLinkableProjectId.args = {
|
|
@@ -58,13 +94,20 @@ FileFromProjectWithoutLinkableProjectId.args = {
|
|
|
...fileData,
|
|
...fileData,
|
|
|
linkedFileData: {
|
|
linkedFileData: {
|
|
|
v1_source_doc_id: 'v1-source-id',
|
|
v1_source_doc_id: 'v1-source-id',
|
|
|
- source_entity_path: '/source-entity-path.ext',
|
|
|
|
|
|
|
+ source_entity_path: '/source-file.tex',
|
|
|
provider: 'project_file',
|
|
provider: 'project_file',
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export const FileFromProjectOutputWithLinkableProject = args => {
|
|
export const FileFromProjectOutputWithLinkableProject = args => {
|
|
|
|
|
+ useFetchMock(fetchMock =>
|
|
|
|
|
+ setupFetchMock(fetchMock).get(
|
|
|
|
|
+ 'express:/project/:project_id/file/:file_id',
|
|
|
|
|
+ { body: bodies.latex }
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
return <FileView {...args} />
|
|
return <FileView {...args} />
|
|
|
}
|
|
}
|
|
|
FileFromProjectOutputWithLinkableProject.args = {
|
|
FileFromProjectOutputWithLinkableProject.args = {
|
|
@@ -72,13 +115,20 @@ FileFromProjectOutputWithLinkableProject.args = {
|
|
|
...fileData,
|
|
...fileData,
|
|
|
linkedFileData: {
|
|
linkedFileData: {
|
|
|
source_project_id: 'source_project_id',
|
|
source_project_id: 'source_project_id',
|
|
|
- source_output_file_path: '/source-entity-path.ext',
|
|
|
|
|
|
|
+ source_output_file_path: '/source-file.tex',
|
|
|
provider: 'project_output_file',
|
|
provider: 'project_output_file',
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export const FileFromProjectOutputWithoutLinkableProjectId = args => {
|
|
export const FileFromProjectOutputWithoutLinkableProjectId = args => {
|
|
|
|
|
+ useFetchMock(fetchMock =>
|
|
|
|
|
+ setupFetchMock(fetchMock).get(
|
|
|
|
|
+ 'express:/project/:project_id/file/:file_id',
|
|
|
|
|
+ { body: bodies.latex }
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
return <FileView {...args} />
|
|
return <FileView {...args} />
|
|
|
}
|
|
}
|
|
|
FileFromProjectOutputWithoutLinkableProjectId.args = {
|
|
FileFromProjectOutputWithoutLinkableProjectId.args = {
|
|
@@ -86,15 +136,18 @@ FileFromProjectOutputWithoutLinkableProjectId.args = {
|
|
|
...fileData,
|
|
...fileData,
|
|
|
linkedFileData: {
|
|
linkedFileData: {
|
|
|
v1_source_doc_id: 'v1-source-id',
|
|
v1_source_doc_id: 'v1-source-id',
|
|
|
- source_output_file_path: '/source-entity-path.ext',
|
|
|
|
|
|
|
+ source_output_file_path: '/source-file.tex',
|
|
|
provider: 'project_output_file',
|
|
provider: 'project_output_file',
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export const ImageFile = args => {
|
|
export const ImageFile = args => {
|
|
|
|
|
+ useFetchMock(setupFetchMock) // NOTE: can't mock img src request
|
|
|
|
|
+
|
|
|
return <FileView {...args} />
|
|
return <FileView {...args} />
|
|
|
}
|
|
}
|
|
|
|
|
+ImageFile.storyName = 'Image File (Error)'
|
|
|
ImageFile.args = {
|
|
ImageFile.args = {
|
|
|
file: {
|
|
file: {
|
|
|
...fileData,
|
|
...fileData,
|
|
@@ -102,20 +155,27 @@ ImageFile.args = {
|
|
|
name: 'file.jpg',
|
|
name: 'file.jpg',
|
|
|
linkedFileData: {
|
|
linkedFileData: {
|
|
|
source_project_id: 'source_project_id',
|
|
source_project_id: 'source_project_id',
|
|
|
- source_entity_path: '/source-entity-path',
|
|
|
|
|
|
|
+ source_entity_path: '/source-file.jpg',
|
|
|
provider: 'project_file',
|
|
provider: 'project_file',
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export const ThirdPartyReferenceFile = args => {
|
|
export const ThirdPartyReferenceFile = args => {
|
|
|
|
|
+ useFetchMock(fetchMock =>
|
|
|
|
|
+ setupFetchMock(fetchMock).get(
|
|
|
|
|
+ 'express:/project/:project_id/file/:file_id',
|
|
|
|
|
+ { body: bodies.bibtex }
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
return <FileView {...args} />
|
|
return <FileView {...args} />
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ThirdPartyReferenceFile.args = {
|
|
ThirdPartyReferenceFile.args = {
|
|
|
file: {
|
|
file: {
|
|
|
...fileData,
|
|
...fileData,
|
|
|
- name: 'example.tex',
|
|
|
|
|
|
|
+ name: 'references.bib',
|
|
|
linkedFileData: {
|
|
linkedFileData: {
|
|
|
provider: 'zotero',
|
|
provider: 'zotero',
|
|
|
},
|
|
},
|
|
@@ -123,13 +183,22 @@ ThirdPartyReferenceFile.args = {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export const ThirdPartyReferenceFileWithError = args => {
|
|
export const ThirdPartyReferenceFileWithError = args => {
|
|
|
|
|
+ useFetchMock(fetchMock =>
|
|
|
|
|
+ setupFetchMock(fetchMock).head(
|
|
|
|
|
+ 'express:/project/:project_id/file/:file_id',
|
|
|
|
|
+ { status: 500 },
|
|
|
|
|
+ { overwriteRoutes: true }
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
return <FileView {...args} />
|
|
return <FileView {...args} />
|
|
|
}
|
|
}
|
|
|
|
|
+ThirdPartyReferenceFileWithError.storyName =
|
|
|
|
|
+ 'Third Party Reference File (Error)'
|
|
|
ThirdPartyReferenceFileWithError.args = {
|
|
ThirdPartyReferenceFileWithError.args = {
|
|
|
file: {
|
|
file: {
|
|
|
...fileData,
|
|
...fileData,
|
|
|
id: '500500500500500500500500',
|
|
id: '500500500500500500500500',
|
|
|
- name: 'example.tex',
|
|
|
|
|
|
|
+ name: 'references.bib',
|
|
|
linkedFileData: {
|
|
linkedFileData: {
|
|
|
provider: 'zotero',
|
|
provider: 'zotero',
|
|
|
},
|
|
},
|
|
@@ -137,6 +206,13 @@ ThirdPartyReferenceFileWithError.args = {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export const TextFile = args => {
|
|
export const TextFile = args => {
|
|
|
|
|
+ useFetchMock(fetchMock =>
|
|
|
|
|
+ setupFetchMock(fetchMock).get(
|
|
|
|
|
+ 'express:/project/:project_id/file/:file_id',
|
|
|
|
|
+ { body: bodies.text },
|
|
|
|
|
+ { overwriteRoutes: true }
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
return <FileView {...args} />
|
|
return <FileView {...args} />
|
|
|
}
|
|
}
|
|
|
TextFile.args = {
|
|
TextFile.args = {
|
|
@@ -144,7 +220,7 @@ TextFile.args = {
|
|
|
...fileData,
|
|
...fileData,
|
|
|
linkedFileData: {
|
|
linkedFileData: {
|
|
|
source_project_id: 'source-project-id',
|
|
source_project_id: 'source-project-id',
|
|
|
- source_entity_path: '/source-entity-path.ext',
|
|
|
|
|
|
|
+ source_entity_path: '/source-file.txt',
|
|
|
provider: 'project_file',
|
|
provider: 'project_file',
|
|
|
},
|
|
},
|
|
|
name: 'file.txt',
|
|
name: 'file.txt',
|
|
@@ -152,8 +228,16 @@ TextFile.args = {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export const UploadedFile = args => {
|
|
export const UploadedFile = args => {
|
|
|
|
|
+ useFetchMock(fetchMock =>
|
|
|
|
|
+ setupFetchMock(fetchMock).head(
|
|
|
|
|
+ 'express:/project/:project_id/file/:file_id',
|
|
|
|
|
+ { status: 500 },
|
|
|
|
|
+ { overwriteRoutes: true }
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
return <FileView {...args} />
|
|
return <FileView {...args} />
|
|
|
}
|
|
}
|
|
|
|
|
+UploadedFile.storyName = 'Uploaded File (Error)'
|
|
|
UploadedFile.args = {
|
|
UploadedFile.args = {
|
|
|
file: {
|
|
file: {
|
|
|
...fileData,
|
|
...fileData,
|
|
@@ -165,21 +249,14 @@ UploadedFile.args = {
|
|
|
export default {
|
|
export default {
|
|
|
title: 'FileView',
|
|
title: 'FileView',
|
|
|
component: FileView,
|
|
component: FileView,
|
|
|
- args: {
|
|
|
|
|
- storeReferencesKeys: () => {},
|
|
|
|
|
|
|
+ argTypes: {
|
|
|
|
|
+ storeReferencesKeys: { action: 'store references keys' },
|
|
|
},
|
|
},
|
|
|
decorators: [
|
|
decorators: [
|
|
|
- Story => {
|
|
|
|
|
- useFetchMock(setupFetchMock)
|
|
|
|
|
- return <Story />
|
|
|
|
|
- },
|
|
|
|
|
Story => (
|
|
Story => (
|
|
|
- <>
|
|
|
|
|
- <style>{'html, body { height: 100%; }'}</style>
|
|
|
|
|
- <ContextRoot ide={window._ide} settings={{}}>
|
|
|
|
|
- <Story />
|
|
|
|
|
- </ContextRoot>
|
|
|
|
|
- </>
|
|
|
|
|
|
|
+ <ContextRoot ide={window._ide} settings={{}}>
|
|
|
|
|
+ <Story />
|
|
|
|
|
+ </ContextRoot>
|
|
|
),
|
|
),
|
|
|
],
|
|
],
|
|
|
}
|
|
}
|