From 077d184b8a4fd3181a93e50401a4620f11c3d66d Mon Sep 17 00:00:00 2001 From: Clifton Barnes Date: Tue, 5 May 2020 17:20:25 -0400 Subject: [PATCH 1/2] Convert code viewer to Material UI --- src/components/CodeViewer.js | 92 +++-- src/components/__tests__/CodeViewer.test.js | 22 +- .../__snapshots__/CodeViewer.test.js.snap | 317 ++++-------------- 3 files changed, 146 insertions(+), 285 deletions(-) diff --git a/src/components/CodeViewer.js b/src/components/CodeViewer.js index 3cae8d87..170f11cd 100644 --- a/src/components/CodeViewer.js +++ b/src/components/CodeViewer.js @@ -1,5 +1,10 @@ import React, { Component } from 'react'; -import { Button, Modal } from 'semantic-ui-react'; +import { + Button, + Dialog, + DialogContent, + DialogTitle, +} from '@material-ui/core'; import { FormattedMessage } from 'react-intl'; import { connect } from 'react-redux'; import { hot } from 'react-hot-loader'; @@ -12,6 +17,14 @@ import 'brace/theme/monokai'; const mapStateToProps = ({ code }) => ({ code }); class CodeViewer extends Component { + constructor(props) { + super(props); + + this.state = { + open: false, + }; + } + stripCode = () => { const { code } = this.props; @@ -22,44 +35,53 @@ class CodeViewer extends Component { return ''; } + handleOpen = () => { + this.setState({ + open: true, + }); + } + + handleClose = () => { + this.setState({ + open: false, + }); + } + render() { const { children } = this.props; + const { open } = this.state; return ( - - { children } - - )} - > - - - {' '} - - JavaScript - - : - - - - - + <> + + + + + {' '} + + JavaScript + + : + + + + + + ); } } diff --git a/src/components/__tests__/CodeViewer.test.js b/src/components/__tests__/CodeViewer.test.js index 9e5c560b..ece00f1b 100644 --- a/src/components/__tests__/CodeViewer.test.js +++ b/src/components/__tests__/CodeViewer.test.js @@ -1,6 +1,7 @@ import React from 'react'; -import { mount } from 'enzyme'; +import { shallow } from 'enzyme'; import configureStore from 'redux-mock-store'; +import { Button, Dialog } from '@material-ui/core'; import CodeViewer from '../CodeViewer'; @@ -13,11 +14,11 @@ describe('The CodeViewer component', () => { jsCode: 'test code', }, }); - const wrapper = mount( + const wrapper = shallow( Show Me The Code! , - ); + ).dive().dive(); expect(wrapper).toMatchSnapshot(); }); @@ -27,11 +28,20 @@ describe('The CodeViewer component', () => { jsCode: null, }, }); - const wrapper = mount( + const wrapper = shallow( Show Me The Code! , - ); - expect(wrapper).toMatchSnapshot(); + ).dive().dive(); + + expect(wrapper.state('open')).toBe(false); + + wrapper.find(Button).simulate('click'); + + expect(wrapper.state('open')).toBe(true); + + wrapper.find(Dialog).simulate('close'); + + expect(wrapper.state('open')).toBe(false); }); }); diff --git a/src/components/__tests__/__snapshots__/CodeViewer.test.js.snap b/src/components/__tests__/__snapshots__/CodeViewer.test.js.snap index 1eac38ab..6a1acdce 100644 --- a/src/components/__tests__/__snapshots__/CodeViewer.test.js.snap +++ b/src/components/__tests__/__snapshots__/CodeViewer.test.js.snap @@ -1,251 +1,80 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`The CodeViewer component handles blank code with no errors 1`] = ` - - - - Show Me The Code! - - } - > - } - onClose={[Function]} - onMount={[Function]} - onOpen={[Function]} - onUnmount={[Function]} - openOnTriggerClick={true} - trigger={ - - } - > - - - , - } - } - > - - Show Me The Code! - , - } - } - > - - - - - - - - - - -`; - exports[`The CodeViewer component renders on the page with no errors 1`] = ` - - + + Show Me The Code! + + - - Show Me The Code! - - } + + + + + JavaScript + + : + + - } - onClose={[Function]} - onMount={[Function]} - onOpen={[Function]} - onUnmount={[Function]} - openOnTriggerClick={true} - trigger={ - + - - - , - } - } - > - - Show Me The Code! - , - } - } - > - - - - - - - - - - + enableBasicAutocompletion={false} + enableLiveAutocompletion={false} + enableSnippets={false} + focus={false} + fontSize={14} + height="500px" + highlightActiveLine={true} + maxLines={null} + minLines={null} + mode="javascript" + name="ace-editor" + navigateToFileEnd={true} + onChange={null} + onLoad={null} + onPaste={null} + onScroll={null} + placeholder={null} + readOnly={true} + scrollMargin={ + Array [ + 0, + 0, + 0, + 0, + ] + } + setOptions={Object {}} + showGutter={true} + showPrintMargin={true} + style={Object {}} + tabSize={4} + theme="github" + value="test code" + width="750px" + wrapEnabled={false} + /> + + + `; From ea72badbdae77640c26d2b221d0283922f96682d Mon Sep 17 00:00:00 2001 From: Clifton Barnes Date: Tue, 5 May 2020 19:33:50 -0400 Subject: [PATCH 2/2] Change 'a' to 'Link' --- src/components/CodeViewer.js | 5 +++-- .../__tests__/__snapshots__/CodeViewer.test.js.snap | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/components/CodeViewer.js b/src/components/CodeViewer.js index 170f11cd..ee47e819 100644 --- a/src/components/CodeViewer.js +++ b/src/components/CodeViewer.js @@ -4,6 +4,7 @@ import { Dialog, DialogContent, DialogTitle, + Link, } from '@material-ui/core'; import { FormattedMessage } from 'react-intl'; import { connect } from 'react-redux'; @@ -64,9 +65,9 @@ class CodeViewer extends Component { defaultMessage="Here is the code in" /> {' '} - + JavaScript - + : diff --git a/src/components/__tests__/__snapshots__/CodeViewer.test.js.snap b/src/components/__tests__/__snapshots__/CodeViewer.test.js.snap index 6a1acdce..da1fa147 100644 --- a/src/components/__tests__/__snapshots__/CodeViewer.test.js.snap +++ b/src/components/__tests__/__snapshots__/CodeViewer.test.js.snap @@ -21,11 +21,11 @@ exports[`The CodeViewer component renders on the page with no errors 1`] = ` values={Object {}} /> - JavaScript - + :