Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move files in dashboard directory. #9166

Merged
merged 9 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/js/components/DashboardMainApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import {
AudienceSegmentationSetupCTAWidget,
AudienceSelectionPanel,
} from '../modules/analytics-4/components/audience-segmentation/dashboard';
import ReaderRevenueManagerSetupCTABanner from '../modules/reader-revenue-manager/components/ReaderRevenueManagerSetupCTABanner';
import ReaderRevenueManagerSetupCTABanner from '../modules/reader-revenue-manager/components/dashboard/ReaderRevenueManagerSetupCTABanner';
import EntitySearchInput from './EntitySearchInput';
import DateRangeSelector from './DateRangeSelector';
import HelpMenu from './help/HelpMenu';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,21 @@ import {
BREAKPOINT_SMALL,
BREAKPOINT_TABLET,
useBreakpoint,
} from '../../../hooks/useBreakpoint';
import useActivateModuleCallback from '../../../hooks/useActivateModuleCallback';
import whenInactive from '../../../util/when-inactive';
import { withWidgetComponentProps } from '../../../googlesitekit/widgets/util';
import { CORE_USER } from '../../../googlesitekit/datastore/user/constants';
} from '../../../../hooks/useBreakpoint';
import useActivateModuleCallback from '../../../../hooks/useActivateModuleCallback';
import whenInactive from '../../../../util/when-inactive';
import { withWidgetComponentProps } from '../../../../googlesitekit/widgets/util';
import { CORE_MODULES } from '../../../../googlesitekit/modules/datastore/constants';
import { CORE_USER } from '../../../../googlesitekit/datastore/user/constants';
import {
READER_REVENUE_MANAGER_MODULE_SLUG,
READER_REVENUE_MANAGER_SETUP_BANNER_DISMISSED_KEY,
} from '../datastore/constants';
import { Cell, Grid, Row } from '../../../material-components';
import SetupSVG from '../../../../svg/graphics/reader-revenue-manager-setup.svg';
import SetupTabletSVG from '../../../../svg/graphics/reader-revenue-manager-setup-tablet.svg';
import SetupMobileSVG from '../../../../svg/graphics/reader-revenue-manager-setup-mobile.svg';
import Link from '../../../components/Link';
} from '../../datastore/constants';
import { Cell, Grid, Row } from '../../../../material-components';
import SetupSVG from '../../../../../svg/graphics/reader-revenue-manager-setup.svg';
import SetupTabletSVG from '../../../../../svg/graphics/reader-revenue-manager-setup-tablet.svg';
import SetupMobileSVG from '../../../../../svg/graphics/reader-revenue-manager-setup-mobile.svg';
import Link from '../../../../components/Link';

function ReaderRevenueManagerSetupCTABanner( { Widget, WidgetNull } ) {
const breakpoint = useBreakpoint();
Expand All @@ -76,7 +77,13 @@ function ReaderRevenueManagerSetupCTABanner( { Widget, WidgetNull } ) {
const readerRevenueManagerDocumentationURL =
'https://readerrevenue.withgoogle.com';

if ( isDismissed || isDismissed === undefined ) {
const canActivateRRMModule = useSelect( ( select ) =>
select( CORE_MODULES ).canActivateModule(
READER_REVENUE_MANAGER_MODULE_SLUG
)
);

if ( isDismissed || isDismissed === undefined || ! canActivateRRMModule ) {
return <WidgetNull />;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
/**
* Internal dependencies
*/
import { provideModules } from '../../../../../tests/js/utils';
import { withWidgetComponentProps } from '../../../googlesitekit/widgets/util';
import WithRegistrySetup from '../../../../../tests/js/WithRegistrySetup';
import { provideModules } from '../../../../../../tests/js/utils';
import { withWidgetComponentProps } from '../../../../googlesitekit/widgets/util';
import WithRegistrySetup from '../../../../../../tests/js/WithRegistrySetup';
import ReaderRevenueManagerSetupCTABanner from './ReaderRevenueManagerSetupCTABanner';
import { READER_REVENUE_MANAGER_MODULE_SLUG } from '../datastore/constants';
import { CORE_USER } from '../../../googlesitekit/datastore/user/constants';
import { READER_REVENUE_MANAGER_MODULE_SLUG } from '../../datastore/constants';
import { CORE_USER } from '../../../../googlesitekit/datastore/user/constants';

const WidgetWithComponentProps = withWidgetComponentProps(
'readerRevenueManagerSetupCTABanner'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,18 @@ import {
fireEvent,
provideModules,
waitFor,
} from '../../../../../tests/js/test-utils';
import { getWidgetComponentProps } from '../../../googlesitekit/widgets/util';
import { CORE_USER } from '../../../googlesitekit/datastore/user/constants';
} from '../../../../../../tests/js/test-utils';
import { getWidgetComponentProps } from '../../../../googlesitekit/widgets/util';
import { CORE_USER } from '../../../../googlesitekit/datastore/user/constants';
import { CORE_MODULES } from '../../../../googlesitekit/modules/datastore/constants';
import {
ERROR_CODE_NON_HTTPS_SITE,
READER_REVENUE_MANAGER_MODULE_SLUG,
READER_REVENUE_MANAGER_SETUP_BANNER_DISMISSED_KEY,
} from '../datastore/constants';
import useActivateModuleCallback from '../../../hooks/useActivateModuleCallback';
} from '../../datastore/constants';
import useActivateModuleCallback from '../../../../hooks/useActivateModuleCallback';

jest.mock( '../../../hooks/useActivateModuleCallback' );
jest.mock( '../../../../hooks/useActivateModuleCallback' );

describe( 'ReaderRevenueManagerSetupCTABanner', () => {
let registry;
Expand Down Expand Up @@ -106,7 +108,13 @@ describe( 'ReaderRevenueManagerSetupCTABanner', () => {
} );

it( 'should call the "useActivateModuleCallback" hook when the setup CTA is clicked', async () => {
const { getByRole, waitForRegistry } = render(
registry
.dispatch( CORE_MODULES )
.receiveCheckRequirementsSuccess(
READER_REVENUE_MANAGER_MODULE_SLUG
);

const { container, getByRole, waitForRegistry } = render(
<ReaderRevenueManagerSetupCTABanner
Widget={ Widget }
WidgetNull={ WidgetNull }
Expand All @@ -118,8 +126,12 @@ describe( 'ReaderRevenueManagerSetupCTABanner', () => {

await waitForRegistry();

expect( container ).not.toBeEmptyDOMElement();

fireEvent.click(
getByRole( 'button', { name: /Set up Reader Revenue Manager/i } )
getByRole( 'button', {
name: /Set up Reader Revenue Manager/i,
} )
);

expect( activateModuleMock ).toHaveBeenCalledTimes( 1 );
Expand Down Expand Up @@ -154,4 +166,36 @@ describe( 'ReaderRevenueManagerSetupCTABanner', () => {
expect( fetchMock ).toHaveFetchedTimes( 1 );
} );
} );

it( 'should not render the Reader Revenue Manager setup CTA banner when the module requirements do not meet', async () => {
// Throw error from checkRequirements to simulate non-HTTPS site error.
provideModules( registry, [
{
slug: READER_REVENUE_MANAGER_MODULE_SLUG,
active: false,
checkRequirements: () => {
throw {
code: ERROR_CODE_NON_HTTPS_SITE,
message:
'The site should use HTTPS to set up Reader Revenue Manager',
data: null,
};
},
},
] );

const { container, waitForRegistry } = render(
<ReaderRevenueManagerSetupCTABanner
Widget={ Widget }
WidgetNull={ WidgetNull }
/>,
{
registry,
}
);

await waitForRegistry();

expect( container ).toBeEmptyDOMElement();
} );
} );
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
*/

export { default as PublicationApprovedOverlayNotification } from './PublicationApprovedOverlayNotification';
export { default as ReaderRevenueManagerSetupCTABanner } from './ReaderRevenueManagerSetupCTABanner';
export { default as RRMSetupSuccessSubtleNotification } from './RRMSetupSuccessSubtleNotification';
Loading