File size: 1,724 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 |
import getCommentsPage from 'calypso/state/selectors/get-comments-page';
const SITE_ID = 12345678;
const POST_ID = 1234;
describe( 'getCommentsPage()', () => {
const state = {
comments: {
ui: {
queries: {
[ SITE_ID ]: {
site: {
'all?order=DESC': { 1: [ 1, 2, 3, 4, 5 ] },
'trash?order=DESC': { 1: [] },
},
[ POST_ID ]: {
'all?order=DESC': { 1: [ 6, 7, 8, 9, 10 ] },
'spam?order=ASC&s=foo': { 2: [ 11, 12, 13, 14, 15 ] },
},
},
},
},
},
};
test( 'should return undefined if the state is not initialized for the requested filter', () => {
const commentsPage = getCommentsPage( state, SITE_ID, { page: 10, status: 'all' } );
expect( commentsPage ).toBeUndefined();
} );
test( 'should return an empty array if the state is empty for the requested filters', () => {
const commentsPage = getCommentsPage( state, SITE_ID, { page: 1, status: 'trash' } );
expect( commentsPage ).toEqual( [] );
} );
test( 'should return the first comments page of site view', () => {
const commentsPage = getCommentsPage( state, SITE_ID, {} );
expect( commentsPage ).toEqual( [ 1, 2, 3, 4, 5 ] );
} );
test( 'should return the first comments page of post view', () => {
const commentsPage = getCommentsPage( state, SITE_ID, {
page: 1,
postId: POST_ID,
status: 'all',
} );
expect( commentsPage ).toEqual( [ 6, 7, 8, 9, 10 ] );
} );
test( 'should return a comments page based on several filters', () => {
const commentsPage = getCommentsPage( state, SITE_ID, {
order: 'ASC',
page: 2,
postId: POST_ID,
search: 'foo',
status: 'spam',
} );
expect( commentsPage ).toEqual( [ 11, 12, 13, 14, 15 ] );
} );
} );
|