@@ -5,7 +5,6 @@ import { act, render, screen, waitFor } from '@testing-library/react';
55import { Cookies , CookiesProvider } from 'react-cookie' ;
66import configureStore from 'redux-mock-store' ;
77import { showSavedMessage } from './utils/Notifications' ;
8- import { saveProject } from './components/Editor/EditorSlice' ;
98
109jest . mock ( './utils/Notifications' )
1110jest . mock ( './components/Editor/EditorSlice' , ( ) => {
@@ -137,6 +136,7 @@ describe("When selecting the font size", ()=>{
137136 }
138137 store = mockStore ( initialState ) ;
139138 } )
139+
140140 test ( "Cookie not set defaults css class to small" , ( ) => {
141141 const appContainer = render (
142142 < CookiesProvider cookies = { cookies } >
@@ -236,7 +236,7 @@ test('Successful manual save prompts project saved message', async () => {
236236 const initialState = {
237237 editor : {
238238 saving : 'success' ,
239- lastSaveAutosaved : false
239+ lastSaveAutosave : false
240240 } ,
241241 auth : { }
242242 }
@@ -246,133 +246,3 @@ test('Successful manual save prompts project saved message', async () => {
246246} )
247247
248248// TODO: Write test for successful autosave not prompting the project saved message as per the above
249-
250- describe ( 'When not logged in' , ( ) => {
251- const project = {
252- name : 'hello world' ,
253- project_type : 'python' ,
254- identifier : 'hello-world-project' ,
255- components : [
256- {
257- name : 'main' ,
258- extension : 'py' ,
259- content : '# hello'
260- }
261- ]
262- }
263- beforeEach ( ( ) => {
264- const middlewares = [ ]
265- const mockStore = configureStore ( middlewares )
266- const initialState = {
267- editor : {
268- project : project ,
269- projectLoaded : 'success'
270- } ,
271- auth : {
272- user : null
273- }
274- }
275- const mockedStore = mockStore ( initialState ) ;
276- render ( < Provider store = { mockedStore } > < App /> </ Provider > ) ;
277- } )
278-
279- afterEach ( ( ) => {
280- localStorage . clear ( )
281- } )
282-
283- test ( 'Project saved in localStorage' , async ( ) => {
284- await waitFor ( ( ) => expect ( localStorage . getItem ( 'hello-world-project' ) ) . toEqual ( JSON . stringify ( project ) ) , { timeout : 2100 } )
285- } )
286- } )
287-
288- describe ( 'When logged in and user does not own project' , ( ) => {
289- const project = {
290- name : 'hello world' ,
291- project_type : 'python' ,
292- identifier : 'hello-world-project' ,
293- components : [
294- {
295- name : 'main' ,
296- extension : 'py' ,
297- content : '# hello'
298- }
299- ] ,
300- user_id : 'another_user'
301- }
302- const user = {
303- profile : {
304- user : "b48e70e2-d9ed-4a59-aee5-fc7cf09dbfaf"
305- }
306- }
307-
308- beforeEach ( ( ) => {
309- const middlewares = [ ]
310- const mockStore = configureStore ( middlewares )
311- const initialState = {
312- editor : {
313- project,
314- projectLoaded : 'success'
315- } ,
316- auth : { user}
317- }
318- const mockedStore = mockStore ( initialState ) ;
319- render ( < Provider store = { mockedStore } > < App /> </ Provider > ) ;
320- } )
321-
322- afterEach ( ( ) => {
323- localStorage . clear ( )
324- } )
325-
326- test ( 'Project saved in localStorage' , async ( ) => {
327- await waitFor ( ( ) => expect ( localStorage . getItem ( 'hello-world-project' ) ) . toEqual ( JSON . stringify ( project ) ) , { timeout : 2100 } )
328- } )
329-
330- } )
331-
332- describe ( 'When logged in and user owns project' , ( ) => {
333- const project = {
334- name : 'hello world' ,
335- project_type : 'python' ,
336- identifier : 'hello-world-project' ,
337- components : [
338- {
339- name : 'main' ,
340- extension : 'py' ,
341- content : '# hello'
342- }
343- ] ,
344- user_id : "b48e70e2-d9ed-4a59-aee5-fc7cf09dbfaf"
345- }
346- const user = {
347- profile : {
348- user : "b48e70e2-d9ed-4a59-aee5-fc7cf09dbfaf"
349- }
350- }
351-
352- let mockedStore ;
353-
354- beforeEach ( ( ) => {
355- const middlewares = [ ]
356- const mockStore = configureStore ( middlewares )
357- const initialState = {
358- editor : {
359- project,
360- projectLoaded : 'success'
361- } ,
362- auth : { user}
363- }
364- mockedStore = mockStore ( initialState ) ;
365- render ( < Provider store = { mockedStore } > < App /> </ Provider > ) ;
366- } )
367-
368- afterEach ( ( ) => {
369- localStorage . clear ( )
370- } )
371-
372- test ( 'Project autosaved to database' , async ( ) => {
373- const saveAction = { type : 'SAVE_PROJECT' }
374- saveProject . mockImplementationOnce ( ( ) => ( saveAction ) )
375- await waitFor ( ( ) => expect ( saveProject ) . toHaveBeenCalledWith ( { project, user, autosave : true } ) , { timeout : 2100 } )
376- expect ( mockedStore . getActions ( ) [ 1 ] ) . toEqual ( saveAction )
377- } )
378- } )
0 commit comments