Skip to content

Commit

Permalink
Fix unit tests and update snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
delawski committed Mar 19, 2021
1 parent 56ceb8c commit 4794812
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 24 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ describe( 'AMPValidationStatusNotification', () => {

function setupUseSelect( overrides ) {
useSelect.mockImplementation( () => ( {
ampCompatibilityBroken: false,
fetchingErrorsRequestErrorMessage: '',
hasValidationErrors: false,
isDraft: false,
isEditedPostNew: false,
isFetchingErrors: false,
keptMarkupValidationErrorCount: 0,
reviewLink: 'http://example.com',
unreviewedValidationErrorCount: 0,
validationErrorCount: 0,
...overrides,
} ) );
}
Expand All @@ -51,27 +52,30 @@ describe( 'AMPValidationStatusNotification', () => {
container = null;
} );

it( 'renders message when there are no AMP validation errors', () => {
setupUseSelect();
it( 'does not render when errors are being fetched', () => {
setupUseSelect( {
isFetchingErrors: true,
} );

act( () => {
render( <AMPValidationStatusNotification />, container );
} );

expect( container.innerHTML ).toMatchSnapshot();
expect( container.innerHTML ).toContain( 'All issues reviewed or removed' );
expect( container.children ).toHaveLength( 0 );
} );

it( 'does not render when errors are being fetched', () => {
it( 'renders message when the post is new', () => {
setupUseSelect( {
isFetchingErrors: true,
isEditedPostNew: true,
} );

act( () => {
render( <AMPValidationStatusNotification />, container );
} );

expect( container.children ).toHaveLength( 0 );
expect( container.innerHTML ).toMatchSnapshot();
expect( container.innerHTML ).toContain( 'Validation will be checked upon saving' );
expect( container.querySelector( 'a[href="http://example.com"]' ) ).toBeNull();
} );

it( 'renders error message when API request error is present', () => {
Expand Down Expand Up @@ -102,46 +106,57 @@ describe( 'AMPValidationStatusNotification', () => {
expect( savePost ).toHaveBeenCalledWith( { isPreview: true } );
} );

it( 'renders error message when AMP compatibility is broken', () => {
it( 'renders error message when there are kept issues', () => {
setupUseSelect( {
ampCompatibilityBroken: true,
keptMarkupValidationErrorCount: 2,
} );

act( () => {
render( <AMPValidationStatusNotification />, container );
} );

expect( container.innerHTML ).toMatchSnapshot();
expect( container.innerHTML ).toContain( 'validation issues marked kept' );
expect( container.innerHTML ).toContain( 'AMP is disabled due to invalid markup being kept for 2 issues.' );
expect( container.querySelector( 'a[href="http://example.com"]' ) ).not.toBeNull();
} );

it( 'renders message when there are AMP validation errors', () => {
it( 'renders message when there are unreviewed issues', () => {
setupUseSelect( {
hasValidationErrors: true,
unreviewedValidationErrorCount: 3,
} );

act( () => {
render( <AMPValidationStatusNotification />, container );
} );

expect( container.innerHTML ).toMatchSnapshot();
expect( container.innerHTML ).toContain( 'issues needs review' );
expect( container.innerHTML ).toContain( 'AMP is enabled, but 3 issues need review.' );
expect( container.querySelector( 'a[href="http://example.com"]' ) ).not.toBeNull();
} );

it( 'renders message when there are no errors and post is new', () => {
it( 'renders message when there are reviewed issues', () => {
setupUseSelect( {
isEditedPostNew: true,
validationErrorCount: 1,
} );

act( () => {
render( <AMPValidationStatusNotification />, container );
} );

expect( container.innerHTML ).toMatchSnapshot();
expect( container.innerHTML ).toContain( 'issues will be checked for when the post is saved' );
expect( container.querySelector( 'a[href="http://example.com"]' ) ).toBeNull();
expect( container.innerHTML ).toContain( 'AMP is enabled, and 1 validation issue has been reviewed.' );
expect( container.querySelector( 'a[href="http://example.com"]' ) ).not.toBeNull();
} );

it( 'renders message when there are no AMP validation errors', () => {
setupUseSelect();

act( () => {
render( <AMPValidationStatusNotification />, container );
} );

expect( container.innerHTML ).toMatchSnapshot();
expect( container.innerHTML ).toContain( 'AMP is enabled. There are no validation issues.' );
} );
} );

0 comments on commit 4794812

Please sign in to comment.