-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update StandardFieldComponent to RTL
- Loading branch information
Showing
2 changed files
with
40 additions
and
18 deletions.
There are no files selected for viewing
14 changes: 8 additions & 6 deletions
14
app/javascript/legacy_react/src/components/common/StandardFieldComponent.spec.tsx
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,25 +1,27 @@ | ||
// License: LGPL-3.0-or-later | ||
import * as React from 'react'; | ||
import {shallow} from 'enzyme' | ||
import {render, screen} from '@testing-library/react' | ||
import userEvent from '@testing-library/user-event' | ||
import StandardFieldComponent from './StandardFieldComponent' | ||
import toJson from 'enzyme-to-json'; | ||
|
||
describe('StandardFieldComponent', () => { | ||
test('works with no children', () => { | ||
var field = shallow(<StandardFieldComponent inError={false} />) | ||
var field = render(<StandardFieldComponent inError={false} />) | ||
|
||
|
||
expect(toJson(field)).toMatchSnapshot() | ||
expect(field.baseElement).toMatchSnapshot() | ||
}) | ||
test('works with a child', () => { | ||
var field = shallow(<StandardFieldComponent inError={false}><input/></StandardFieldComponent>); | ||
var field = render(<StandardFieldComponent inError={false}><input/></StandardFieldComponent>); | ||
|
||
expect(toJson(field)).toMatchSnapshot() | ||
expect(field.baseElement).toMatchSnapshot() | ||
}) | ||
|
||
test('sets error message properly', () => { | ||
var field = shallow(<StandardFieldComponent inError={true} error={"Something more"}><input/></StandardFieldComponent>); | ||
var field = render(<StandardFieldComponent inError={true} error={"Something more"}><input/></StandardFieldComponent>); | ||
|
||
expect(toJson(field)).toMatchSnapshot() | ||
expect(field.baseElement).toMatchSnapshot() | ||
}) | ||
}) |
44 changes: 32 additions & 12 deletions
44
...ipt/legacy_react/src/components/common/__snapshots__/StandardFieldComponent.spec.tsx.snap
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,21 +1,41 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`StandardFieldComponent sets error message properly 1`] = ` | ||
<div> | ||
<input /> | ||
<div | ||
className="help-block" | ||
role="alert" | ||
> | ||
Something more | ||
<body> | ||
<div> | ||
<div> | ||
<input /> | ||
<div | ||
class="help-block" | ||
role="alert" | ||
> | ||
Something more | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</body> | ||
`; | ||
|
||
exports[`StandardFieldComponent works with a child 1`] = ` | ||
<div> | ||
<input /> | ||
</div> | ||
<body> | ||
<div> | ||
<div> | ||
<input /> | ||
</div> | ||
</div> | ||
</body> | ||
`; | ||
|
||
exports[`StandardFieldComponent works with no children 1`] = `<div />`; | ||
exports[`StandardFieldComponent works with no children 1`] = ` | ||
<body> | ||
<div> | ||
<div> | ||
</div> | ||
</div> | ||
</body> | ||
`; |