🧑‍💻 Add a Reset-Store action for testing

This commit is contained in:
Philipp Stracker 2024-10-30 16:55:44 +01:00
parent 0faeb5fd6b
commit 49c24f56d0
No known key found for this signature in database
4 changed files with 20 additions and 0 deletions

View file

@ -1,4 +1,6 @@
export default {
RESET_ONBOARDING: 'RESET_ONBOARDING',
// Transient data.
SET_ONBOARDING_IS_READY: 'SET_ONBOARDING_IS_READY',
SET_IS_SAVING_ONBOARDING: 'SET_IS_SAVING_ONBOARDING',

View file

@ -3,6 +3,15 @@ import { apiFetch } from '@wordpress/data-controls';
import ACTION_TYPES from './action-types';
import { NAMESPACE, STORE_NAME } from '../constants';
/**
* Special. Resets all values in the onboarding store to initial defaults.
*
* @return {{type: string}} The action.
*/
export const resetOnboarding = () => {
return { type: ACTION_TYPES.RESET_ONBOARDING };
};
/**
* Non-persistent. Marks the onboarding details as "ready", i.e., fully initialized.
*

View file

@ -46,6 +46,10 @@ export const onboardingReducer = (
};
switch ( type ) {
// Reset store to initial state.
case ACTION_TYPES.RESET_ONBOARDING:
return setPersistent( defaultState.data );
// Transient data.
case ACTION_TYPES.SET_ONBOARDING_IS_READY:
return setTransient( { isReady: action.isReady } );

View file

@ -44,9 +44,14 @@ export const initStore = () => {
console.groupEnd();
};
window.ppcpSettings.resetStore = () => {
wp.data.dispatch( STORE_NAME ).resetOnboarding();
wp.data.dispatch( STORE_NAME ).persist();
};
window.ppcpSettings.startOnboarding = () => {
wp.data.dispatch( STORE_NAME ).setCompleted( false );
wp.data.dispatch( STORE_NAME ).setOnboardingStep( 0 );
wp.data.dispatch( STORE_NAME ).persist();
};
}
/* eslint-enable no-console */