File tree Expand file tree Collapse file tree 11 files changed +260
-441
lines changed
src/frontend/apps/impress/src/features/docs Expand file tree Collapse file tree 11 files changed +260
-441
lines changed Original file line number Diff line number Diff line change
1
+ import { renderHook , waitFor } from '@testing-library/react' ;
2
+
3
+ import { AppWrapper } from '@/tests/utils' ;
4
+
5
+ // Mock the environment variable
6
+ const originalEnv = process . env . NEXT_PUBLIC_PUBLISH_AS_MIT ;
7
+
8
+ // Mock the libAGPL module
9
+ jest . mock (
10
+ '../../libAGPL' ,
11
+ ( ) => ( {
12
+ exportToPdf : jest . fn ( ) ,
13
+ exportToDocx : jest . fn ( ) ,
14
+ } ) ,
15
+ { virtual : true } ,
16
+ ) ;
17
+
18
+ describe ( 'useModuleExport' , ( ) => {
19
+ afterAll ( ( ) => {
20
+ process . env . NEXT_PUBLIC_PUBLISH_AS_MIT = originalEnv ;
21
+ } ) ;
22
+
23
+ it ( 'should load modules when NEXT_PUBLIC_PUBLISH_AS_MIT is false' , async ( ) => {
24
+ process . env . NEXT_PUBLIC_PUBLISH_AS_MIT = 'false' ;
25
+ const { useModuleExport } = await import ( '../useModuleExport' ) ;
26
+
27
+ const { result } = renderHook ( ( ) => useModuleExport ( ) , {
28
+ wrapper : AppWrapper ,
29
+ } ) ;
30
+
31
+ // Initial state should be undefined
32
+ expect ( result . current ) . toBeUndefined ( ) ;
33
+
34
+ // After effects run, it should contain the modules from libAGPL
35
+ await waitFor ( ( ) => {
36
+ expect ( result . current ) . toBeDefined ( ) ;
37
+ } ) ;
38
+
39
+ expect ( result . current ) . toHaveProperty ( 'exportToPdf' ) ;
40
+ expect ( result . current ) . toHaveProperty ( 'exportToDocx' ) ;
41
+ } ) ;
42
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import { renderHook } from '@testing-library/react' ;
2
+
3
+ import { AppWrapper } from '@/tests/utils' ;
4
+ import { sleep } from '@/utils' ;
5
+
6
+ const originalEnv = process . env . NEXT_PUBLIC_PUBLISH_AS_MIT ;
7
+
8
+ describe ( 'useModuleExport' , ( ) => {
9
+ afterAll ( ( ) => {
10
+ process . env . NEXT_PUBLIC_PUBLISH_AS_MIT = originalEnv ;
11
+ } ) ;
12
+
13
+ it ( 'should return null when NEXT_PUBLIC_PUBLISH_AS_MIT is true' , async ( ) => {
14
+ const { useModuleExport } = await import ( '../useModuleExport' ) ;
15
+
16
+ const { result } = renderHook ( ( ) => useModuleExport ( ) , {
17
+ wrapper : AppWrapper ,
18
+ } ) ;
19
+
20
+ expect ( result . current ) . toBeUndefined ( ) ;
21
+
22
+ await sleep ( 1000 ) ;
23
+
24
+ expect ( result . current ) . toBeUndefined ( ) ;
25
+ } ) ;
26
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import { useEffect , useState } from 'react' ;
2
+
3
+ const modulesAGPL =
4
+ process . env . NEXT_PUBLIC_PUBLISH_AS_MIT === 'false'
5
+ ? import ( '../libAGPL' )
6
+ : Promise . resolve ( null ) ;
7
+
8
+ export const useModuleExport = ( ) => {
9
+ const [ modules , setModules ] = useState < Awaited < typeof modulesAGPL > > ( ) ;
10
+
11
+ useEffect ( ( ) => {
12
+ const resolveModule = async ( ) => {
13
+ const resolvedModules = await modulesAGPL ;
14
+ if ( ! resolvedModules ) {
15
+ return ;
16
+ }
17
+ setModules ( resolvedModules ) ;
18
+ } ;
19
+ void resolveModule ( ) ;
20
+ } , [ ] ) ;
21
+
22
+ return modules ;
23
+ } ;
Original file line number Diff line number Diff line change 1
1
export * from './api' ;
2
- export * from './components ' ;
2
+ export * from './hooks/useModuleExport ' ;
3
3
export * from './utils' ;
Original file line number Diff line number Diff line change
1
+ export { ModalExport } from './components' ;
Original file line number Diff line number Diff line change @@ -30,6 +30,10 @@ class TestAnalytic extends AbstractAnalytic {
30
30
31
31
jest . mock ( '@/features/docs/doc-export/' , ( ) => ( {
32
32
ModalExport : ( ) => < span > ModalExport</ span > ,
33
+ useModuleExport : ( ) => ( {
34
+ exportToPdf : jest . fn ( ) ,
35
+ exportToDocx : jest . fn ( ) ,
36
+ } ) ,
33
37
} ) ) ;
34
38
35
39
const doc = {
Load Diff This file was deleted.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments