Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add jest and enzyme dependencies and tests for existing components and scripts #7

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions __tests__/Semester.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import Semester from '../components/Semester'
import renderer from 'react-test-renderer'

describe('App', () => {
const data = [
{
_id: 1,
lessonCode: 1,
name: 'lesson1',
semester: 1,
type: 'E',
hoursTheory: 4,
hoursLab: 2,
credit: 6
},
{
_id: 2,
lessonCode: 2,
name: 'lesson2',
semester: 1,
type: 'E',
hoursTheory: 4,
hoursLab: 2,
credit: 6
}
]

it('renders', () => {
const component = renderer.create(<Semester rows={data} semester={1} />)
const tree = component.toJSON()
expect(tree).toMatchSnapshot()
})

// it('fetches async data', () => {
// const promise = new Promise((resolve, reject) =>
// setTimeout(
// () =>
// resolve({
// data: {
// lessons: [
// {
// _id: 1,
// lessonCode: 1,
// name: 'lesson1',
// semester: 1,
// type: 'E',
// hoursTheory: 4,
// hoursLab: 2,
// credit: 6
// }
// ]
// }
// }),
// 100
// )
// )
//
// promise.then(() => {
// const wrapper = mount(<Semester rows={this.data} semester={1} />)
//
// expect(wrapper.find('tbody').find('tr').length).toEqual(2)
// })
// })
})
77 changes: 77 additions & 0 deletions __tests__/__snapshots__/Semester.spec.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`App renders 1`] = `
<div
className="makeStyles-root-1"
>
<div
className="MuiPaper-root MuiExpansionPanel-root makeStyles-summary-3 MuiExpansionPanel-rounded MuiPaper-elevation1 MuiPaper-rounded"
>
<div
aria-controls="panel-content"
aria-disabled={false}
aria-expanded={false}
className="MuiButtonBase-root MuiExpansionPanelSummary-root"
id="panel1d-header"
onBlur={[Function]}
onClick={[Function]}
onDragLeave={[Function]}
onFocus={[Function]}
onKeyDown={[Function]}
onKeyUp={[Function]}
onMouseDown={[Function]}
onMouseLeave={[Function]}
onMouseUp={[Function]}
onTouchEnd={[Function]}
onTouchMove={[Function]}
onTouchStart={[Function]}
role="button"
tabIndex={0}
>
<div
className="MuiExpansionPanelSummary-content"
>
<p
className="MuiTypography-root MuiTypography-body1"
>
Εξάμηνο
1
</p>
</div>
<div
aria-disabled={false}
aria-hidden={true}
className="MuiButtonBase-root MuiIconButton-root MuiExpansionPanelSummary-expandIcon MuiIconButton-edgeEnd"
onBlur={[Function]}
onDragLeave={[Function]}
onFocus={[Function]}
onKeyDown={[Function]}
onKeyUp={[Function]}
onMouseDown={[Function]}
onMouseLeave={[Function]}
onMouseUp={[Function]}
onTouchEnd={[Function]}
onTouchMove={[Function]}
onTouchStart={[Function]}
role={null}
tabIndex={null}
>
<span
className="MuiIconButton-label"
>
<svg
aria-hidden="true"
className="MuiSvgIcon-root makeStyles-icon-2"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M16.59 8.59L12 13.17 7.41 8.59 6 10l6 6 6-6z"
/>
</svg>
</span>
</div>
</div>
</div>
</div>
`;
4 changes: 2 additions & 2 deletions components/Semester.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const StyledTableCell = withStyles(theme => ({
backgroundColor: theme.palette.secondary.main,
color: theme.palette.common.white
}
})) (TableCell)
}))(TableCell)

const StyledTableRow = withStyles(theme => ({
root: {
Expand All @@ -31,7 +31,7 @@ const StyledTableRow = withStyles(theme => ({
backgroundColor: theme.palette.type === 'light' ? lightBlue[100] : theme.palette.primary.level3
}
}
})) (TableRow)
}))(TableRow)

const useStyles = makeStyles(theme => ({
root: {
Expand Down
6 changes: 6 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"testRegex": "((\\.|/*.)(spec|test))\\.js?$",
"setupFilesAfterEnv": [
"<rootDir>/jest.setup.js"
]
}
4 changes: 4 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { configure } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'

configure({ adapter: new Adapter() })
Loading