initial commit

This commit is contained in:
2021-12-10 12:03:04 +00:00
commit c46c7ddbf0
3643 changed files with 582794 additions and 0 deletions

View File

@ -0,0 +1,136 @@
/**
* External dependencies
*/
import deepFreeze from 'deep-freeze';
/**
* Internal dependencies
*/
import queryStateReducer from '../reducers';
import { setQueryValue, setValueForQueryContext } from '../actions';
describe( 'queryStateReducer', () => {
const originalState = deepFreeze( {
contexta: JSON.stringify( {
foo: 'bar',
cheese: 'pizza',
} ),
} );
it(
'returns original state when the action is not of the type being ' +
'processed',
() => {
expect(
queryStateReducer( originalState, { type: 'invalid' } )
).toBe( originalState );
}
);
describe( 'SET_QUERY_KEY_VALUE action', () => {
it(
'returns original state when incoming query-state key value ' +
'matches what is already in the state',
() => {
expect(
queryStateReducer(
originalState,
setQueryValue( 'contexta', 'foo', 'bar' )
)
).toBe( originalState );
}
);
it(
'returns new state when incoming query-state key exist ' +
'but the value is a new value',
() => {
const newState = queryStateReducer(
originalState,
setQueryValue( 'contexta', 'foo', 'zed' )
);
expect( newState ).not.toBe( originalState );
expect( newState ).toEqual( {
contexta: JSON.stringify( {
foo: 'zed',
cheese: 'pizza',
} ),
} );
}
);
it(
'returns new state when incoming query-state key does not ' +
'exist',
() => {
const newState = queryStateReducer(
originalState,
setQueryValue( 'contexta', 'burger', 'pizza' )
);
expect( newState ).not.toBe( originalState );
expect( newState ).toEqual( {
contexta: JSON.stringify( {
foo: 'bar',
cheese: 'pizza',
burger: 'pizza',
} ),
} );
}
);
} );
describe( 'SET_QUERY_CONTEXT_VALUE action', () => {
it(
'returns original state when incoming context value matches ' +
'what is already in the state',
() => {
expect(
queryStateReducer(
originalState,
setValueForQueryContext( 'contexta', {
foo: 'bar',
cheese: 'pizza',
} )
)
).toBe( originalState );
}
);
it(
'returns new state when incoming context value is different ' +
'than what is already in the state',
() => {
const newState = queryStateReducer(
originalState,
setValueForQueryContext( 'contexta', {
bar: 'foo',
pizza: 'cheese',
} )
);
expect( newState ).not.toBe( originalState );
expect( newState ).toEqual( {
contexta: JSON.stringify( {
bar: 'foo',
pizza: 'cheese',
} ),
} );
}
);
it(
'returns new state when incoming context does not exist in the ' +
'state',
() => {
const newState = queryStateReducer(
originalState,
setValueForQueryContext( 'contextb', {
foo: 'bar',
} )
);
expect( newState ).not.toBe( originalState );
expect( newState ).toEqual( {
contexta: JSON.stringify( {
foo: 'bar',
cheese: 'pizza',
} ),
contextb: JSON.stringify( {
foo: 'bar',
} ),
} );
}
);
} );
} );

View File

@ -0,0 +1,63 @@
/**
* External dependencies
*/
import deepFreeze from 'deep-freeze';
/**
* Internal dependencies
*/
import { getValueForQueryKey, getValueForQueryContext } from '../selectors';
const testState = deepFreeze( {
contexta: JSON.stringify( {
foo: 'bar',
cheese: 'pizza',
} ),
} );
describe( 'getValueForQueryKey', () => {
it(
'returns provided default value when there is no state for the ' +
'given context',
() => {
expect(
getValueForQueryKey( testState, 'invalid', 'foo', 42 )
).toBe( 42 );
}
);
it(
'returns provided default value when there is no value for the ' +
'given context and queryKey',
() => {
expect(
getValueForQueryKey( testState, 'contexta', 'pizza', 42 )
).toBe( 42 );
}
);
it( 'returns expected value when context and queryKey exist', () => {
expect( getValueForQueryKey( testState, 'contexta', 'foo', 42 ) ).toBe(
'bar'
);
} );
} );
describe( 'getValueForQueryContext', () => {
it(
'returns provided default value when there is no state for the ' +
'given context',
() => {
expect( getValueForQueryContext( testState, 'invalid', 42 ) ).toBe(
42
);
}
);
it(
'returns expected value when selecting a context that exists in ' +
'state',
() => {
expect(
getValueForQueryContext( testState, 'contexta', 42 )
).toEqual( JSON.parse( testState.contexta ) );
}
);
} );