forked from rebassjs/rebass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSectionHeader.spec.js
97 lines (81 loc) · 2.67 KB
/
SectionHeader.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import React from 'react'
import TestUtils from 'react-addons-test-utils'
import expect from 'expect'
import { SectionHeader, HeadingLink, Base } from '../src'
const renderer = TestUtils.createRenderer()
describe('SectionHeader', () => {
let tree, heading, description
beforeEach(() => {
renderer.render(<SectionHeader />)
tree = renderer.getRenderOutput()
heading = tree.props.children[0].props.children[0]
description = tree.props.children[0].props.children[1]
})
it('should render', () => {
expect(tree.type).toEqual(Base)
})
it('should set tagName header', () => {
expect(tree.props.tagName).toEqual('header')
})
it('should have a className', () => {
expect(tree.props.className).toEqual('SectionHeader')
})
it('should have a Heading', () => {
expect(heading.type).toEqual(HeadingLink)
})
it('should set a default href', () => {
expect(heading.props.href).toEqual('#')
})
it('should not have a description', () => {
expect(description).toNotExist()
})
context('when heading is set', () => {
beforeEach(() => {
renderer.render(<SectionHeader heading='Test' />)
tree = renderer.getRenderOutput()
heading = tree.props.children[0].props.children[0]
description = tree.props.children[0].props.children[1]
})
it('should set text to Test', () => {
expect(heading.props.children).toEqual('Test')
})
it('should set href to #Test', () => {
expect(heading.props.href).toEqual('#Test')
})
it('should not have a description', () => {
expect(description).toNotExist()
})
})
context('when description is set', () => {
beforeEach(() => {
renderer.render(<SectionHeader description='Test' />)
tree = renderer.getRenderOutput()
description = tree.props.children[0].props.children[1]
})
it('should set text to Test', () => {
expect(description.props.children).toEqual('Test')
})
})
context('when heading and href is set', () => {
beforeEach(() => {
renderer.render(<SectionHeader heading='Test' href='#hello' />)
tree = renderer.getRenderOutput()
heading = tree.props.children[0].props.children[0]
})
it('should set text to Test', () => {
expect(heading.props.children).toEqual('Test')
})
it('should set href to #hello', () => {
expect(heading.props.href).toEqual('#hello')
})
})
context('when custom styles are set', () => {
beforeEach(() => {
renderer.render(<SectionHeader style={{ color: 'tomato' }} />)
tree = renderer.getRenderOutput()
})
it('should have a custom color', () => {
expect(tree.props.style.color).toEqual('tomato')
})
})
})