-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* test(Fade): migrate to rtl * test(ButtonDropdown): migrate to rtl * test(Row): migrate to RTL * test(Spinner): migrate to rtl * test(Form): migrate to RTL * test(Form): migrate to RTL * test(#2625): migrate FormFeedback to rtl
- Loading branch information
1 parent
bf28db5
commit 8a33920
Showing
6 changed files
with
117 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,38 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import { ButtonDropdown, DropdownToggle, DropdownMenu, DropdownItem } from '..'; | ||
|
||
describe('ButtonDropdown', () => { | ||
let isOpen; | ||
let toggle; | ||
|
||
beforeEach(() => { | ||
isOpen = false; | ||
toggle = () => { | ||
isOpen = !isOpen; | ||
}; | ||
toggle = () => {}; | ||
}); | ||
|
||
it('should render a single child', () => { | ||
const wrapper = mount( | ||
<ButtonDropdown isOpen={isOpen} toggle={toggle}> | ||
render( | ||
<ButtonDropdown isOpen toggle={toggle}> | ||
Ello world | ||
</ButtonDropdown>, | ||
); | ||
|
||
expect(wrapper.find('.btn-group').hostNodes().text()).toBe('Ello world'); | ||
expect(wrapper.find('.btn-group').hostNodes().length).toBe(1); | ||
expect(screen.getByText('Ello world')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render multiple children when isOpen', () => { | ||
isOpen = true; | ||
const wrapper = mount( | ||
<ButtonDropdown isOpen={isOpen} toggle={toggle}> | ||
render( | ||
<ButtonDropdown isOpen toggle={toggle}> | ||
<DropdownToggle>Toggle</DropdownToggle> | ||
<DropdownMenu> | ||
<DropdownItem>Test</DropdownItem> | ||
</DropdownMenu> | ||
</ButtonDropdown>, | ||
); | ||
|
||
expect(wrapper.find('.btn').hostNodes().text()).toBe('Toggle'); | ||
expect(wrapper.find('.btn-group').hostNodes().length).toBe(1); | ||
expect(wrapper.find('.dropdown-item').hostNodes().length).toBe(1); | ||
expect(wrapper.childAt(0).childAt(0).childAt(0).children().length).toBe(2); | ||
expect(screen.getByText(/toggle/i)).toBeInTheDocument(); | ||
expect(screen.getByText(/test/i)).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,25 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { Form } from '..'; | ||
import { | ||
testForChildrenInComponent, | ||
testForCustomClass, | ||
testForCustomTag, | ||
testForDefaultTag, | ||
} from '../testUtils'; | ||
|
||
describe('Form', () => { | ||
it('should render with "form" tag', () => { | ||
const wrapper = shallow(<Form>Yo!</Form>); | ||
|
||
expect(wrapper.type()).toBe('form'); | ||
testForDefaultTag(Form, 'form'); | ||
}); | ||
|
||
it('should render children', () => { | ||
const wrapper = shallow(<Form>Yo!</Form>); | ||
|
||
expect(wrapper.text()).toBe('Yo!'); | ||
testForChildrenInComponent(Form); | ||
}); | ||
|
||
it('should render additional classes', () => { | ||
const wrapper = shallow(<Form className="other">Yo!</Form>); | ||
|
||
expect(wrapper.hasClass('other')).toBe(true); | ||
testForCustomClass(Form); | ||
}); | ||
|
||
it('should render custom tag', () => { | ||
const wrapper = shallow(<Form tag="main">Yo!</Form>); | ||
|
||
expect(wrapper.type()).toBe('main'); | ||
testForCustomTag(Form); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,48 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { FormFeedback } from '..'; | ||
import { | ||
testForChildrenInComponent, | ||
testForCustomClass, | ||
testForCustomTag, | ||
testForDefaultClass, | ||
testForDefaultTag, | ||
} from '../testUtils'; | ||
|
||
describe('FormFeedback', () => { | ||
it('should render with "form" tag by default', () => { | ||
const wrapper = shallow(<FormFeedback>Yo!</FormFeedback>); | ||
|
||
expect(wrapper.type()).toBe('div'); | ||
it('should render with "div" tag by default', () => { | ||
testForDefaultTag(FormFeedback, 'div'); | ||
}); | ||
|
||
it('should render children', () => { | ||
const wrapper = shallow(<FormFeedback>Yo!</FormFeedback>); | ||
|
||
expect(wrapper.text()).toBe('Yo!'); | ||
testForChildrenInComponent(FormFeedback); | ||
}); | ||
|
||
it('should render with "invalid-feedback" class', () => { | ||
const wrapper = shallow(<FormFeedback>Yo!</FormFeedback>); | ||
expect(wrapper.hasClass('invalid-feedback')).toBe(true); | ||
testForDefaultClass(FormFeedback, 'invalid-feedback'); | ||
}); | ||
|
||
it('should render with "valid-feedback" class', () => { | ||
const wrapper = shallow(<FormFeedback valid>Yo!</FormFeedback>); | ||
render(<FormFeedback valid>Yo!</FormFeedback>); | ||
|
||
expect(wrapper.hasClass('valid-feedback')).toBe(true); | ||
expect(screen.getByText(/yo/i)).toHaveClass('valid-feedback'); | ||
}); | ||
|
||
it('should render with "valid-tooltip" class', () => { | ||
const wrapper = shallow( | ||
render( | ||
<FormFeedback valid tooltip> | ||
Yo! | ||
</FormFeedback>, | ||
); | ||
|
||
expect(wrapper.hasClass('valid-tooltip')).toBe(true); | ||
expect(screen.getByText(/yo/i)).toHaveClass('valid-tooltip'); | ||
}); | ||
|
||
it('should render additional classes', () => { | ||
const wrapper = shallow(<FormFeedback className="other">Yo!</FormFeedback>); | ||
|
||
expect(wrapper.hasClass('other')).toBe(true); | ||
testForCustomClass(FormFeedback); | ||
}); | ||
|
||
it('should render custom tag', () => { | ||
const wrapper = shallow(<FormFeedback tag="main">Yo!</FormFeedback>); | ||
|
||
expect(wrapper.type()).toBe('main'); | ||
testForCustomTag(FormFeedback); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,38 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import { Row } from '..'; | ||
import { | ||
testForChildrenInComponent, | ||
testForCustomClass, | ||
testForDefaultClass, | ||
} from '../testUtils'; | ||
|
||
describe('Row', () => { | ||
it('should render .row markup', () => { | ||
const wrapper = shallow(<Row />); | ||
|
||
expect(wrapper.html()).toBe('<div class="row"></div>'); | ||
testForDefaultClass(Row, 'row'); | ||
}); | ||
|
||
it('should render children', () => { | ||
const wrapper = shallow(<Row>Children</Row>); | ||
|
||
expect(wrapper.html()).toBe('<div class="row">Children</div>'); | ||
testForChildrenInComponent(Row); | ||
}); | ||
|
||
it('should pass additional classNames', () => { | ||
const wrapper = shallow(<Row className="extra" />); | ||
|
||
expect(wrapper.hasClass('extra')).toBe(true); | ||
expect(wrapper.hasClass('row')).toBe(true); | ||
testForCustomClass(Row); | ||
}); | ||
|
||
it('show render noGutters class as gx-0', () => { | ||
const wrapper = shallow(<Row noGutters />); | ||
|
||
expect(wrapper.hasClass('gx-0')).toBe(true); | ||
expect(wrapper.hasClass('row')).toBe(true); | ||
render(<Row noGutters data-testid="row" />); | ||
expect(screen.getByTestId('row')).toHaveClass('gx-0 row'); | ||
}); | ||
|
||
it('should pass row col size specific classes as strings', () => { | ||
const wrapper = shallow(<Row sm="6" />); | ||
|
||
expect(wrapper.hasClass('row-cols-sm-6')).toBe(true); | ||
render(<Row sm="6" data-testid="row" />); | ||
expect(screen.getByTestId('row')).toHaveClass('row-cols-sm-6'); | ||
}); | ||
|
||
it('should pass row col size specific classes as numbers', () => { | ||
const wrapper = shallow(<Row sm={6} />); | ||
|
||
expect(wrapper.hasClass('row-cols-sm-6')).toBe(true); | ||
render(<Row sm={6} data-testid="row" />); | ||
expect(screen.getByTestId('row')).toHaveClass('row-cols-sm-6'); | ||
}); | ||
}); |
Oops, something went wrong.