Skip to content

Commit

Permalink
Add test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
hussain-t committed Dec 1, 2022
1 parent a091984 commit 5e6e0ac
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions assets/js/components/settings/SettingsActiveModule/Header.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import {
provideModules,
fireEvent,
} from '../../../../../tests/js/test-utils';
import { MODULES_ANALYTICS } from '../../../modules/analytics/datastore/constants';
import { CORE_MODULES } from '../../../googlesitekit/modules/datastore/constants';

describe( 'Header', () => {
const history = createHashHistory();
Expand Down Expand Up @@ -85,6 +87,7 @@ describe( 'Header', () => {
connected: false,
},
] );
registry.dispatch( MODULES_ANALYTICS ).receiveGetSettings( {} );
} );

it( 'should render "Connected" for a connected module', () => {
Expand Down Expand Up @@ -115,6 +118,44 @@ describe( 'Header', () => {
expect( button ).toHaveTextContent( 'Connect Google Analytics 4' );
} );

it( 'should not render the button to connect GA4 if Analytics is connected without access to it but GA4 is not', () => {
registry
.dispatch( MODULES_ANALYTICS )
.receiveGetSettings( { ownerID: 100 } );
registry
.dispatch( CORE_MODULES )
.receiveCheckModuleAccess(
{ access: false },
{ slug: 'analytics' }
);
const { container } = render( <Header slug="analytics" />, {
registry,
} );

expect(
container.querySelector( '.googlesitekit-settings-module__status' )
).toHaveTextContent( 'Google Analytics 4 is not connected' );
} );

it( 'should render a GA4 not connected status if Analytics is connected without access to it but GA4 is not', () => {
registry
.dispatch( MODULES_ANALYTICS )
.receiveGetSettings( { ownerID: 100 } );
registry
.dispatch( CORE_MODULES )
.receiveCheckModuleAccess(
{ access: false },
{ slug: 'analytics' }
);
const { queryByRole } = render( <Header slug="analytics" />, {
registry,
} );

expect(
queryByRole( 'button', { name: /connect google analytics 4/i } )
).not.toBeInTheDocument();
} );

it( 'should open the tab when ENTER key is pressed', () => {
history.push( '/connected-services' );

Expand Down

0 comments on commit 5e6e0ac

Please sign in to comment.