зеркало из https://github.com/Azure/Sia-EventUI.git
Add snapshot testing for MenuLink (#144)
Add snapshot testing helper and convert `MenuLinkTest.js` to snapshot testing
This commit is contained in:
Родитель
ee4ce00960
Коммит
96a66763dd
|
@ -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",
|
||||
|
|
|
@ -1,47 +1,32 @@
|
|||
'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'
|
||||
import { describeSnapshot } from 'test/helpers/describeSnapshot'
|
||||
|
||||
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)
|
||||
describeSnapshot(function () {
|
||||
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()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`MenuLink when all input is valid snapshot 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"
|
||||
/>
|
||||
`;
|
|
@ -0,0 +1,18 @@
|
|||
import chai from 'chai'
|
||||
import chaiJestSnapshot from 'chai-jest-snapshot'
|
||||
|
||||
chai.use(chaiJestSnapshot)
|
||||
|
||||
export const describeSnapshot = (testsCallback) => {
|
||||
describe('snapshot', function () {
|
||||
before(function () {
|
||||
chaiJestSnapshot.resetSnapshotRegistry()
|
||||
})
|
||||
|
||||
beforeEach(function () {
|
||||
chaiJestSnapshot.configureUsingMochaContext(this)
|
||||
})
|
||||
|
||||
testsCallback()
|
||||
})
|
||||
}
|
Загрузка…
Ссылка в новой задаче