Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for bug with toggling opensInNewWindow state (#17794)
* Update getDerivedStateFromProps to pass back all state property changes * Add test to check that state.opensInNewWindow is set correctly on prop change * Rename test file
- Loading branch information
1 parent
844b9b7
commit 12425d2
Showing
2 changed files
with
42 additions
and
2 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
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import InlineLinkUI from '../inline'; | ||
/** | ||
* External dependencies | ||
*/ | ||
import { shallow } from 'enzyme'; | ||
|
||
describe( 'InlineLinkUI', () => { | ||
it( 'InlineLinkUI renders', () => { | ||
const wrapper = shallow( | ||
<InlineLinkUI /> | ||
); | ||
expect( wrapper ).toBeTruthy(); | ||
} ); | ||
|
||
it( 'should set state.opensInNewWindow to false by default', () => { | ||
const wrapper = shallow( | ||
<InlineLinkUI activeAttributes={ {} } /> | ||
).dive(); | ||
|
||
expect( wrapper.state( 'opensInNewWindow' ) ).toEqual( false ); | ||
} ); | ||
|
||
it( 'should set state.opensInNewWindow to true if props.activeAttributes.target is _blank', () => { | ||
const givenProps = { | ||
addingLink: false, | ||
activeAttributes: { url: 'http://www.google.com', target: '_blank' }, | ||
}; | ||
|
||
const wrapper = shallow( | ||
<InlineLinkUI activeAttributes={ {} } /> | ||
).dive(); | ||
wrapper.setProps( givenProps ); | ||
expect( wrapper.state( 'opensInNewWindow' ) ).toEqual( true ); | ||
} ); | ||
} ); |