403Webshell
Server IP : 104.21.14.103  /  Your IP : 18.117.7.212
Web Server : LiteSpeed
System : Linux business53.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64
User : giankuin ( 1871)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /proc/thread-self/root/home/giankuin/sieuthiweb.com.vn/wp-content/plugins/woocommerce/packages/woocommerce-blocks/assets/js/data/collections/test/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /proc/thread-self/root/home/giankuin/sieuthiweb.com.vn/wp-content/plugins/woocommerce/packages/woocommerce-blocks/assets/js/data/collections/test/selectors.js
/**
 * Internal dependencies
 */
import { getCollection, getCollectionHeader } from '../selectors';

const getHeaderMock = ( total ) => {
	const headers = { total };
	return {
		get: ( key ) => headers[ key ] || null,
		has: ( key ) => !! headers[ key ],
	};
};

const state = {
	'wc/blocks': {
		products: {
			'[]': {
				'?someQuery=2': {
					items: [ 'foo' ],
					headers: getHeaderMock( 22 ),
				},
			},
		},
		'products/attributes': {
			'[10]': {
				'?someQuery=2': {
					items: [ 'bar' ],
					headers: getHeaderMock( 42 ),
				},
			},
		},
		'products/attributes/terms': {
			'[10,20]': {
				'?someQuery=10': {
					items: [ 42 ],
					headers: getHeaderMock( 12 ),
				},
			},
		},
	},
};

describe( 'getCollection', () => {
	it( 'returns empty array when namespace does not exist in state', () => {
		expect( getCollection( state, 'invalid', 'products' ) ).toEqual( [] );
	} );
	it( 'returns empty array when resourceName does not exist in state', () => {
		expect( getCollection( state, 'wc/blocks', 'invalid' ) ).toEqual( [] );
	} );
	it( 'returns empty array when query does not exist in state', () => {
		expect( getCollection( state, 'wc/blocks', 'products' ) ).toEqual( [] );
	} );
	it( 'returns empty array when ids do not exist in state', () => {
		expect(
			getCollection(
				state,
				'wc/blocks',
				'products/attributes',
				'?someQuery=2',
				[ 20 ]
			)
		).toEqual( [] );
	} );
	describe( 'returns expected values for items existing in state', () => {
		test.each`
			resourceName                   | ids           | query                | expected
			${'products'}                  | ${[]}         | ${{ someQuery: 2 }}  | ${[ 'foo' ]}
			${'products/attributes'}       | ${[ 10 ]}     | ${{ someQuery: 2 }}  | ${[ 'bar' ]}
			${'products/attributes/terms'} | ${[ 10, 20 ]} | ${{ someQuery: 10 }} | ${[ 42 ]}
		`(
			'for "$resourceName", "$ids", and "$query"',
			( { resourceName, ids, query, expected } ) => {
				expect(
					getCollection(
						state,
						'wc/blocks',
						resourceName,
						query,
						ids
					)
				).toEqual( expected );
			}
		);
	} );
} );

describe( 'getCollectionHeader', () => {
	it(
		'returns undefined when there are headers but the specific header ' +
			'does not exist',
		() => {
			expect(
				getCollectionHeader(
					state,
					'invalid',
					'wc/blocks',
					'products',
					{
						someQuery: 2,
					}
				)
			).toBeUndefined();
		}
	);
	it( 'returns null when there are no headers for the given arguments', () => {
		expect( getCollectionHeader( state, 'wc/blocks', 'invalid' ) ).toBe(
			null
		);
	} );
	it( 'returns expected header when it exists', () => {
		expect(
			getCollectionHeader( state, 'total', 'wc/blocks', 'products', {
				someQuery: 2,
			} )
		).toBe( 22 );
	} );
} );

Youez - 2016 - github.com/yon3zu
LinuXploit