diff --git a/src/features/sicp/parser/ParseJson.tsx b/src/features/sicp/parser/ParseJson.tsx index b3e7c5cd5a..f2c5690633 100644 --- a/src/features/sicp/parser/ParseJson.tsx +++ b/src/features/sicp/parser/ParseJson.tsx @@ -1,4 +1,5 @@ import { Blockquote, Code, H1, OL, Pre, UL } from '@blueprintjs/core'; +import React from 'react'; import Constants from 'src/commons/utils/Constants'; import SicpExercise from 'src/pages/sicp/subcomponents/SicpExercise'; import SicpLatex from 'src/pages/sicp/subcomponents/SicpLatex'; @@ -40,14 +41,14 @@ export type JsonType = { const handleFootnote = (obj: JsonType, refs: React.MutableRefObject<{}>) => { return ( -
+ <> {obj['count'] === 1 &&
}
(refs.current[obj['id']!] = ref)} /> {'[' + obj['count'] + '] '} {parseArr(obj['child']!, refs)}
-
+ ); }; @@ -65,10 +66,10 @@ const handleEpigraph = (obj: JsonType, refs: React.MutableRefObject<{}>) => { const hasAttribution = author || title || date; const attribution = []; - attribution.push(-); + attribution.push(-); if (author) { - attribution.push({author}); + attribution.push({author}); } if (title) { @@ -76,7 +77,7 @@ const handleEpigraph = (obj: JsonType, refs: React.MutableRefObject<{}>) => { } if (date) { - attribution.push({date}); + attribution.push({date}); } const text = child && parseArr(child!, refs); @@ -179,7 +180,7 @@ const handleReference = (obj: JsonType, refs: React.MutableRefObject<{}>) => { }; const handleText = (text: string) => { - return

{text}

; + return <>{text}; }; const handleLatex = (math: string) => { @@ -187,7 +188,7 @@ const handleLatex = (math: string) => { }; export const processingFunctions = { - '#text': (obj: JsonType, _refs: React.MutableRefObject<{}>) =>

{obj['body']}

, + '#text': (obj: JsonType, _refs: React.MutableRefObject<{}>) => handleText(obj['body']!), B: (obj: JsonType, refs: React.MutableRefObject<{}>) => {parseArr(obj['child']!, refs)}, @@ -290,12 +291,14 @@ export const parseObj = ( ) => { if (obj['tag']) { if (processingFunctions[obj['tag']]) { - return {processingFunctions[obj['tag']](obj, refs)}; + return ( + {processingFunctions[obj['tag']](obj, refs)} + ); } else { throw new ParseJsonError('Unrecognised Tag: ' + obj['tag']); } } else { // Handle case where tag does not exists. Should not happen if json file is created properly. - return {parseArr(obj['child']!, refs)}; + return {parseArr(obj['child']!, refs)}; } }; diff --git a/src/features/sicp/parser/__tests__/ParseJson.tsx b/src/features/sicp/parser/__tests__/ParseJson.tsx index 73d96503de..37ced8bed0 100644 --- a/src/features/sicp/parser/__tests__/ParseJson.tsx +++ b/src/features/sicp/parser/__tests__/ParseJson.tsx @@ -1,4 +1,4 @@ -import { mount, shallow } from 'enzyme'; +import { mount } from 'enzyme'; import lzString from 'lz-string'; import { CodeSnippetProps } from 'src/pages/sicp/subcomponents/CodeSnippet'; @@ -30,8 +30,8 @@ jest.mock('src/commons/utils/Constants', () => ({ interactiveSicpDataUrl: 'https://source-academy.github.io/sicp/' })); -jest.mock('src/pages/sicp/subcomponents/CodeSnippet', () => { - return (props: CodeSnippetProps) =>
Code Snippet
; +jest.mock('src/pages/sicp/subcomponents/CodeSnippet', () => (props: CodeSnippetProps) => { + return
Code Snippet
; }); const mockData = { @@ -55,7 +55,7 @@ const processTag = (tag: string, obj: JsonType) => { const testTagSuccessful = (obj: JsonType, tag: string, text: string = '') => { test(tag + ' ' + text + ' successful', () => { - const tree = shallow(processTag(tag, obj)); + const tree = mount(processTag(tag, obj)); expect(tree.debug()).toMatchSnapshot(); }); @@ -326,7 +326,7 @@ describe('Parse reference', () => { describe('Parse object', () => { test('successful', () => { const obj = mockData['text']; - const tree = shallow(parseObj(obj, 0, mockRef)); + const tree = mount(parseObj(obj, 0, mockRef)); expect(tree.debug()).toMatchSnapshot(); }); diff --git a/src/features/sicp/parser/__tests__/__snapshots__/ParseJson.tsx.snap b/src/features/sicp/parser/__tests__/__snapshots__/ParseJson.tsx.snap index ad006b0bca..5aad66f50c 100644 --- a/src/features/sicp/parser/__tests__/__snapshots__/ParseJson.tsx.snap +++ b/src/features/sicp/parser/__tests__/__snapshots__/ParseJson.tsx.snap @@ -2,128 +2,138 @@ exports[`Parse array no child successful 1`] = `""`; -exports[`Parse array one child successful 1`] = ` -" -

- Mock Text -

-
" -`; +exports[`Parse array one child successful 1`] = `"Mock Text"`; exports[`Parse array two child successful 1`] = ` -" -

- Mock Text -

-
+"Mock Text - -

- Mock Text -

-
" +Mock Text" `; exports[`Parse epigraph EPIGRAPH with all successful 1`] = ` -"
- -

- Mock Text -

-
-
- +" +
+ Mock Text +
- - - Author - - - Title - - + + Title + 2021 - -
-
" +
+
+" `; exports[`Parse epigraph EPIGRAPH with author successful 1`] = ` -"
- -

- Mock Text -

-
-
- +" +
+ Mock Text +
- - - Author - -
-
" +
+
+" `; exports[`Parse epigraph EPIGRAPH with date successful 1`] = ` -"
- -

- Mock Text -

-
-
- +" +
+ Mock Text +
- - - 2021 - -
-
" +
+
+" `; exports[`Parse epigraph EPIGRAPH with none successful 1`] = ` -"
- -

- Mock Text -

-
-
" +" +
+ Mock Text +
+
" `; exports[`Parse epigraph EPIGRAPH with title successful 1`] = ` -"
- -

- Mock Text -

-
-
- +" +
+ Mock Text +
- - - - Title - -
-
" + + Title + +
+
+" `; exports[`Parse exercise EXERCISE with solution successful 1`] = ` "
- + + +
+ +
+
+ + + +
+ +
+
+
+ +
+ +
" `; exports[`Parse exercise EXERCISE without solution successful 1`] = ` "
- + + +
+ + Title + +
+ Mock Text +
+
+ + + +
+ +
+
+
+ +
+ +
" `; @@ -133,11 +143,7 @@ exports[`Parse figures FIGURE with image and scale successful 1`] = ` \\"id\\"
name - -

- Mock Text -

-
+ Mock Text
" `; @@ -148,11 +154,7 @@ exports[`Parse figures FIGURE with image successful 1`] = ` \\"id\\"
name - -

- Mock Text -

-
+ Mock Text
" `; @@ -160,14 +162,14 @@ exports[`Parse figures FIGURE with image successful 1`] = ` exports[`Parse figures FIGURE with snippet successful 1`] = ` "
- + +
+ Code Snippet +
+
name - -

- Mock Text -

-
+ Mock Text
" `; @@ -179,113 +181,79 @@ exports[`Parse figures FIGURE with table successful 1`] = ` - -

- Mock Text -

-
+ Mock Text - -

- Mock Text -

-
+ Mock Text - -

- Mock Text -

-
+ Mock Text - -

- Mock Text -

-
+ Mock Text
name - -

- Mock Text -

-
+ Mock Text
" `; exports[`Parse footnote DISPLAYFOOTNOTE count is 1 successful 1`] = ` -"
-
-
-
- - [1] - - -

- Mock Text -

-
-
+"
+ + +
+
+ + [1] + + Mock Text
" `; exports[`Parse footnote DISPLAYFOOTNOTE count is 2 successful 1`] = ` -"
-
-
- - [2] - - -

- Mock Text -

-
-
+"
+
+ + [2] + + Mock Text
" `; exports[`Parse heading SUBHEADING successful 1`] = ` "

- -

- Mock Text -

-
+ Mock Text

" `; exports[`Parse heading SUBSUBHEADING successful 1`] = ` "


- -

- Mock Text -

-
+ Mock Text

" `; exports[`Parse latex LATEX successful 1`] = ` -" - $test$ -" +" + + + +" `; exports[`Parse latex LATEXINLINE successful 1`] = ` -" - $test$ -" +" + + + +" `; exports[`Parse links FOOTNOTE_REF successful 1`] = ` @@ -309,214 +277,154 @@ exports[`Parse links REF successful 1`] = ` `; exports[`Parse list OL successful 1`] = ` -"
    - +" +
    1. - -

      - Mock Text -

      -
      + Mock Text
    2. - -
    " +
+" `; exports[`Parse list UL successful 1`] = ` -"
    - +" +
    • - -

      - Mock Text -

      -
      + Mock Text
    • - -
    " +
+" `; -exports[`Parse object no tag 1`] = ` -" - -

- Mock Text -

-
-
" -`; +exports[`Parse object no tag 1`] = `"Mock Text"`; -exports[`Parse object successful 1`] = ` -" -

- Mock Text -

-
" -`; +exports[`Parse object successful 1`] = `"Mock Text"`; exports[`Parse reference REFERENCE successful 1`] = ` "
- -

- Mock Text -

-
+ Mock Text
" `; exports[`Parse section SECTION successful 1`] = ` "
- Title +

+ Title +

- -
-
- -

- Mock Text -

-
- -

- Mock Text -

-
-
-
- - -
-
- -

- Mock Text -

-
- -

- Mock Text -

-
-
-
- +
+
+ Mock Text + Mock Text +
+
+
+
+ Mock Text + Mock Text +
+
" `; exports[`Parse snippet SNIPPET no eval successful 1`] = ` -"
-  1 + 1;
-
" +" +
+    1 + 1;
+  
+
" `; exports[`Parse snippet SNIPPET with latex successful 1`] = ` -"
-  
-
" +" +
+    
+      
+        
+      
+    
+  
+
" `; exports[`Parse snippet SNIPPET with prepend successful 1`] = ` -"
- Code Snippet -
" +" +
+ Code Snippet +
+
" `; exports[`Parse snippet SNIPPET without prepend successful 1`] = ` -"
- Code Snippet -
" +" +
+ Code Snippet +
+
" `; exports[`Parse snippet SNIPPET without prepend with output successful 1`] = ` -"
- Code Snippet -
" +" +
+ Code Snippet +
+
" `; exports[`Parse styling B successful 1`] = ` " - -

- Mock Text -

-
+ Mock Text
" `; exports[`Parse styling EM successful 1`] = ` " - -

- Mock Text -

-
+ Mock Text
" `; -exports[`Parse styling JAVASCRIPTINLINE successful 1`] = `""`; +exports[`Parse styling JAVASCRIPTINLINE successful 1`] = ` +" + +" +`; exports[`Parse styling META successful 1`] = `""`; exports[`Parse styling TT successful 1`] = ` -" - -

- Mock Text -

-
-
" +" + + Mock Text + +" `; exports[`Parse symbol BR successful 1`] = `"
"`; -exports[`Parse symbol LaTeX successful 1`] = ` -"

- LaTeX -

" -`; +exports[`Parse symbol LaTeX successful 1`] = `"LaTeX"`; -exports[`Parse symbol TeX successful 1`] = ` -"

- TeX -

" -`; +exports[`Parse symbol TeX successful 1`] = `"TeX"`; exports[`Parse table TABLE successful 1`] = ` "
- -

- Mock Text -

-
+ Mock Text
- -

- Mock Text -

-
+ Mock Text
- -

- Mock Text -

-
+ Mock Text
- -

- Mock Text -

-
+ Mock Text