Skip to content

Commit

Permalink
Merge branch 'develop' into fix/8843-dismiss-notification.
Browse files Browse the repository at this point in the history
  • Loading branch information
nfmohit committed Aug 2, 2024
2 parents 8ca8b76 + 14d4496 commit f0ba853
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.staged.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": [ "./.eslintrc.json" ],
"rules": []
"rules": {}
}
6 changes: 4 additions & 2 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,7 @@ jobs:
uses: actions/upload-artifact@v4
if: failure()
with:
name: e2e-screenshots
path: tests/e2e/screenshots
name: e2e-debugging-run[${{ github.run_attempt }}]-wp[${{ matrix.wp_version }}]-amp[${{ matrix.amp_version }}]
path: |
~/.npm/_logs/
tests/e2e/screenshots/
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,38 @@
/**
* WordPress dependencies
*/
import { useCallback } from '@wordpress/element';
import { __, _x } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { useSelect, useDispatch } from 'googlesitekit-data';
import { SpinnerButton } from 'googlesitekit-components';
import ReaderRevenueManagerIcon from '../../../../../svg/graphics/reader-revenue-manager.svg';
import { useRefocus } from '../../../../hooks/useRefocus';
import { MODULES_READER_REVENUE_MANAGER } from '../../datastore/constants';
import { PublicationSelect, PublicationOnboardingStateNotice } from '../common';

export default function SetupMain() {
const publicationID = useSelect( ( select ) =>
select( MODULES_READER_REVENUE_MANAGER ).getPublicationID()
);

const { resetPublications } = useDispatch( MODULES_READER_REVENUE_MANAGER );

const reset = useCallback( () => {
// Do not reset if the publication ID is already set.
if ( publicationID !== '' ) {
return;
}

resetPublications();
}, [ publicationID, resetPublications ] );

// Reset publication data when user re-focuses window.
useRefocus( reset, 15000 );

return (
<div className="googlesitekit-setup-module googlesitekit-setup-module--reader-revenue-manager">
<div className="googlesitekit-setup-module__logo">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
PUBLICATION_ONBOARDING_STATES,
UI_KEY_READER_REVENUE_MANAGER_SHOW_PUBLICATION_APPROVED_NOTIFICATION,
} from './constants';
import { actions as errorStoreActions } from '../../../googlesitekit/data/create-error-store';
import { HOUR_IN_SECONDS } from '../../../util';

const fetchGetPublicationsStore = createFetchStore( {
Expand All @@ -40,7 +41,7 @@ const fetchGetPublicationsStore = createFetchStore( {
MODULE_SLUG,
'publications',
{},
{ useCache: true }
{ useCache: false }
),
reducerCallback: ( state, publications ) => ( { ...state, publications } ),
} );
Expand Down Expand Up @@ -213,12 +214,38 @@ const baseActions = {

return completedOnboardingPublication || publications[ 0 ];
},

/**
* Resets the publications data in the store.
*
* @since n.e.x.t
*
* @return {Object} The dispatched action results.
*/
*resetPublications() {
const registry = yield commonActions.getRegistry();

yield {
type: 'RESET_PUBLICATIONS',
};

yield errorStoreActions.clearErrors( 'getPublications' );

return registry
.dispatch( MODULES_READER_REVENUE_MANAGER )
.invalidateResolutionForStoreSelector( 'getPublications' );
},
};

const baseControls = {};

const baseReducer = ( state, { type } ) => {
switch ( type ) {
case 'RESET_PUBLICATIONS':
return {
...state,
publications: baseInitialState.publications,
};
default:
return state;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,45 @@ describe( 'modules/reader-revenue-manager publications', () => {
).not.toBe( 0 );
} );
} );

describe( 'resetPublications', () => {
it( 'should reset the publications data in the store', async () => {
const response = fixtures.publications.slice( 0, 2 );
fetchMock.getOnce( publicationsEndpoint, {
body: response,
status: 200,
} );

registry
.dispatch( MODULES_READER_REVENUE_MANAGER )
.receiveGetPublications( fixtures.publications );

registry
.dispatch( MODULES_READER_REVENUE_MANAGER )
.receiveGetSettings( {} );

await registry
.dispatch( MODULES_READER_REVENUE_MANAGER )
.resetPublications();

registry
.select( MODULES_READER_REVENUE_MANAGER )
.getPublications();

await untilResolved(
registry,
MODULES_READER_REVENUE_MANAGER
).getPublications();

expect( fetchMock ).toHaveFetched();

expect(
registry
.select( MODULES_READER_REVENUE_MANAGER )
.getPublications()
).toEqual( response );
} );
} );
} );

describe( 'selectors', () => {
Expand Down
2 changes: 0 additions & 2 deletions bin/local-env/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.1'

services:
wordpress:
image: wordpress:5.6-php7.4
Expand Down
6 changes: 3 additions & 3 deletions bin/local-env/includes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export COMPOSE_PROJECT_NAME='googlesitekit-e2e'
if [ -t 0 ]; then
COMPOSE_EXEC_ARGS=""
else
COMPOSE_EXEC_ARGS="-T" # Disable pseudo-tty allocation. By default `docker-compose exec` allocates a TTY.
COMPOSE_EXEC_ARGS="-T" # Disable pseudo-tty allocation. By default `docker compose exec` allocates a TTY.
fi

##
Expand Down Expand Up @@ -155,10 +155,10 @@ command_exists() {
##
# Docker Compose helper
#
# Calls docker-compose with common options.
# Calls `docker compose` with common options.
##
dc() {
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS "$@"
docker compose $DOCKER_COMPOSE_FILE_OPTIONS "$@"
}

##
Expand Down
4 changes: 2 additions & 2 deletions bin/local-env/launch-containers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ fi

# Stop existing containers.
status_message "Stopping Docker containers..."
dc down --remove-orphans >/dev/null 2>&1
dc down --remove-orphans

# Download image updates.
status_message "Downloading Docker image updates..."
dc pull --quiet

# Launch the containers.
status_message "Starting Docker containers..."
dc up -d >/dev/null
dc up -d

0 comments on commit f0ba853

Please sign in to comment.