<commit_before>/**
 * External dependencies
 */
import { renderHook, act } from '@testing-library/react-hooks';

/**
 * Internal dependencies
 */
import useStoryReducer from '../useStoryReducer';

export function setupReducer() {
	const { result } = renderHook( () => useStoryReducer() );

	// convert each method to be wrapped in act and return the new state
	const wrapWithAct = ( methods ) => Object.keys( methods )
		.reduce(
			( obj, methodName ) => {
				const method = methods[ methodName ];
				const wrapped = ( parms ) => {
					act( () => method( parms ) );
					return result.current.state;
				};
				return {
					...obj,
					[ methodName ]: wrapped,
				};
			},
			{},
		);

	return wrapWithAct( {
		...result.current.api,
		...result.current.internal,
	} );
}

export function addRandomPage( { addPage } ) {
	const res = addPage( { id: getRandomId(), elements: [] } );
	console.log( 'res', res );
	return res;
}

export function addRandomPages( reducer, count ) {
	return Array.from( Array( count ) ).reduce( () => addRandomPage( reducer ), {} );
}

function getRandomId() {
	return `id-${ Math.floor( Math.random() * 1000000 ) }`;
}<commit_msg>Exit debug<commit_after>/**
 * External dependencies
 */
import { renderHook, act } from '@testing-library/react-hooks';

/**
 * Internal dependencies
 */
import useStoryReducer from '../useStoryReducer';

export function setupReducer() {
	const { result } = renderHook( () => useStoryReducer() );

	// convert each method to be wrapped in act and return the new state
	const wrapWithAct = ( methods ) => Object.keys( methods )
		.reduce(
			( obj, methodName ) => {
				const method = methods[ methodName ];
				const wrapped = ( parms ) => {
					act( () => method( parms ) );
					return result.current.state;
				};
				return {
					...obj,
					[ methodName ]: wrapped,
				};
			},
			{},
		);

	return wrapWithAct( {
		...result.current.api,
		...result.current.internal,
	} );
}
{'fraction_non_alphanumeric': 0.1619682214249103, 'fraction_numerical': 0.0035879036391594054, 'mean_word_length': 2.9918200408997957, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6986218', 'n_tokens_mistral': 709, 'n_tokens_neox': 600, 'n_words': 159}