Skip to content

Commit

Permalink
Merge pull request #9120 from google/fix/8843-dismiss-notification
Browse files Browse the repository at this point in the history
  • Loading branch information
nfmohit authored Aug 2, 2024
2 parents 14d4496 + f0ba853 commit 1ee7f87
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export default function PublicationApprovedOverlayNotification() {
<Button
disabled={ isDismissing }
href={ serviceURL }
onClick={ dismissNotification }
trailingIcon={ <ExternalIcon width={ 13 } height={ 13 } /> }
target="_blank"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,21 @@
* limitations under the License.
*/

/**
* External dependencies
*/
import fetchMock from 'fetch-mock';

/**
* Internal dependencies
*/
import { createTestRegistry } from '../../../../../../tests/js/utils';
import { render } from '../../../../../../tests/js/test-utils';
import {
act,
fireEvent,
render,
waitForDefaultTimeouts,
} from '../../../../../../tests/js/test-utils';
import PublicationApprovedOverlayNotification, {
RRM_PUBLICATION_APPROVED_OVERLAY_NOTIFICATION,
} from './PublicationApprovedOverlayNotification';
Expand All @@ -36,6 +46,10 @@ import { CORE_USER } from '../../../../googlesitekit/datastore/user/constants';
describe( 'PublicationApprovedOverlayNotification', () => {
let registry;

const dismissItemsEndpoint = new RegExp(
'^/google-site-kit/v1/core/user/data/dismiss-item'
);

beforeEach( () => {
registry = createTestRegistry();
registry
Expand Down Expand Up @@ -127,4 +141,35 @@ describe( 'PublicationApprovedOverlayNotification', () => {
// Component should return null.
expect( container.firstChild ).toBeNull();
} );

it( 'should get dismissed when "Enable features" CTA is clicked', async () => {
registry.dispatch( CORE_USER ).receiveGetDismissedItems( [] );

fetchMock.postOnce( dismissItemsEndpoint, {
body: {
data: {
slug: RRM_PUBLICATION_APPROVED_OVERLAY_NOTIFICATION,
expiration: 0,
},
},
status: 200,
} );

const { getByRole, waitForRegistry } = render(
<ViewContextProvider value={ VIEW_CONTEXT_MAIN_DASHBOARD }>
<PublicationApprovedOverlayNotification />
</ViewContextProvider>,
{
registry,
}
);

await waitForRegistry();

fireEvent.click( getByRole( 'button', { name: /Enable features/i } ) );

await act( waitForDefaultTimeouts );

expect( fetchMock ).toHaveFetched( dismissItemsEndpoint );
} );
} );

0 comments on commit 1ee7f87

Please sign in to comment.