-
Notifications
You must be signed in to change notification settings - Fork 29
/
MetaTools.spec.js
93 lines (78 loc) · 4.33 KB
/
MetaTools.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
import { FavouritesButton } from '@zooniverse/react-components'
import React from 'react'
import { shallow } from 'enzyme'
import sinon from 'sinon'
import { MetaTools } from './MetaTools'
import Metadata from './components/Metadata'
import CollectionsButton from './components/CollectionsButton'
import { Factory } from 'rosie'
const subjectWithMetadata = Factory.build('subject', { metadata: { foo: 'bar' } })
const favoriteSubject = Factory.build('subject', { favorite: true })
describe('Component > MetaTools', function () {
it('should render without crashing', function () {
const wrapper = shallow(<MetaTools.wrappedComponent />)
expect(wrapper).to.be.ok()
})
describe('Metadata', function () {
it('should render a Metadata component', function () {
const wrapper = shallow(<MetaTools.wrappedComponent />)
expect(wrapper.find(Metadata)).to.have.lengthOf(1)
})
it('should pass along the isThereMetadata and subject resource metadata props', function () {
const wrapper = shallow(<MetaTools.wrappedComponent isThereMetadata subject={subjectWithMetadata} />)
const metadataComponentProps = wrapper.find(Metadata).props()
expect(metadataComponentProps.isThereMetadata).to.be.true()
expect(metadataComponentProps.metadata).to.equal(subjectWithMetadata.metadata)
})
})
describe('FavouritesButton', function () {
it('should render a FavouritesButton component', function () {
const wrapper = shallow(<MetaTools.wrappedComponent />)
expect(wrapper.find(FavouritesButton)).to.have.lengthOf(1)
})
it('should call toggle favourites on click of the FavouritesButton', function () {
const subjectMethod = { toggleFavorite: sinon.spy() }
const wrapper = shallow(<MetaTools.wrappedComponent subject={subjectMethod} />)
wrapper.find(FavouritesButton).simulate('click')
expect(subjectMethod.toggleFavorite).to.have.been.calledOnce()
})
it('should disable the FavouritesButton if there is no user project preferences', function () {
const wrapper = shallow(<MetaTools.wrappedComponent subject={favoriteSubject} />)
expect(wrapper.find(FavouritesButton).props().disabled).to.be.true()
})
it('should enable the FavouritesButton if there is user project preferences', function () {
const wrapper = shallow(<MetaTools.wrappedComponent subject={favoriteSubject} upp={{ id: '1' }} />)
expect(wrapper.find(FavouritesButton).props().disabled).to.be.false()
})
it('should check the FavouritesButton if the subject is a favorite', function () {
const wrapper = shallow(<MetaTools.wrappedComponent subject={favoriteSubject} upp={{ id: '1' }} />)
expect(wrapper.find(FavouritesButton).props().checked).to.be.true()
})
it('should not check the FavouritesButton if the subject is not a favorite', function () {
const wrapper = shallow(<MetaTools.wrappedComponent subject={subjectWithMetadata} upp={{ id: '1' }} />)
expect(wrapper.find(FavouritesButton).props().checked).to.be.false()
})
})
describe('CollectionsButton', function () {
it('should render a CollectionsButton component', function () {
const wrapper = shallow(<MetaTools.wrappedComponent />)
expect(wrapper.find(CollectionsButton)).to.have.lengthOf(1)
})
it('should call to add to collection on click of the CollectionsButton', function () {
const subjectMethod = { addToCollection: sinon.spy() }
const addToCollectionSpy = sinon.spy(MetaTools.wrappedComponent.prototype, 'addToCollection')
const wrapper = shallow(<MetaTools.wrappedComponent subject={subjectMethod} />)
wrapper.find(CollectionsButton).simulate('click')
expect(addToCollectionSpy).to.have.been.calledOnce()
expect(subjectMethod.addToCollection).to.have.been.calledOnce()
})
it('should disable the CollectionsButton if there is no user project preferences', function () {
const wrapper = shallow(<MetaTools.wrappedComponent subject={favoriteSubject} />)
expect(wrapper.find(CollectionsButton).props().disabled).to.be.true()
})
it('should enable the CollectionsButton if there is user project preferences', function () {
const wrapper = shallow(<MetaTools.wrappedComponent subject={favoriteSubject} upp={{ id: '1' }} />)
expect(wrapper.find(CollectionsButton).props().disabled).to.be.false()
})
})
})