@wordpress/e2e-tests
Version:
End-To-End (E2E) tests for WordPress.
47 lines (40 loc) • 960 B
JavaScript
/**
* WordPress dependencies
*/
import { store, withSyncEvent } from '@wordpress/interactivity';
const { state } = store( 'router', {
state: {
status: 'idle',
navigations: {
pending: 0,
count: 0,
},
timeout: 10000,
data: {
get getterProp() {
return `value from getter (${ state.data.prop1 })`;
},
},
},
actions: {
navigate: withSyncEvent( function* ( e ) {
e.preventDefault();
state.navigations.count += 1;
state.navigations.pending += 1;
state.status = 'busy';
const force = e.target.dataset.forceNavigation === 'true';
const { timeout } = state;
const { actions } = yield import(
'@wordpress/interactivity-router'
);
yield actions.navigate( e.target.href, { force, timeout } );
state.navigations.pending -= 1;
if ( state.navigations.pending === 0 ) {
state.status = 'idle';
}
} ),
toggleTimeout() {
state.timeout = state.timeout === 10000 ? 0 : 10000;
},
},
} );