react-google-contacts
Version:
A Google Button to import user's gmail contacts
190 lines (153 loc) • 5.53 kB
JavaScript
import React from 'react'
import { create } from 'react-test-renderer'
import { configure, shallow } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
import GoogleContactsDist from '../dist/google-contacts'
configure({ adapter: new Adapter() })
describe('Google Contacts Dist', () => {
describe('With default props', () => {
const props = {
onSuccess() {},
onFailure() {},
clientId: '429632624144-40js6mbas4r3tmjursoco68eoum0a24v.apps.googleusercontent.com'
}
test('render the button', () => {
const component = create(<GoogleContactsDist {...props} />)
const tree = component.toJSON()
expect(tree).toMatchSnapshot()
})
const button = shallow(<GoogleContactsDist {...props} />)
test('does not have a class attr', () => {
expect(button.prop('className')).toEqual(undefined)
})
test('has inline styles', () => {
expect(button.prop('style')).toMatchSnapshot()
})
test('displays a button element when tag prop is not set', () => {
expect(button.type()).toEqual('button')
})
})
describe('With custom text and default props', () => {
const buttonText = 'buttonText'
const props = {
onSuccess() {},
onFailure() {},
clientId: '429632624144-40js6mbas4r3tmjursoco68eoum0a24v.apps.googleusercontent.com',
buttonText
}
test('render the button', () => {
const component = create(<GoogleContactsDist {...props} />)
const tree = component.toJSON()
expect(tree).toMatchSnapshot()
})
const button = shallow(<GoogleContactsDist {...props} />)
test('does not have a class attr', () => {
expect(button.prop('className')).toEqual(undefined)
})
test('has inline styles', () => {
expect(button.prop('style')).toMatchSnapshot()
})
test('displays a button element when tag prop is not set', () => {
expect(button.type()).toEqual('button')
})
})
describe('With custom class and default props', () => {
const className = 'test-class'
const props = {
onSuccess() {},
onFailure() {},
clientId: '429632624144-40js6mbas4r3tmjursoco68eoum0a24v.apps.googleusercontent.com',
className
}
test('render the button', () => {
const component = create(<GoogleContactsDist {...props} />)
const tree = component.toJSON()
expect(tree).toMatchSnapshot()
})
const button = shallow(<GoogleContactsDist {...props} />)
test('does not have a class attr', () => {
expect(button.prop('className')).toEqual(className)
})
test('has inline styles', () => {
expect(button.prop('style')).toMatchSnapshot()
})
test('displays a button element when tag prop is not set', () => {
expect(button.type()).toEqual('button')
})
})
describe('With custom class and custom style', () => {
const className = 'test-class'
const style = { color: 'red' }
const props = {
onSuccess() {},
onFailure() {},
clientId: '429632624144-40js6mbas4r3tmjursoco68eoum0a24v.apps.googleusercontent.com',
className,
style
}
test('render the button', () => {
const component = create(<GoogleContactsDist {...props} />)
const tree = component.toJSON()
expect(tree).toMatchSnapshot()
})
const button = shallow(<GoogleContactsDist {...props} />)
test('does not have a class attr', () => {
expect(button.prop('className')).toEqual(className)
})
test('has inline styles', () => {
expect(button.prop('style')).toMatchSnapshot()
})
test('displays a button element when tag prop is not set', () => {
expect(button.type()).toEqual('button')
})
})
describe('With children, custom text, and default props', () => {
const children = 'test'
const buttonText = 'buttonText'
const props = {
onSuccess() {},
onFailure() {},
clientId: '429632624144-40js6mbas4r3tmjursoco68eoum0a24v.apps.googleusercontent.com',
buttonText
}
test('render the button', () => {
const component = create(<GoogleContactsDist {...props}>{children}</GoogleContactsDist>)
const tree = component.toJSON()
expect(tree).toMatchSnapshot()
})
const button = shallow(<GoogleContactsDist {...props}>{children}</GoogleContactsDist>)
test('does not have a class attr', () => {
expect(button.prop('className')).toEqual(undefined)
})
test('has inline styles', () => {
expect(button.prop('style')).toMatchSnapshot()
})
test('displays a button element when tag prop is not set', () => {
expect(button.type()).toEqual('button')
})
})
describe('With handles custom tag prop', () => {
const tag = 'div'
const props = {
onSuccess() {},
onFailure() {},
clientId: '429632624144-40js6mbas4r3tmjursoco68eoum0a24v.apps.googleusercontent.com',
tag
}
test('render the button', () => {
const component = create(<GoogleContactsDist {...props} />)
const tree = component.toJSON()
expect(tree).toMatchSnapshot()
})
const button = shallow(<GoogleContactsDist {...props} />)
test('does not have a class attr', () => {
expect(button.prop('className')).toEqual(undefined)
})
test('has inline styles', () => {
expect(button.prop('style')).toMatchSnapshot()
})
test('displays a button element when tag prop is not set', () => {
expect(button.type()).toEqual(tag)
})
})
})