Skip to content

Commit

Permalink
Add names to button queries
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla committed Sep 8, 2022
1 parent 4bf8afb commit c25047d
Showing 1 changed file with 39 additions and 34 deletions.
73 changes: 39 additions & 34 deletions packages/editor/src/components/post-publish-button/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,19 @@ describe( 'PostPublishButton', () => {
it( 'should be true if post is currently saving', () => {
render( <PostPublishButton isPublishable isSaveable isSaving /> );

expect( screen.getByRole( 'button' ) ).toHaveAttribute(
'aria-disabled',
'true'
);
expect(
screen.getByRole( 'button', { name: 'Submit for Review' } )
).toHaveAttribute( 'aria-disabled', 'true' );
} );

it( 'should be true if forceIsSaving is true', () => {
render(
<PostPublishButton isPublishable isSaveable forceIsSaving />
);

expect( screen.getByRole( 'button' ) ).toHaveAttribute(
'aria-disabled',
'true'
);
expect(
screen.getByRole( 'button', { name: 'Submit for Review' } )
).toHaveAttribute( 'aria-disabled', 'true' );
} );

it( 'should be true if post is not publishable and not forceIsDirty', () => {
Expand All @@ -40,19 +38,17 @@ describe( 'PostPublishButton', () => {
/>
);

expect( screen.getByRole( 'button' ) ).toHaveAttribute(
'aria-disabled',
'true'
);
expect(
screen.getByRole( 'button', { name: 'Submit for Review' } )
).toHaveAttribute( 'aria-disabled', 'true' );
} );

it( 'should be true if post is not saveable', () => {
render( <PostPublishButton isPublishable isSaveable={ false } /> );

expect( screen.getByRole( 'button' ) ).toHaveAttribute(
'aria-disabled',
'true'
);
expect(
screen.getByRole( 'button', { name: 'Submit for Review' } )
).toHaveAttribute( 'aria-disabled', 'true' );
} );

it( 'should be true if post saving is locked', () => {
Expand All @@ -64,10 +60,9 @@ describe( 'PostPublishButton', () => {
/>
);

expect( screen.getByRole( 'button' ) ).toHaveAttribute(
'aria-disabled',
'true'
);
expect(
screen.getByRole( 'button', { name: 'Submit for Review' } )
).toHaveAttribute( 'aria-disabled', 'true' );
} );

it( 'should be false if post is saveable but not publishable and forceIsDirty is true', () => {
Expand All @@ -79,19 +74,17 @@ describe( 'PostPublishButton', () => {
/>
);

expect( screen.getByRole( 'button' ) ).toHaveAttribute(
'aria-disabled',
'false'
);
expect(
screen.getByRole( 'button', { name: 'Submit for Review' } )
).toHaveAttribute( 'aria-disabled', 'false' );
} );

it( 'should be false if post is publishave and saveable', () => {
render( <PostPublishButton isPublishable isSaveable /> );

expect( screen.getByRole( 'button' ) ).toHaveAttribute(
'aria-disabled',
'false'
);
expect(
screen.getByRole( 'button', { name: 'Submit for Review' } )
).toHaveAttribute( 'aria-disabled', 'false' );
} );
} );

Expand All @@ -112,7 +105,9 @@ describe( 'PostPublishButton', () => {
/>
);

await user.click( screen.getByRole( 'button' ) );
await user.click(
screen.getByRole( 'button', { name: 'Submit for Review' } )
);

expect( onStatusChange ).toHaveBeenCalledWith( 'pending' );
} );
Expand All @@ -134,7 +129,9 @@ describe( 'PostPublishButton', () => {
/>
);

await user.click( screen.getByRole( 'button' ) );
await user.click(
screen.getByRole( 'button', { name: 'Submit for Review' } )
);

expect( onStatusChange ).toHaveBeenCalledWith( 'future' );
} );
Expand All @@ -156,7 +153,9 @@ describe( 'PostPublishButton', () => {
/>
);

await user.click( screen.getByRole( 'button' ) );
await user.click(
screen.getByRole( 'button', { name: 'Submit for Review' } )
);

expect( onStatusChange ).toHaveBeenCalledWith( 'private' );
} );
Expand All @@ -177,7 +176,9 @@ describe( 'PostPublishButton', () => {
/>
);

await user.click( screen.getByRole( 'button' ) );
await user.click(
screen.getByRole( 'button', { name: 'Submit for Review' } )
);

expect( onStatusChange ).toHaveBeenCalledWith( 'publish' );
} );
Expand All @@ -200,7 +201,9 @@ describe( 'PostPublishButton', () => {
/>
);

await user.click( screen.getByRole( 'button' ) );
await user.click(
screen.getByRole( 'button', { name: 'Submit for Review' } )
);

expect( onStatusChange ).toHaveBeenCalledWith( 'publish' );
expect( onSave ).toHaveBeenCalled();
Expand All @@ -210,6 +213,8 @@ describe( 'PostPublishButton', () => {
it( 'should have save modifier class', () => {
render( <PostPublishButton isSaving isPublished /> );

expect( screen.getByRole( 'button' ) ).toHaveClass( 'is-busy' );
expect(
screen.getByRole( 'button', { name: 'Submit for Review' } )
).toHaveClass( 'is-busy' );
} );
} );

0 comments on commit c25047d

Please sign in to comment.