UNPKG

3.32 kBJavaScriptView Raw
1import React from 'react'
2import GoogleButton from '../../src'
3import { shallow } from 'enzyme'
4
5const defaults = {
6 label: 'Sign in with Google',
7 backgroundColor: '#4285f4'
8}
9
10const disabledStyle = {
11 backgroundColor: 'rgba(37, 5, 5, .08)'
12}
13
14describe('react-google-button Library', () => {
15 describe('exports a component', () => {
16 expect(GoogleButton).to.exist
17 })
18
19 describe('Component', () => {
20 let _component
21
22 describe('Default Props', () => {
23 beforeEach(() => {
24 _component = shallow(<GoogleButton />)
25 })
26 it('Renders div', () => {
27 const firstDiv = _component.find('div')
28 expect(firstDiv).to.exist
29 })
30
31 it('Sets correct label text', () => {
32 const firstDiv = _component.find('span')
33 expect(firstDiv.first().text()).to.equal(defaults.label)
34 })
35
36 it('Applies styles', () => {
37 const firstDiv = _component.find('div')
38 expect(firstDiv.first()).to.have.style(
39 'background-color',
40 defaults.backgroundColor
41 )
42 })
43 })
44
45 describe('Custom Label', () => {
46 const customLabel = 'Custom Label'
47
48 beforeEach(() => {
49 _component = shallow(<GoogleButton label={customLabel} />)
50 })
51
52 it('Renders div', () => {
53 const firstDiv = _component.find('div')
54 expect(firstDiv).to.exist
55 })
56
57 it('Sets correct label text', () => {
58 const firstDiv = _component.find('span')
59 expect(firstDiv.first().text()).to.equal(customLabel)
60 })
61 })
62
63 describe('Disabled', () => {
64 beforeEach(() => {
65 _component = shallow(<GoogleButton disabled />)
66 })
67
68 it('Renders div', () => {
69 const firstDiv = _component.find('div')
70 expect(firstDiv).to.exist
71 })
72
73 it('Applies background color', () => {
74 const firstDiv = _component.find('div')
75 expect(firstDiv.first()).to.have.style(
76 'background-color',
77 disabledStyle.backgroundColor
78 )
79 })
80 })
81
82 describe('onClick', () => {
83 let clickSpy
84 beforeEach(() => {
85 clickSpy = sinon.spy()
86 _component = shallow(<GoogleButton onClick={clickSpy} />)
87 })
88
89 it('Calls onClick prop when clicked', () => {
90 _component.simulate('click')
91 expect(clickSpy).to.have.been.calledOnce
92 })
93 })
94
95 describe('Hover', () => {
96 beforeEach(() => {
97 _component = shallow(<GoogleButton />)
98 })
99
100 it('Sets hover style on hover', () => {
101 _component.simulate('mouseover')
102 const firstDiv = _component.find('div')
103 expect(firstDiv.first()).to.have.style(
104 'box-shadow',
105 '0 0 3px 3px rgba(66,133,244,.3)'
106 )
107 expect(firstDiv.first()).to.have.style(
108 'transition',
109 'background-color .218s, border-color .218s, box-shadow .218s'
110 )
111 })
112
113 it('Sets original style when mouse leave', () => {
114 _component.simulate('mouseout')
115 const firstDiv = _component.find('div')
116 expect(firstDiv.first()).to.have.style(
117 'background-color',
118 defaults.backgroundColor
119 )
120 expect(firstDiv.first()).to.have.style(
121 'background-color',
122 defaults.backgroundColor
123 )
124 })
125 })
126 })
127})