-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Components: Fix no-node-access violations in FocalPointPicker tests (#…
- Loading branch information
Showing
1 changed file
with
26 additions
and
21 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,58 +1,63 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { render } from '@testing-library/react'; | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Media from '../media'; | ||
|
||
const getMedia = ( container ) => | ||
container.querySelector( '.components-focal-point-picker__media' ); | ||
|
||
describe( 'FocalPointPicker/Media', () => { | ||
describe( 'Basic rendering', () => { | ||
it( 'should render', () => { | ||
const { container } = render( <Media /> ); | ||
const el = getMedia( container ); | ||
render( <Media data-testid="media" /> ); | ||
|
||
expect( el ).toBeTruthy(); | ||
expect( screen.getByTestId( 'media' ) ).toBeVisible(); | ||
} ); | ||
} ); | ||
|
||
describe( 'Media types', () => { | ||
it( 'should render a placeholder by default', () => { | ||
const { container } = render( <Media /> ); | ||
const el = getMedia( container ); | ||
render( <Media data-testid="media" /> ); | ||
|
||
expect( el.outerHTML ).toContain( 'placeholder' ); | ||
expect( screen.getByTestId( 'media' ) ).toHaveClass( | ||
'components-focal-point-picker__media--placeholder' | ||
); | ||
} ); | ||
|
||
it( 'should render an video if src is a video file', () => { | ||
const { container, rerender } = render( | ||
<Media src="file.mp4" muted={ false } /> | ||
const { rerender } = render( | ||
<Media src="file.mp4" muted={ false } data-testid="media" /> | ||
); | ||
|
||
expect( getMedia( container ).tagName ).toBe( 'VIDEO' ); | ||
expect( screen.getByTestId( 'media' ).tagName ).toBe( 'VIDEO' ); | ||
|
||
rerender( <Media src="file.ogg" muted={ false } /> ); | ||
rerender( | ||
<Media src="file.ogg" muted={ false } data-testid="media" /> | ||
); | ||
|
||
expect( getMedia( container ).tagName ).toBe( 'VIDEO' ); | ||
expect( screen.getByTestId( 'media' ).tagName ).toBe( 'VIDEO' ); | ||
|
||
rerender( <Media src="file.webm" muted={ false } /> ); | ||
rerender( | ||
<Media src="file.webm" muted={ false } data-testid="media" /> | ||
); | ||
|
||
expect( getMedia( container ).tagName ).toBe( 'VIDEO' ); | ||
expect( screen.getByTestId( 'media' ).tagName ).toBe( 'VIDEO' ); | ||
} ); | ||
|
||
it( 'should render an image file, if not video', () => { | ||
const { container, rerender } = render( <Media src="file.gif" /> ); | ||
const { rerender } = render( | ||
<Media src="file.gif" data-testid="media" /> | ||
); | ||
|
||
expect( getMedia( container ).tagName ).toBe( 'IMG' ); | ||
expect( screen.getByTestId( 'media' ).tagName ).toBe( 'IMG' ); | ||
|
||
rerender( <Media src="file.png" muted={ false } /> ); | ||
rerender( | ||
<Media src="file.png" muted={ false } data-testid="media" /> | ||
); | ||
|
||
expect( getMedia( container ).tagName ).toBe( 'IMG' ); | ||
expect( screen.getByTestId( 'media' ).tagName ).toBe( 'IMG' ); | ||
} ); | ||
} ); | ||
} ); |