Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Commit

Permalink
Merge 52a7e1e into b4b7db8
Browse files Browse the repository at this point in the history
  • Loading branch information
danieljurek committed Apr 18, 2018
2 parents b4b7db8 + 52a7e1e commit cbe6394
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 34 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,14 @@
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"chai": "^4.1.2",
"chai-jest-snapshot": "^2.0.0",
"copy-webpack-plugin": "^4.5.1",
"copyfiles": "^1.2.0",
"cross-env": "^5.1.3",
"css-loader": "^0.28.7",
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1",
"enzyme-to-json": "^3.3.3",
"eslint": "^4.18.2",
"eslint-plugin-react": "^7.7.0",
"file-loader": "^1.1.6",
Expand Down
52 changes: 18 additions & 34 deletions test/components/elements/MenuLinkTest.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,31 @@
'use strict'
import React from 'react'
import { expect } from 'chai'
import { Link } from 'react-router-dom'
import MenuItem from 'material-ui/MenuItem'
import MenuLink from 'components/elements/MenuLink'
import { shallow } from 'enzyme'
import toJson from 'enzyme-to-json'
require('test/helpers/enableSnapshot')

describe('MenuLink', function() {
describe('when all input is valid', function() {
describe('MenuLink', function () {
describe('when all input is valid', function () {
const mockTitle = 'mock title'
const mockToolTip = 'mock tool tip'
const mockRoute = '/mock/route'
const mockOnClick = () => 'clicked'
const mockRightIcon = {}

const result = MenuLink({
primaryText: mockTitle,
toolTip: mockToolTip,
route: mockRoute,
onClick: mockOnClick,
rightIcon: mockRightIcon
})

it('should render a MenuItem', function() {
expect(result.type).to.equal(MenuItem)
})

it('should not contain a Link in the primaryText', function() {
expect(result.props.primaryText.type).to.not.equal(Link)
})

it('should link to the provided route', function () {
expect(result.props.containerElement.props.to).to.equal(mockRoute)
})

it('should display the provided text as primaryText', function () {
expect(result.props.primaryText.props.children).to.contain(mockTitle)
})

it('should have a key that is composed of both the route and primaryText', function () {
expect(result.key).to.equal(mockTitle + mockRoute)
})

it('should contain the provided rightIcon', function () {
expect(result.props.rightIcon).to.equal(mockRightIcon)
it('should match the snapshot', function () {
const wrapper = shallow(
<MenuLink
primaryText={mockTitle}
toolTip={mockToolTip}
route={mockRoute}
onClick={mockOnClick}
rightIcon={mockRightIcon}
/>
)

expect(toJson(wrapper)).to.matchSnapshot()
})
})
})
46 changes: 46 additions & 0 deletions test/components/elements/MenuLinkTest.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`MenuLink when all input is valid should match the snapshot 1`] = `
<MenuItem
anchorOrigin={
Object {
"horizontal": "right",
"vertical": "top",
}
}
checked={false}
containerElement={
<Link
replace={false}
to="/mock/route"
/>
}
desktop={false}
disabled={false}
focusState="none"
insetChildren={false}
key="mock title/mock/route"
onClick={[Function]}
primaryText={
<div
style={
Object {
"overflow": "hidden",
"textOverflow": "ellipsis",
"width": "25rem",
}
}
>
mock title
</div>
}
rightIcon={Object {}}
targetOrigin={
Object {
"horizontal": "left",
"vertical": "top",
}
}
title="mock title"
/>
`;
12 changes: 12 additions & 0 deletions test/helpers/enableSnapshot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import chai from 'chai'
import chaiJestSnapshot from 'chai-jest-snapshot'

chai.use(chaiJestSnapshot)

before(function () {
chaiJestSnapshot.resetSnapshotRegistry()
})

beforeEach(function () {
chaiJestSnapshot.configureUsingMochaContext(this)
})

0 comments on commit cbe6394

Please sign in to comment.