|
| 1 | +import { readFileSync } from "node:fs"; |
| 2 | + |
| 3 | +import { describe, expect, it } from "vitest"; |
| 4 | + |
| 5 | +const editorSources = { |
| 6 | + base: readEditorSource("base"), |
| 7 | + board: readEditorSource("board"), |
| 8 | + doc: readEditorSource("doc"), |
| 9 | + sheet: readEditorSource("sheet"), |
| 10 | + slide: readEditorSource("slide"), |
| 11 | +}; |
| 12 | +const globalStyles = readFileSync( |
| 13 | + new URL("../../web/src/app/styles/global.css", import.meta.url), |
| 14 | + "utf8" |
| 15 | +); |
| 16 | + |
| 17 | +describe("editor integration assets", () => { |
| 18 | + it("loads shared styles before manual Plugin Mode product styles", () => { |
| 19 | + expectImportsInOrder(editorSources.base, [ |
| 20 | + "@univerjs/design/lib/index.css", |
| 21 | + "@univerjs/ui/lib/index.css", |
| 22 | + "@univerjs-pro/bases-ui/lib/index.css", |
| 23 | + "@univerjs-pro/bases-exchange-client/lib/index.css", |
| 24 | + ]); |
| 25 | + expectImportsInOrder(editorSources.slide, [ |
| 26 | + "@univerjs/design/lib/index.css", |
| 27 | + "@univerjs/ui/lib/index.css", |
| 28 | + "@univerjs/docs-ui/lib/index.css", |
| 29 | + "@univerjs/drawing-ui/lib/index.css", |
| 30 | + "@univerjs-pro/chart-ui/lib/index.css", |
| 31 | + "@univerjs-pro/shape-editor-ui/lib/index.css", |
| 32 | + "@univerjs-pro/slides-ui/lib/index.css", |
| 33 | + "@univerjs-pro/slides-chart-ui/lib/index.css", |
| 34 | + "@univerjs-pro/slides-print/lib/index.css", |
| 35 | + "@univerjs-pro/slides-table-ui/lib/index.css", |
| 36 | + ]); |
| 37 | + expectImportsInOrder(editorSources.board, [ |
| 38 | + "@univerjs/design/lib/index.css", |
| 39 | + "@univerjs/ui/lib/index.css", |
| 40 | + "@univerjs/docs-ui/lib/index.css", |
| 41 | + "@univerjs/drawing-ui/lib/index.css", |
| 42 | + "@univerjs-pro/chart-ui/lib/index.css", |
| 43 | + "@univerjs-pro/shape-editor-ui/lib/index.css", |
| 44 | + "@univerjs-pro/ink-ui/lib/index.css", |
| 45 | + "@univerjs-pro/docs-latex-ui/lib/index.css", |
| 46 | + "@univerjs-pro/boards-ui/lib/index.css", |
| 47 | + "@univerjs-pro/boards-chart-ui/lib/index.css", |
| 48 | + "@univerjs-pro/boards-mind-ui/lib/index.css", |
| 49 | + "@univerjs-pro/boards-print/lib/index.css", |
| 50 | + "@univerjs-pro/boards-table-ui/lib/index.css", |
| 51 | + ]); |
| 52 | + }); |
| 53 | + |
| 54 | + it("loads shared Pro styles before Doc feature styles", () => { |
| 55 | + expectImportsInOrder(editorSources.doc, [ |
| 56 | + "@univerjs/preset-docs-core/lib/index.css", |
| 57 | + "@univerjs/preset-docs-drawing/lib/index.css", |
| 58 | + "@univerjs/preset-docs-hyper-link/lib/index.css", |
| 59 | + "@univerjs/preset-docs-thread-comment/lib/index.css", |
| 60 | + "@univerjs-pro/chart-ui/lib/index.css", |
| 61 | + "@univerjs-pro/shape-editor-ui/lib/index.css", |
| 62 | + "@univerjs-pro/docs-callout-ui/lib/index.css", |
| 63 | + "@univerjs-pro/docs-chart-ui/lib/index.css", |
| 64 | + "@univerjs-pro/docs-code-ui/lib/index.css", |
| 65 | + "@univerjs-pro/docs-latex-ui/lib/index.css", |
| 66 | + "@univerjs-pro/docs-print/lib/index.css", |
| 67 | + "@univerjs-pro/docs-shape-ui/lib/index.css", |
| 68 | + "@univerjs-pro/docs-table-ui/lib/index.css", |
| 69 | + ]); |
| 70 | + }); |
| 71 | + |
| 72 | + it("loads the public Facade entries for every installed editor feature", () => { |
| 73 | + expectImports(editorSources.doc, [ |
| 74 | + "@univerjs-pro/chart-ui/facade", |
| 75 | + "@univerjs-pro/docs-callout/facade", |
| 76 | + "@univerjs-pro/docs-chart/facade", |
| 77 | + "@univerjs-pro/docs-code/facade", |
| 78 | + "@univerjs-pro/docs-exchange-client/facade", |
| 79 | + "@univerjs-pro/docs-latex/facade", |
| 80 | + "@univerjs-pro/docs-shape/facade", |
| 81 | + "@univerjs-pro/docs-table/facade", |
| 82 | + "@univerjs-pro/engine-chart/facade", |
| 83 | + ]); |
| 84 | + expectImports(editorSources.slide, [ |
| 85 | + "@univerjs-pro/chart-ui/facade", |
| 86 | + "@univerjs-pro/engine-chart/facade", |
| 87 | + "@univerjs-pro/slides/facade", |
| 88 | + "@univerjs-pro/slides-chart/facade", |
| 89 | + "@univerjs-pro/slides-exchange-client/facade", |
| 90 | + "@univerjs-pro/slides-print/facade", |
| 91 | + "@univerjs-pro/slides-table/facade", |
| 92 | + ]); |
| 93 | + expectImports(editorSources.base, [ |
| 94 | + "@univerjs-pro/bases/facade", |
| 95 | + "@univerjs-pro/bases-exchange-client/facade", |
| 96 | + "@univerjs-pro/bases-ui/facade", |
| 97 | + ]); |
| 98 | + expectImports(editorSources.board, [ |
| 99 | + "@univerjs-pro/boards/facade", |
| 100 | + "@univerjs-pro/boards-chart/facade", |
| 101 | + "@univerjs-pro/boards-mind/facade", |
| 102 | + "@univerjs-pro/boards-table/facade", |
| 103 | + "@univerjs-pro/boards-ui/facade", |
| 104 | + "@univerjs-pro/chart-ui/facade", |
| 105 | + "@univerjs-pro/engine-chart/facade", |
| 106 | + ]); |
| 107 | + }); |
| 108 | + |
| 109 | + it("keeps the Base-only status and footer out of the Workspace shell", () => { |
| 110 | + expect(editorSources.base).toContain("hideCollaborationStatus: true"); |
| 111 | + expect(editorSources.base).toContain("toolbar: false"); |
| 112 | + expect(editorSources.base).toContain("collaborationStatus: false"); |
| 113 | + expect(editorSources.base).toContain("footer: false"); |
| 114 | + expect(globalStyles).toContain( |
| 115 | + '[id^="univer-base-"] [data-u-comp="base-table-sidebar"] > :last-child' |
| 116 | + ); |
| 117 | + expect(globalStyles).toContain( |
| 118 | + '[id^="univer-base-"] [data-u-comp="base-canvas-container"]' |
| 119 | + ); |
| 120 | + }); |
| 121 | + |
| 122 | + it("registers the supported output plugins for each editor", () => { |
| 123 | + expect(editorSources.sheet).toContain("exchangeProvidedByPreset: true"); |
| 124 | + expect(editorSources.doc).toContain( |
| 125 | + "exchangeFeaturePlugins: () => [UniverDocsExchangeClientPlugin]" |
| 126 | + ); |
| 127 | + expect(editorSources.doc).toContain( |
| 128 | + "printFeaturePlugins: () => [UniverDocsPrintPlugin]" |
| 129 | + ); |
| 130 | + expect(editorSources.slide).toContain( |
| 131 | + "exchangeFeaturePlugins: () => [UniverSlidesExchangeClientPlugin]" |
| 132 | + ); |
| 133 | + expect(editorSources.slide).toContain( |
| 134 | + "printFeaturePlugins: () => [UniverSlidesPrintPlugin]" |
| 135 | + ); |
| 136 | + expect(editorSources.base).toContain( |
| 137 | + "exchangeFeaturePlugins: () => [UniverBasesExchangeClientPlugin]" |
| 138 | + ); |
| 139 | + expect(editorSources.board).toContain("exchangeEnabled: false"); |
| 140 | + expect(editorSources.board).toContain( |
| 141 | + "printFeaturePlugins: () => [UniverBoardsPrintPlugin]" |
| 142 | + ); |
| 143 | + }); |
| 144 | + |
| 145 | + it("keeps Board chrome out and contains viewport overscroll", () => { |
| 146 | + expect(editorSources.board).toContain("hideCollaborationStatus: true"); |
| 147 | + expect(editorSources.board).toContain("header: false"); |
| 148 | + expect(editorSources.board).toContain("toolbar: false"); |
| 149 | + expect(editorSources.board).toContain("footer: false"); |
| 150 | + expect(globalStyles).toContain("overscroll-behavior: none"); |
| 151 | + expect(globalStyles).toContain(".univer-editor-shell"); |
| 152 | + expect(globalStyles).toContain("overflow: hidden"); |
| 153 | + }); |
| 154 | +}); |
| 155 | + |
| 156 | +function readEditorSource(product: string): string { |
| 157 | + return readFileSync( |
| 158 | + new URL(`../../web/src/features/editor/${product}-editor.tsx`, import.meta.url), |
| 159 | + "utf8" |
| 160 | + ); |
| 161 | +} |
| 162 | + |
| 163 | +function expectImports(source: string, specifiers: readonly string[]): void { |
| 164 | + for (const specifier of specifiers) { |
| 165 | + expect(source, `missing side-effect import: ${specifier}`).toContain( |
| 166 | + `import "${specifier}";` |
| 167 | + ); |
| 168 | + } |
| 169 | +} |
| 170 | + |
| 171 | +function expectImportsInOrder( |
| 172 | + source: string, |
| 173 | + specifiers: readonly string[] |
| 174 | +): void { |
| 175 | + expectImports(source, specifiers); |
| 176 | + const indexes = specifiers.map((specifier) => |
| 177 | + source.indexOf(`import "${specifier}";`) |
| 178 | + ); |
| 179 | + expect(indexes, `incorrect import order: ${specifiers.join(" -> ")}`).toEqual( |
| 180 | + [...indexes].sort((left, right) => left - right) |
| 181 | + ); |
| 182 | +} |
0 commit comments