|
| 1 | +// import React from 'react'; |
| 2 | +// import { CountryDropdown, CountryRegionData } from '../../dist/rcrs.es'; |
| 3 | +// import Enzyme, { shallow } from 'enzyme'; |
| 4 | + |
| 5 | +// const Adapter = require('enzyme-adapter-react-16'); |
| 6 | +// Enzyme.configure({ adapter: new Adapter() }); |
| 7 | + |
| 8 | +// describe('CountryDropdown', () => { |
| 9 | +// it('sets ID attribute', () => { |
| 10 | +// const wrapper = shallow(<CountryDropdown id="id-attribute" />); |
| 11 | +// expect(wrapper.find('#id-attribute').length).toBe(1); |
| 12 | +// expect(wrapper.find('#fake-id-attribute').length).toBe(0); |
| 13 | +// }); |
| 14 | + |
| 15 | +// it('classes attribute gets recognized', () => { |
| 16 | +// const wrapper = shallow(<CountryDropdown classes="one two three" />); |
| 17 | +// expect(wrapper.find('select').hasClass('one two three')).toBe(true); |
| 18 | +// }); |
| 19 | + |
| 20 | +// it('passes arbitrary properties', () => { |
| 21 | +// const wrapper = shallow( |
| 22 | +// <CountryDropdown style={{ color: 'red' }} data-whatever="5" /> |
| 23 | +// ); |
| 24 | +// expect(wrapper.find('select').getElement().props.style.color).toBe('red'); |
| 25 | +// expect(wrapper.find('select').getElement().props['data-whatever']).toBe( |
| 26 | +// '5' |
| 27 | +// ); |
| 28 | +// }); |
| 29 | + |
| 30 | +// describe('name attribute', () => { |
| 31 | +// it('falls back on default name attribute when not specified', () => { |
| 32 | +// const wrapper = shallow(<CountryDropdown />); |
| 33 | +// expect(wrapper.find('select').getElement().props.name).toBe( |
| 34 | +// 'rcrs-country' |
| 35 | +// ); |
| 36 | +// }); |
| 37 | + |
| 38 | +// it('sets explicit name attribute', () => { |
| 39 | +// const wrapper = shallow(<CountryDropdown name="name-attribute" />); |
| 40 | +// expect(wrapper.find('select[name="name-attribute"]').length).toBe(1); |
| 41 | +// expect(wrapper.find('select[name="fake-name-attribute"]').length).toBe(0); |
| 42 | +// }); |
| 43 | +// }); |
| 44 | + |
| 45 | +// describe('disabled attribute', () => { |
| 46 | +// it('disabled attribute not on by default', () => { |
| 47 | +// const wrapper = shallow(<CountryDropdown />); |
| 48 | +// expect(wrapper.find('select').getElement().props.disabled).toBe(false); |
| 49 | +// }); |
| 50 | +// it('disabled attribute', () => { |
| 51 | +// const wrapper = shallow(<CountryDropdown disabled={true} />); |
| 52 | +// expect(wrapper.find('select').getElement().props.disabled).toBe(true); |
| 53 | +// }); |
| 54 | +// }); |
| 55 | + |
| 56 | +// describe('default blank option', () => { |
| 57 | +// it('showDefaultOption = false removes the default option', () => { |
| 58 | +// const wrapper = shallow(<CountryDropdown showDefaultOption={false} />); |
| 59 | +// expect(wrapper.find('option').length).toBe(CountryRegionData.length); |
| 60 | +// }); |
| 61 | + |
| 62 | +// it('confirm default label is "Select Country"', () => { |
| 63 | +// const wrapper = shallow(<CountryDropdown />); |
| 64 | +// expect(wrapper.find('select').childAt(0).text()).toBe('Select Country'); |
| 65 | +// }); |
| 66 | + |
| 67 | +// it('defaultOptionLabel', () => { |
| 68 | +// const customLabel = 'Holy moly I am a custom label!'; |
| 69 | +// const wrapper = shallow( |
| 70 | +// <CountryDropdown defaultOptionLabel={customLabel} /> |
| 71 | +// ); |
| 72 | +// expect(wrapper.find('select').childAt(0).text()).toBe(customLabel); |
| 73 | +// }); |
| 74 | +// }); |
| 75 | + |
| 76 | +// describe('country list', () => { |
| 77 | +// it('outputs the list of countries', () => { |
| 78 | +// const wrapper = shallow(<CountryDropdown />); |
| 79 | +// expect(wrapper.find('option').length).toBe(CountryRegionData.length + 1); // 1 for the "Select Country" default option |
| 80 | +// }); |
| 81 | + |
| 82 | +// it('respects the blacklist', () => { |
| 83 | +// const blacklist = ['GB', 'CA', 'US']; |
| 84 | +// const wrapper = shallow( |
| 85 | +// <CountryDropdown blacklist={blacklist} showDefaultOption={false} /> |
| 86 | +// ); |
| 87 | +// expect(wrapper.find('option').length).toBe( |
| 88 | +// CountryRegionData.length - blacklist.length |
| 89 | +// ); |
| 90 | + |
| 91 | +// // confirm a non-blacklist item appears |
| 92 | +// expect(wrapper.find('option[value="Afghanistan"]').length).toBe(1); |
| 93 | + |
| 94 | +// // confirm none of the blacklist item appears |
| 95 | +// expect(wrapper.find('option[value="United Kingdom"]').length).toBe(0); |
| 96 | +// expect(wrapper.find('option[value="Canada"]').length).toBe(0); |
| 97 | +// expect(wrapper.find('option[value="United States"]').length).toBe(0); |
| 98 | +// }); |
| 99 | + |
| 100 | +// it('respects the whitelist', () => { |
| 101 | +// const whitelist = ['GB', 'CA', 'US']; |
| 102 | +// const wrapper = shallow( |
| 103 | +// <CountryDropdown whitelist={whitelist} showDefaultOption={false} /> |
| 104 | +// ); |
| 105 | +// expect(wrapper.find('option').length).toBe(whitelist.length); |
| 106 | + |
| 107 | +// // confirm the expected items appear |
| 108 | +// expect(wrapper.find('option[value="United Kingdom"]').length).toBe(1); |
| 109 | +// expect(wrapper.find('option[value="Canada"]').length).toBe(1); |
| 110 | +// expect(wrapper.find('option[value="United States"]').length).toBe(1); |
| 111 | +// }); |
| 112 | +// }); |
| 113 | + |
| 114 | +// describe('valueType', () => { |
| 115 | +// it('confirm value is full country name by default', () => { |
| 116 | +// const wrapper = shallow(<CountryDropdown showDefaultOption={false} />); |
| 117 | +// expect(wrapper.find('select').childAt(0).getElement().props.value).toBe( |
| 118 | +// CountryRegionData[0][0] |
| 119 | +// ); |
| 120 | +// }); |
| 121 | + |
| 122 | +// it('confirm explicit valueType="full" also sets full country name', () => { |
| 123 | +// const wrapper = shallow( |
| 124 | +// <CountryDropdown showDefaultOption={false} valueType="full" /> |
| 125 | +// ); |
| 126 | +// expect(wrapper.find('select').childAt(0).getElement().props.value).toBe( |
| 127 | +// CountryRegionData[0][0] |
| 128 | +// ); |
| 129 | +// }); |
| 130 | + |
| 131 | +// it('confirm valueType="short" outputs country short code', () => { |
| 132 | +// const wrapper = shallow( |
| 133 | +// <CountryDropdown showDefaultOption={false} valueType="short" /> |
| 134 | +// ); |
| 135 | +// expect(wrapper.find('select').childAt(0).getElement().props.value).toBe( |
| 136 | +// CountryRegionData[0][1] |
| 137 | +// ); |
| 138 | +// }); |
| 139 | +// }); |
| 140 | + |
| 141 | +// describe('labelType', () => { |
| 142 | +// it('confirm label type is full country name by default', () => { |
| 143 | +// const wrapper = shallow(<CountryDropdown showDefaultOption={false} />); |
| 144 | +// expect(wrapper.find('select').childAt(0).text()).toBe( |
| 145 | +// CountryRegionData[0][0] |
| 146 | +// ); |
| 147 | +// }); |
| 148 | + |
| 149 | +// it('confirm label type is full country name when explicitly set', () => { |
| 150 | +// const wrapper = shallow( |
| 151 | +// <CountryDropdown showDefaultOption={false} labelType="full" /> |
| 152 | +// ); |
| 153 | +// expect(wrapper.find('select').childAt(0).text()).toBe( |
| 154 | +// CountryRegionData[0][0] |
| 155 | +// ); |
| 156 | +// }); |
| 157 | + |
| 158 | +// it('confirm label type is the country shortcode when set', () => { |
| 159 | +// const wrapper = shallow( |
| 160 | +// <CountryDropdown showDefaultOption={false} labelType="short" /> |
| 161 | +// ); |
| 162 | +// expect(wrapper.find('select').childAt(0).text()).toBe( |
| 163 | +// CountryRegionData[0][1] |
| 164 | +// ); |
| 165 | +// }); |
| 166 | +// }); |
| 167 | +// }); |
0 commit comments