|
| 1 | +import React from 'react' |
| 2 | +import { shallow } from 'enzyme' |
| 3 | + |
| 4 | +import { NAMESPACE } from '../../../constants' |
| 5 | +import { ProgressBar } from '../' |
| 6 | + |
| 7 | +describe('<ProgressBar.Indicator />', () => { |
| 8 | + it('takes a className that gets appended', () => { |
| 9 | + const $ = shallow(<ProgressBar.Indicator className="test" />) |
| 10 | + expect($.hasClass(`${NAMESPACE}c-progress-bar__indicator`)).toBe(true) |
| 11 | + expect($.hasClass(`${NAMESPACE}c-progress-bar__indicator--animated`)).toBe(false) |
| 12 | + expect($.hasClass('test')).toBe(true) |
| 13 | + }) |
| 14 | + |
| 15 | + it('renders with an animated gradient', () => { |
| 16 | + const $ = shallow(<ProgressBar.Indicator animated />) |
| 17 | + expect($.hasClass(`${NAMESPACE}c-progress-bar__indicator`)).toBe(true) |
| 18 | + expect($.hasClass(`${NAMESPACE}c-progress-bar__indicator--animated`)).toBe(true) |
| 19 | + }) |
| 20 | + |
| 21 | + it('renders a defined tag type', () => { |
| 22 | + const $ = shallow(<ProgressBar.Indicator tag="article" />) |
| 23 | + expect($.type()).toBe('article') |
| 24 | + }) |
| 25 | + |
| 26 | + it('renders a div by default', () => { |
| 27 | + const $ = shallow(<ProgressBar.Indicator />) |
| 28 | + expect($.type()).toBe('div') |
| 29 | + }) |
| 30 | + |
| 31 | + it('renders with attributes', () => { |
| 32 | + const $ = shallow( |
| 33 | + <ProgressBar.Indicator style={{ position: 'relative' }} ariaHidden /> |
| 34 | + ) |
| 35 | + expect($.prop('style')).toEqual({ |
| 36 | + position: 'relative' |
| 37 | + }) |
| 38 | + expect($.prop('ariaHidden')).toBe(true) |
| 39 | + }) |
| 40 | + |
| 41 | + it('renders with the correct aria values', () => { |
| 42 | + const $ = shallow(<ProgressBar.Indicator percent="50" />) |
| 43 | + expect($.prop('role')).toBe('progressbar') |
| 44 | + expect($.prop('aria-valuemin')).toBe('0%') |
| 45 | + expect($.prop('aria-valuemax')).toBe('100%') |
| 46 | + expect($.prop('aria-valuenow')).toBe('50%') |
| 47 | + }) |
| 48 | + |
| 49 | + describe('percent prop', () => { |
| 50 | + it('renders an inline style width as a percentage', () => { |
| 51 | + const $ = shallow(<ProgressBar.Indicator percent="50" />) |
| 52 | + expect($.prop('style')).toEqual({ |
| 53 | + width: '50%' |
| 54 | + }) |
| 55 | + }) |
| 56 | + |
| 57 | + it('only appends the percentage unit if not passed', () => { |
| 58 | + const $ = shallow(<ProgressBar.Indicator percent="50%" />) |
| 59 | + expect($.prop('style')).toEqual({ |
| 60 | + width: '50%' |
| 61 | + }) |
| 62 | + }) |
| 63 | + }) |
| 64 | +}) |
0 commit comments