File size: 3,013 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
/**
* @jest-environment jsdom
*/
import { render } from '@testing-library/react';
import { MediaListData } from 'calypso/components/data/media-list-data';
/**
* Module variables
*/
const DUMMY_SITE_ID = 123456789;
const EMPTY_COMPONENT = () => {
return <div />;
};
describe( 'EditorMediaModal', () => {
test( 'should pass search parameter to media query', () => {
const setQuery = jest.fn();
const search = 'arbitrary-search-term';
render(
<MediaListData siteId={ DUMMY_SITE_ID } setQuery={ setQuery } search={ search }>
<EMPTY_COMPONENT />
</MediaListData>
);
expect( setQuery ).toHaveBeenCalledWith( DUMMY_SITE_ID, { search } );
} );
test( 'should pass and process filter parameter to media query', () => {
const setQuery = jest.fn();
render(
<MediaListData siteId={ DUMMY_SITE_ID } setQuery={ setQuery } filter="images">
<EMPTY_COMPONENT />
</MediaListData>
);
expect( setQuery ).toHaveBeenCalledWith( DUMMY_SITE_ID, { mime_type: 'image/' } );
} );
test( 'should pass and process filter parameter for google photos', () => {
const setQuery = jest.fn();
render(
<MediaListData
siteId={ DUMMY_SITE_ID }
setQuery={ setQuery }
filter="images"
source="google_photos"
>
<EMPTY_COMPONENT />
</MediaListData>
);
expect( setQuery ).toHaveBeenCalledWith( DUMMY_SITE_ID, {
source: 'google_photos',
path: 'recent',
filter: [ 'mediaType=photo' ],
} );
} );
test( 'should not pass and process filter parameter for pexels', () => {
const setQuery = jest.fn();
render(
<MediaListData siteId={ DUMMY_SITE_ID } setQuery={ setQuery } filter="images" source="pexels">
<EMPTY_COMPONENT />
</MediaListData>
);
expect( setQuery ).toHaveBeenCalledWith( DUMMY_SITE_ID, { source: 'pexels', path: 'recent' } );
} );
test( 'should pass source parameter and set recent path to media query', () => {
const setQuery = jest.fn();
render(
<MediaListData siteId={ DUMMY_SITE_ID } setQuery={ setQuery } source="anything">
<EMPTY_COMPONENT />
</MediaListData>
);
expect( setQuery ).toHaveBeenCalledWith( DUMMY_SITE_ID, {
path: 'recent',
source: 'anything',
} );
} );
test( 'should pass categoryFilter parameter to media query for Google Photos', () => {
const setQuery = jest.fn();
render(
<MediaListData
siteId={ DUMMY_SITE_ID }
setQuery={ setQuery }
categoryFilter="cats"
source="google_photos"
>
<EMPTY_COMPONENT />
</MediaListData>
);
expect( setQuery ).toHaveBeenCalledWith( DUMMY_SITE_ID, {
filter: [ 'categoryInclude=cats' ],
path: 'recent',
source: 'google_photos',
} );
} );
test( 'should not pass categoryFilter parameter to media query for other sources', () => {
const setQuery = jest.fn();
render(
<MediaListData siteId={ DUMMY_SITE_ID } setQuery={ setQuery } categoryFilter="cats">
<EMPTY_COMPONENT />
</MediaListData>
);
expect( setQuery ).toHaveBeenCalledWith( DUMMY_SITE_ID, {} );
} );
} );
|