Skip to content

Test logic within notification registration #9273

Open

Description

Feature Description

In #8978 and #8979, the ErrorNotifications.test.js require "mock" registration of notifications using the new Notifications datastore register function.

it( 'does not render UnsatisfiedScopesAlert when user is not authenticated', () => {
provideUserAuthentication( registry, {
authenticated: false,
unsatisfiedScopes: [
'https://www.googleapis.com/auth/analytics.readonly',
],
} );
const { container } = render( <ErrorNotifications />, {
registry,
} );
expect( container.childElementCount ).toBe( 0 );
} );
it( 'renders UnsatisfiedScopesAlert when user is authenticated', () => {
provideUserAuthentication( registry, {
unsatisfiedScopes: [
'https://www.googleapis.com/auth/analytics.readonly',
],
} );
const { container } = render( <ErrorNotifications />, {
registry,
} );
expect( container ).toHaveTextContent(
'Site Kit can’t access necessary data'
);
expect( container ).toMatchSnapshot();
} );

This would require us to "copy-paste" code that registers notifications within our tests. In addition to copy-pasting, the main drawback here is that our tests do not actually cover the real production registration code within register-defaults.js. So we need a way to cover the logic within this code. We could perhaps create a utility function that wraps production registration code and adds it to a test registry.


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

Implementation Brief

  • Update tests/js/utils.js
    • Add provideNotificationsRegistration util function
      • It should accept registry and extraData arguments
      • Use createNotifications with provided registry argument to include notifications into the test registry. You can check its usage in assets/js/googlesitekit-notifications.js
      • If extraData is passed, it should be object consisting of {id, settings} data, which can be forwarded to the registerNotification action of CORE_NOTIFICATIONS datastore, to include extra notification registration if needed .
  • Return referenced tests in AC, provideNotificationsRegistration util will include the notifications in the test registry so notifications can be rendered

Test Coverage

  • No changes needed, issue is about tests

QA Brief

Changelog entry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

P2Low priorityTeam SIssues for Squad 1Type: EnhancementImprovement of an existing feature

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions