Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Fix JS Lint issues (#10866)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmanijak committed Sep 7, 2023
1 parent 95cc04f commit f656bf9
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 109 deletions.
25 changes: 16 additions & 9 deletions assets/js/base/context/hooks/cart/test/use-store-cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ describe( 'useStoreCart', () => {
useStoreCart( options );
return (
<div
results={ results }
receiveCart={ receiveCart }
receiveCartContents={ receiveCartContents }
data-results={ results }
data-receiveCart={ receiveCart }
data-receiveCartContents={ receiveCartContents }
/>
);
};
Expand Down Expand Up @@ -200,8 +200,11 @@ describe( 'useStoreCart', () => {
);
} );

const { results, receiveCart, receiveCartContents } =
renderer.root.findByType( 'div' ).props; //eslint-disable-line testing-library/await-async-query
const props = renderer.root.findByType( 'div' ).props; //eslint-disable-line testing-library/await-async-query
const results = props[ 'data-results' ];
const receiveCart = props[ 'data-receiveCart' ];
const receiveCartContents = props[ 'data-receiveCartContents' ];

const {
receiveCart: defaultReceiveCart,
receiveCartContents: defaultReceiveCartContents,
Expand All @@ -223,8 +226,10 @@ describe( 'useStoreCart', () => {
);
} );

const { results, receiveCart, receiveCartContents } =
renderer.root.findByType( 'div' ).props; //eslint-disable-line testing-library/await-async-query
const props = renderer.root.findByType( 'div' ).props; //eslint-disable-line testing-library/await-async-query
const results = props[ 'data-results' ];
const receiveCart = props[ 'data-receiveCart' ];
const receiveCartContents = props[ 'data-receiveCartContents' ];

expect( results ).toEqual( mockStoreCartData );
expect( receiveCart ).toBeUndefined();
Expand Down Expand Up @@ -255,8 +260,10 @@ describe( 'useStoreCart', () => {
);
} );

const { results, receiveCart, receiveCartContents } =
renderer.root.findByType( 'div' ).props; //eslint-disable-line testing-library/await-async-query
const props = renderer.root.findByType( 'div' ).props; //eslint-disable-line testing-library/await-async-query
const results = props[ 'data-results' ];
const receiveCart = props[ 'data-receiveCart' ];
const receiveCartContents = props[ 'data-receiveCartContents' ];

expect( results ).toEqual( previewCartData );
expect( receiveCart ).toEqual( receiveCartMock );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TestErrorBoundary extends ReactComponent {

render() {
if ( this.state.hasError ) {
return <div error={ this.state.error } />;
return <div data-error={ this.state.error } />;
}

return this.props.children;
Expand Down Expand Up @@ -100,7 +100,7 @@ describe( 'useCollection', () => {
} );
//eslint-disable-next-line testing-library/await-async-query
const props = renderer.root.findByType( 'div' ).props;
expect( props.error.message ).toMatch( /options object/ );
expect( props[ 'data-error' ].message ).toMatch( /options object/ );
expect( console ).toHaveErrored( /your React components:/ );
renderer.unmount();
}
Expand All @@ -122,7 +122,7 @@ describe( 'useCollection', () => {
} );
//eslint-disable-next-line testing-library/await-async-query
const props = renderer.root.findByType( 'div' ).props;
expect( props.error.message ).toMatch( /options object/ );
expect( props[ 'data-error' ].message ).toMatch( /options object/ );
expect( console ).toHaveErrored( /your React components:/ );
renderer.unmount();
}
Expand Down
7 changes: 5 additions & 2 deletions assets/js/base/context/hooks/test/use-query-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe( 'Testing Query State Hooks', () => {
const getProps = ( testRenderer ) => {
//eslint-disable-next-line testing-library/await-async-query
const props = testRenderer.root.findByType( 'div' ).props;
return [ props.queryState, props.setQueryState ];
return [ props[ 'data-queryState' ], props[ 'data-setQueryState' ] ];
};

/**
Expand Down Expand Up @@ -75,7 +75,10 @@ describe( 'Testing Query State Hooks', () => {
const args = propKeysForArgs.map( ( key ) => props[ key ] );
const [ queryValue, setQueryValue ] = hookTested( ...args );
return (
<div queryState={ queryValue } setQueryState={ setQueryValue } />
<div
data-queryState={ queryValue }
data-setQueryState={ setQueryValue }
/>
);
};

Expand Down
32 changes: 18 additions & 14 deletions assets/js/base/hocs/test/with-reviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ const defaultArgs = {
const TestComponent = withReviews( ( props ) => {
return (
<div
error={ props.error }
getReviews={ props.getReviews }
appendReviews={ props.appendReviews }
onChangeArgs={ props.onChangeArgs }
isLoading={ props.isLoading }
reviews={ props.reviews }
totalReviews={ props.totalReviews }
data-error={ props.error }
data-getReviews={ props.getReviews }
data-appendReviews={ props.appendReviews }
data-onChangeArgs={ props.onChangeArgs }
data-isLoading={ props.isLoading }
data-reviews={ props.reviews }
data-totalReviews={ props.totalReviews }
/>
);
} );
Expand Down Expand Up @@ -127,10 +127,14 @@ describe( 'withReviews Component', () => {
it( 'sets reviews based on API response', () => {
const props = renderer.root.findByType( 'div' ).props;

expect( props.error ).toBeNull();
expect( props.isLoading ).toBe( false );
expect( props.reviews ).toEqual( mockReviews.slice( 0, 2 ) );
expect( props.totalReviews ).toEqual( mockReviews.length );
expect( props[ 'data-error' ] ).toBeNull();
expect( props[ 'data-isLoading' ] ).toBe( false );
expect( props[ 'data-reviews' ] ).toEqual(
mockReviews.slice( 0, 2 )
);
expect( props[ 'data-totalReviews' ] ).toEqual(
mockReviews.length
);
} );
} );

Expand All @@ -155,9 +159,9 @@ describe( 'withReviews Component', () => {

expect( formatError ).toHaveBeenCalledWith( error );
expect( formatError ).toHaveBeenCalledTimes( 1 );
expect( props.error ).toEqual( formattedError );
expect( props.isLoading ).toBe( false );
expect( props.reviews ).toEqual( [] );
expect( props[ 'data-error' ] ).toEqual( formattedError );
expect( props[ 'data-isLoading' ] ).toBe( false );
expect( props[ 'data-reviews' ] ).toEqual( [] );
} );
} );
} );
28 changes: 17 additions & 11 deletions assets/js/base/hooks/test/use-previous.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import { usePrevious } from '../use-previous';
describe( 'usePrevious', () => {
const TestComponent = ( { testValue, validation } ) => {
const previousValue = usePrevious( testValue, validation );
return <div testValue={ testValue } previousValue={ previousValue } />;
return (
<div
data-testValue={ testValue }
data-previousValue={ previousValue }
/>
);
};

let renderer;
Expand All @@ -24,9 +29,10 @@ describe( 'usePrevious', () => {
act( () => {
renderer = TestRenderer.create( <TestComponent testValue={ 1 } /> );
} );
const testValue = renderer.root.findByType( 'div' ).props.testValue;
const testValue =
renderer.root.findByType( 'div' ).props[ 'data-testValue' ];
const testPreviousValue =
renderer.root.findByType( 'div' ).props.previousValue;
renderer.root.findByType( 'div' ).props[ 'data-previousValue' ];

expect( testValue ).toBe( 1 );
expect( testPreviousValue ).toBe( undefined );
Expand All @@ -42,18 +48,18 @@ describe( 'usePrevious', () => {
act( () => {
renderer.update( <TestComponent testValue={ 2 } /> );
} );
testValue = renderer.root.findByType( 'div' ).props.testValue;
testValue = renderer.root.findByType( 'div' ).props[ 'data-testValue' ];
testPreviousValue =
renderer.root.findByType( 'div' ).props.previousValue;
renderer.root.findByType( 'div' ).props[ 'data-previousValue' ];
expect( testValue ).toBe( 2 );
expect( testPreviousValue ).toBe( 1 );

act( () => {
renderer.update( <TestComponent testValue={ 3 } /> );
} );
testValue = renderer.root.findByType( 'div' ).props.testValue;
testValue = renderer.root.findByType( 'div' ).props[ 'data-testValue' ];
testPreviousValue =
renderer.root.findByType( 'div' ).props.previousValue;
renderer.root.findByType( 'div' ).props[ 'data-previousValue' ];
expect( testValue ).toBe( 3 );
expect( testPreviousValue ).toBe( 2 );
} );
Expand All @@ -72,9 +78,9 @@ describe( 'usePrevious', () => {
<TestComponent testValue="abc" validation={ Number.isFinite } />
);
} );
testValue = renderer.root.findByType( 'div' ).props.testValue;
testValue = renderer.root.findByType( 'div' ).props[ 'data-testValue' ];
testPreviousValue =
renderer.root.findByType( 'div' ).props.previousValue;
renderer.root.findByType( 'div' ).props[ 'data-previousValue' ];
expect( testValue ).toBe( 'abc' );
expect( testPreviousValue ).toBe( 1 );

Expand All @@ -83,9 +89,9 @@ describe( 'usePrevious', () => {
<TestComponent testValue={ 3 } validation={ Number.isFinite } />
);
} );
testValue = renderer.root.findByType( 'div' ).props.testValue;
testValue = renderer.root.findByType( 'div' ).props[ 'data-testValue' ];
testPreviousValue =
renderer.root.findByType( 'div' ).props.previousValue;
renderer.root.findByType( 'div' ).props[ 'data-previousValue' ];
expect( testValue ).toBe( 3 );
expect( testPreviousValue ).toBe( 1 );
} );
Expand Down
14 changes: 9 additions & 5 deletions assets/js/base/hooks/test/use-shallow-equal.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useShallowEqual } from '../use-shallow-equal';
describe( 'useShallowEqual', () => {
const TestComponent = ( { testValue } ) => {
const newValue = useShallowEqual( testValue );
return <div newValue={ newValue } />;
return <div data-newValue={ newValue } />;
};
let renderer;
beforeEach( () => ( renderer = null ) );
Expand All @@ -34,13 +34,15 @@ describe( 'useShallowEqual', () => {
<TestComponent testValue={ testValueA } />
);
} );
testPropValue = renderer.root.findByType( 'div' ).props.newValue;
testPropValue =
renderer.root.findByType( 'div' ).props[ 'data-newValue' ];
expect( testPropValue ).toBe( testValueA );
// do update
act( () => {
renderer.update( <TestComponent testValue={ testValueB } /> );
} );
testPropValue = renderer.root.findByType( 'div' ).props.newValue;
testPropValue =
renderer.root.findByType( 'div' ).props[ 'data-newValue' ];
expect( testPropValue ).toBe( testValueA );
}
);
Expand All @@ -62,13 +64,15 @@ describe( 'useShallowEqual', () => {
<TestComponent testValue={ testValueA } />
);
} );
testPropValue = renderer.root.findByType( 'div' ).props.newValue;
testPropValue =
renderer.root.findByType( 'div' ).props[ 'data-newValue' ];
expect( testPropValue ).toBe( testValueA );
// do update
act( () => {
renderer.update( <TestComponent testValue={ testValueB } /> );
} );
testPropValue = renderer.root.findByType( 'div' ).props.newValue;
testPropValue =
renderer.root.findByType( 'div' ).props[ 'data-newValue' ];
expect( testPropValue ).toBe( testValueB );
}
);
Expand Down
24 changes: 12 additions & 12 deletions assets/js/blocks/price-filter/test/use-price-constraints.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ describe( 'usePriceConstraints', () => {
const minPriceConstraint = usePriceConstraint( price, 2, ROUND_DOWN );
return (
<div
minPriceConstraint={ minPriceConstraint }
maxPriceConstraint={ maxPriceConstraint }
data-minPriceConstraint={ minPriceConstraint }
data-maxPriceConstraint={ maxPriceConstraint }
/>
);
};
Expand All @@ -30,11 +30,11 @@ describe( 'usePriceConstraints', () => {
);
const container = renderer.root.findByType( 'div' );

expect( container.props.maxPriceConstraint ).toBe( 1000 );
expect( container.props[ 'data-maxPriceConstraint' ] ).toBe( 1000 );

renderer.update( <TestComponent price={ 2000 } /> );

expect( container.props.maxPriceConstraint ).toBe( 2000 );
expect( container.props[ 'data-maxPriceConstraint' ] ).toBe( 2000 );
} );

it( 'min price constraint should be updated when new price is set', () => {
Expand All @@ -43,11 +43,11 @@ describe( 'usePriceConstraints', () => {
);
const container = renderer.root.findByType( 'div' );

expect( container.props.minPriceConstraint ).toBe( 1000 );
expect( container.props[ 'data-minPriceConstraint' ] ).toBe( 1000 );

renderer.update( <TestComponent price={ 2000 } /> );

expect( container.props.minPriceConstraint ).toBe( 2000 );
expect( container.props[ 'data-minPriceConstraint' ] ).toBe( 2000 );
} );

it( 'previous price constraint should be preserved when new price is not a infinite number', () => {
Expand All @@ -56,11 +56,11 @@ describe( 'usePriceConstraints', () => {
);
const container = renderer.root.findByType( 'div' );

expect( container.props.maxPriceConstraint ).toBe( 1000 );
expect( container.props[ 'data-maxPriceConstraint' ] ).toBe( 1000 );

renderer.update( <TestComponent price={ Infinity } /> );

expect( container.props.maxPriceConstraint ).toBe( 1000 );
expect( container.props[ 'data-maxPriceConstraint' ] ).toBe( 1000 );
} );

it( 'max price constraint should be higher if the price is decimal', () => {
Expand All @@ -69,21 +69,21 @@ describe( 'usePriceConstraints', () => {
);
const container = renderer.root.findByType( 'div' );

expect( container.props.maxPriceConstraint ).toBe( 2000 );
expect( container.props[ 'data-maxPriceConstraint' ] ).toBe( 2000 );

renderer.update( <TestComponent price={ 1999 } /> );

expect( container.props.maxPriceConstraint ).toBe( 2000 );
expect( container.props[ 'data-maxPriceConstraint' ] ).toBe( 2000 );
} );

it( 'min price constraint should be lower if the price is decimal', () => {
const renderer = TestRenderer.create( <TestComponent price={ 999 } /> );
const container = renderer.root.findByType( 'div' );

expect( container.props.minPriceConstraint ).toBe( 0 );
expect( container.props[ 'data-minPriceConstraint' ] ).toBe( 0 );

renderer.update( <TestComponent price={ 1999 } /> );

expect( container.props.minPriceConstraint ).toBe( 1000 );
expect( container.props[ 'data-minPriceConstraint' ] ).toBe( 1000 );
} );
} );
19 changes: 10 additions & 9 deletions assets/js/hocs/test/with-categories.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// We need to disable the following eslint check as it's only applicable
// to testing-library/react not `react-test-renderer` used here
/* eslint-disable testing-library/await-async-query */

/**
* External dependencies
*/
Expand Down Expand Up @@ -28,9 +29,9 @@ const mockCategories = [
const TestComponent = withCategories( ( props ) => {
return (
<div
error={ props.error }
isLoading={ props.isLoading }
categories={ props.categories }
data-error={ props.error }
data-isLoading={ props.isLoading }
data-categories={ props.categories }
/>
);
} );
Expand Down Expand Up @@ -69,9 +70,9 @@ describe( 'withCategories Component', () => {
it( 'sets the categories props', () => {
const props = renderer.root.findByType( 'div' ).props;

expect( props.error ).toBeNull();
expect( props.isLoading ).toBe( false );
expect( props.categories ).toEqual( mockCategories );
expect( props[ 'data-error' ] ).toBeNull();
expect( props[ 'data-isLoading' ] ).toBe( false );
expect( props[ 'data-categories' ] ).toEqual( mockCategories );
} );
} );

Expand All @@ -98,9 +99,9 @@ describe( 'withCategories Component', () => {

expect( formatError ).toHaveBeenCalledWith( error );
expect( formatError ).toHaveBeenCalledTimes( 1 );
expect( props.error ).toEqual( formattedError );
expect( props.isLoading ).toBe( false );
expect( props.categories ).toEqual( [] );
expect( props[ 'data-error' ] ).toEqual( formattedError );
expect( props[ 'data-isLoading' ] ).toBe( false );
expect( props[ 'data-categories' ] ).toEqual( [] );
} );
} );
} );
Loading

0 comments on commit f656bf9

Please sign in to comment.