Move project context out of scope value store (#26615)
* Refactor project context to not use scope store * Fix Cypress tests for project context changes * Fix frontend React Testing Library tests for project context changes * Remove redundant code * Fix some project types in tests * Remove unused import and fix a type * Throw an error if updating the project in the project context before joining the project * Fix some review panel tests * Remove unused imports GitOrigin-RevId: 2f0c928b651f387aa980c29aef7d1ba0649790a7
This commit is contained in:
-3
@@ -64,7 +64,6 @@ describe('autocomplete', { scrollBehavior: false }, function () {
|
||||
]
|
||||
|
||||
const scope = mockScope()
|
||||
scope.project.rootFolder = rootFolder
|
||||
|
||||
cy.mount(
|
||||
<TestContainer>
|
||||
@@ -446,7 +445,6 @@ describe('autocomplete', { scrollBehavior: false }, function () {
|
||||
]
|
||||
|
||||
const scope = mockScope()
|
||||
scope.project.rootFolder = rootFolder
|
||||
|
||||
cy.mount(
|
||||
<TestContainer>
|
||||
@@ -910,7 +908,6 @@ describe('autocomplete', { scrollBehavior: false }, function () {
|
||||
]
|
||||
|
||||
const scope = mockScope()
|
||||
scope.project.rootFolder = rootFolder
|
||||
|
||||
cy.mount(
|
||||
<TestContainer>
|
||||
|
||||
+9
@@ -2,12 +2,15 @@ import CodemirrorEditor from '../../../../../frontend/js/features/source-editor/
|
||||
import {
|
||||
EditorProviders,
|
||||
makeEditorPropertiesProvider,
|
||||
makeProjectProvider,
|
||||
USER_ID,
|
||||
} from '../../../helpers/editor-providers'
|
||||
import { mockScope, rootFolderId } from '../helpers/mock-scope'
|
||||
import { FC } from 'react'
|
||||
import { FileTreePathContext } from '@/features/file-tree/contexts/file-tree-path'
|
||||
import { TestContainer } from '../helpers/test-container'
|
||||
import getMeta from '@/utils/meta'
|
||||
import { mockProject } from '../helpers/mock-project'
|
||||
|
||||
const clickToolbarButton = (text: string) => {
|
||||
cy.findByLabelText(text).click()
|
||||
@@ -44,6 +47,11 @@ describe('<FigureModal />', function () {
|
||||
function mount() {
|
||||
const content = ''
|
||||
const scope = mockScope(content)
|
||||
const project = mockProject({
|
||||
projectOwner: {
|
||||
_id: USER_ID,
|
||||
},
|
||||
})
|
||||
|
||||
const FileTreePathProvider: FC<React.PropsWithChildren> = ({
|
||||
children,
|
||||
@@ -69,6 +77,7 @@ describe('<FigureModal />', function () {
|
||||
scope={scope}
|
||||
providers={{
|
||||
FileTreePathProvider,
|
||||
ProjectProvider: makeProjectProvider(project),
|
||||
EditorPropertiesProvider: makeEditorPropertiesProvider({
|
||||
showVisual: true,
|
||||
showSymbolPalette: false,
|
||||
|
||||
+10
-3
@@ -1,9 +1,13 @@
|
||||
import { mockScope } from '../helpers/mock-scope'
|
||||
import { EditorProviders } from '../../../helpers/editor-providers'
|
||||
import {
|
||||
EditorProviders,
|
||||
makeProjectProvider,
|
||||
} from '../../../helpers/editor-providers'
|
||||
import CodeMirrorEditor from '../../../../../frontend/js/features/source-editor/components/codemirror-editor'
|
||||
import { TestContainer } from '../helpers/test-container'
|
||||
import forEach from 'mocha-each'
|
||||
import PackageVersions from '../../../../../app/src/infrastructure/PackageVersions'
|
||||
import { mockProject } from '../helpers/mock-project'
|
||||
|
||||
const languages = [
|
||||
{ code: 'af', dic: 'af_ZA', name: 'Afrikaans' },
|
||||
@@ -125,11 +129,14 @@ forEach(Object.keys(suggestions)).describe(
|
||||
cy.interceptEvents()
|
||||
|
||||
const scope = mockScope(content)
|
||||
scope.project.spellCheckLanguage = spellCheckLanguage
|
||||
const project = mockProject({ spellCheckLanguage })
|
||||
|
||||
cy.mount(
|
||||
<TestContainer>
|
||||
<EditorProviders scope={scope}>
|
||||
<EditorProviders
|
||||
scope={scope}
|
||||
providers={{ ProjectProvider: makeProjectProvider(project) }}
|
||||
>
|
||||
<CodeMirrorEditor />
|
||||
</EditorProviders>
|
||||
</TestContainer>
|
||||
|
||||
+5
@@ -1,19 +1,24 @@
|
||||
import {
|
||||
EditorProviders,
|
||||
makeEditorPropertiesProvider,
|
||||
makeProjectProvider,
|
||||
} from '../../../helpers/editor-providers'
|
||||
import CodemirrorEditor from '../../../../../frontend/js/features/source-editor/components/codemirror-editor'
|
||||
import { mockScope } from '../helpers/mock-scope'
|
||||
import { TestContainer } from '../helpers/test-container'
|
||||
import { mockProject } from '../helpers/mock-project'
|
||||
|
||||
const mountEditor = (content: string) => {
|
||||
const scope = mockScope(content)
|
||||
|
||||
const project = mockProject()
|
||||
|
||||
cy.mount(
|
||||
<TestContainer>
|
||||
<EditorProviders
|
||||
scope={scope}
|
||||
providers={{
|
||||
ProjectProvider: makeProjectProvider(project),
|
||||
EditorPropertiesProvider: makeEditorPropertiesProvider({
|
||||
showVisual: true,
|
||||
showSymbolPalette: false,
|
||||
|
||||
+4
@@ -1,20 +1,24 @@
|
||||
import {
|
||||
EditorProviders,
|
||||
makeEditorPropertiesProvider,
|
||||
makeProjectProvider,
|
||||
} from '../../../helpers/editor-providers'
|
||||
import CodemirrorEditor from '../../../../../frontend/js/features/source-editor/components/codemirror-editor'
|
||||
import { mockScope } from '../helpers/mock-scope'
|
||||
import { TestContainer } from '../helpers/test-container'
|
||||
import { isMac } from '@/shared/utils/os'
|
||||
import { mockProject } from '../helpers/mock-project'
|
||||
|
||||
const mountEditor = (content: string) => {
|
||||
const scope = mockScope(content)
|
||||
const project = mockProject()
|
||||
|
||||
cy.mount(
|
||||
<TestContainer>
|
||||
<EditorProviders
|
||||
scope={scope}
|
||||
providers={{
|
||||
ProjectProvider: makeProjectProvider(project),
|
||||
EditorPropertiesProvider: makeEditorPropertiesProvider({
|
||||
showVisual: true,
|
||||
showSymbolPalette: false,
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
import { docId } from './mock-doc'
|
||||
import { Folder } from '../../../../../types/folder'
|
||||
import { UserId } from '../../../../../types/user'
|
||||
import { ProjectCompiler } from '../../../../../types/project-settings'
|
||||
|
||||
export const rootFolderId = '012345678901234567890123'
|
||||
export const figuresFolderId = '123456789012345678901234'
|
||||
export const figureId = '234567890123456789012345'
|
||||
export const mockProject = ({
|
||||
projectFeatures = {},
|
||||
projectOwner = undefined,
|
||||
spellCheckLanguage = 'en',
|
||||
rootFolder = null,
|
||||
}: any = {}) => {
|
||||
return {
|
||||
_id: 'test-project',
|
||||
name: 'Test Project',
|
||||
spellCheckLanguage,
|
||||
rootDocId: '_root_doc_id',
|
||||
rootFolder:
|
||||
rootFolder ||
|
||||
([
|
||||
{
|
||||
_id: rootFolderId,
|
||||
name: 'rootFolder',
|
||||
docs: [
|
||||
{
|
||||
_id: docId,
|
||||
name: 'test.tex',
|
||||
},
|
||||
],
|
||||
folders: [
|
||||
{
|
||||
_id: figuresFolderId,
|
||||
name: 'figures',
|
||||
docs: [
|
||||
{
|
||||
_id: 'fake-nested-doc-id',
|
||||
name: 'foo.tex',
|
||||
},
|
||||
],
|
||||
folders: [],
|
||||
fileRefs: [
|
||||
{
|
||||
_id: figureId,
|
||||
name: 'frog.jpg',
|
||||
hash: '42',
|
||||
},
|
||||
{
|
||||
_id: 'fake-figure-id',
|
||||
name: 'unicorn.png',
|
||||
hash: '43',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
fileRefs: [],
|
||||
},
|
||||
] as Folder[]),
|
||||
features: {
|
||||
trackChanges: true,
|
||||
...projectFeatures,
|
||||
},
|
||||
compiler: 'pdflatex' as ProjectCompiler,
|
||||
imageName: 'texlive-full:2024.1',
|
||||
trackChangesState: false,
|
||||
invites: [],
|
||||
members: [],
|
||||
owner: projectOwner || {
|
||||
_id: '124abd' as UserId,
|
||||
email: 'owner@example.com',
|
||||
first_name: 'Test',
|
||||
last_name: 'Owner',
|
||||
privileges: 'owner',
|
||||
signUpDate: new Date('2025-07-07').toISOString(),
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,10 @@
|
||||
import { docId, mockDoc } from './mock-doc'
|
||||
import { sleep } from '../../../helpers/sleep'
|
||||
import { Folder } from '../../../../../types/folder'
|
||||
|
||||
export const rootFolderId = '012345678901234567890123'
|
||||
export const figuresFolderId = '123456789012345678901234'
|
||||
export const figureId = '234567890123456789012345'
|
||||
export const mockScope = (
|
||||
content?: string,
|
||||
{
|
||||
docOptions = {},
|
||||
projectFeatures = {},
|
||||
permissions = {},
|
||||
projectOwner = undefined,
|
||||
}: any = {}
|
||||
{ docOptions = {}, permissions = {} }: any = {}
|
||||
) => {
|
||||
return {
|
||||
editor: {
|
||||
@@ -21,55 +13,8 @@ export const mockScope = (
|
||||
currentDocumentId: docId,
|
||||
wantTrackChanges: false,
|
||||
},
|
||||
project: {
|
||||
_id: 'test-project',
|
||||
name: 'Test Project',
|
||||
spellCheckLanguage: 'en',
|
||||
rootFolder: [
|
||||
{
|
||||
_id: rootFolderId,
|
||||
name: 'rootFolder',
|
||||
docs: [
|
||||
{
|
||||
_id: docId,
|
||||
name: 'test.tex',
|
||||
},
|
||||
],
|
||||
folders: [
|
||||
{
|
||||
_id: figuresFolderId,
|
||||
name: 'figures',
|
||||
docs: [
|
||||
{
|
||||
_id: 'fake-nested-doc-id',
|
||||
name: 'foo.tex',
|
||||
},
|
||||
],
|
||||
folders: [],
|
||||
fileRefs: [
|
||||
{
|
||||
_id: figureId,
|
||||
name: 'frog.jpg',
|
||||
hash: '42',
|
||||
},
|
||||
{
|
||||
_id: 'fake-figure-id',
|
||||
name: 'unicorn.png',
|
||||
hash: '43',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
fileRefs: [],
|
||||
},
|
||||
] as Folder[],
|
||||
features: {
|
||||
trackChanges: true,
|
||||
...projectFeatures,
|
||||
},
|
||||
trackChangesState: {},
|
||||
members: [],
|
||||
owner: projectOwner,
|
||||
pdf: {
|
||||
logEntryAnnotations: {},
|
||||
},
|
||||
permissions: {
|
||||
comment: true,
|
||||
|
||||
Reference in New Issue
Block a user