2022-06-21 17:19:12 +05:30
import setWindowLocation from 'helpers/set_window_location_helper' ;
import { TEST _HOST } from 'helpers/test_constants' ;
2021-06-08 01:23:25 +05:30
import {
apiParams ,
apiParamsWithSpecialValues ,
filteredTokens ,
filteredTokensWithSpecialValues ,
locationSearch ,
locationSearchWithSpecialValues ,
urlParams ,
urlParamsWithSpecialValues ,
2022-03-02 08:16:31 +05:30
} from 'jest/issues/list/mock_data' ;
2023-05-27 22:25:52 +05:30
import { urlSortParams } from '~/issues/list/constants' ;
2021-06-08 01:23:25 +05:30
import {
2021-09-30 23:02:18 +05:30
convertToApiParams ,
2021-06-08 01:23:25 +05:30
convertToSearchQuery ,
2021-09-30 23:02:18 +05:30
convertToUrlParams ,
2021-06-08 01:23:25 +05:30
getFilterTokens ,
2021-10-27 15:23:28 +05:30
getInitialPageParams ,
2021-06-08 01:23:25 +05:30
getSortKey ,
getSortOptions ,
2022-04-04 11:22:00 +05:30
isSortKey ,
2022-03-02 08:16:31 +05:30
} from '~/issues/list/utils' ;
2022-07-16 23:28:13 +05:30
import { FILTERED _SEARCH _TERM } from '~/vue_shared/components/filtered_search_bar/constants' ;
2023-05-27 22:25:52 +05:30
import { DEFAULT _PAGE _SIZE } from '~/vue_shared/issuable/list/constants' ;
2021-06-08 01:23:25 +05:30
2021-10-27 15:23:28 +05:30
describe ( 'getInitialPageParams' , ( ) => {
2022-08-13 15:12:31 +05:30
it ( 'returns page params with a default page size when no arguments are given' , ( ) => {
2023-05-27 22:25:52 +05:30
expect ( getInitialPageParams ( ) ) . toEqual ( { firstPageSize : DEFAULT _PAGE _SIZE } ) ;
2022-08-13 15:12:31 +05:30
} ) ;
2022-07-23 23:45:48 +05:30
2022-08-13 15:12:31 +05:30
it ( 'returns page params with the given page size' , ( ) => {
const pageSize = 100 ;
expect ( getInitialPageParams ( pageSize ) ) . toEqual ( { firstPageSize : pageSize } ) ;
} ) ;
2022-05-07 20:08:51 +05:30
2022-08-13 15:12:31 +05:30
it ( 'does not return firstPageSize when lastPageSize is provided' , ( ) => {
const firstPageSize = 100 ;
const lastPageSize = 50 ;
const afterCursor = undefined ;
const beforeCursor = 'randomCursorString' ;
const pageParams = getInitialPageParams (
100 ,
firstPageSize ,
lastPageSize ,
afterCursor ,
beforeCursor ,
) ;
2022-07-23 23:45:48 +05:30
2022-08-13 15:12:31 +05:30
expect ( pageParams ) . toEqual ( { lastPageSize , beforeCursor } ) ;
} ) ;
2021-10-27 15:23:28 +05:30
} ) ;
2021-06-08 01:23:25 +05:30
describe ( 'getSortKey' , ( ) => {
it . each ( Object . keys ( urlSortParams ) ) ( 'returns %s given the correct inputs' , ( sortKey ) => {
2021-09-30 23:02:18 +05:30
const sort = urlSortParams [ sortKey ] ;
2021-06-08 01:23:25 +05:30
expect ( getSortKey ( sort ) ) . toBe ( sortKey ) ;
} ) ;
} ) ;
2022-04-04 11:22:00 +05:30
describe ( 'isSortKey' , ( ) => {
it . each ( Object . keys ( urlSortParams ) ) ( 'returns true given %s' , ( sort ) => {
expect ( isSortKey ( sort ) ) . toBe ( true ) ;
2021-06-08 01:23:25 +05:30
} ) ;
2022-04-04 11:22:00 +05:30
it . each ( [ '' , 'asdf' , null , undefined ] ) ( 'returns false given %s' , ( sort ) => {
expect ( isSortKey ( sort ) ) . toBe ( false ) ;
2021-06-08 01:23:25 +05:30
} ) ;
} ) ;
describe ( 'getSortOptions' , ( ) => {
describe . each `
2023-03-04 22:38:38 +05:30
hasIssuableHealthStatusFeature | hasIssueWeightsFeature | hasBlockedIssuesFeature | length | containsHealthStatus | containsWeight | containsBlocking
$ { false } | $ { false } | $ { false } | $ { 10 } | $ { false } | $ { false } | $ { false }
$ { false } | $ { false } | $ { true } | $ { 11 } | $ { false } | $ { false } | $ { true }
$ { false } | $ { true } | $ { false } | $ { 11 } | $ { false } | $ { true } | $ { false }
$ { false } | $ { true } | $ { true } | $ { 12 } | $ { false } | $ { true } | $ { true }
$ { true } | $ { false } | $ { false } | $ { 11 } | $ { true } | $ { false } | $ { false }
$ { true } | $ { false } | $ { true } | $ { 12 } | $ { true } | $ { false } | $ { true }
$ { true } | $ { true } | $ { false } | $ { 12 } | $ { true } | $ { true } | $ { false }
$ { true } | $ { true } | $ { true } | $ { 13 } | $ { true } | $ { true } | $ { true }
2021-06-08 01:23:25 +05:30
` (
2023-03-04 22:38:38 +05:30
'when hasIssuableHealthStatusFeature=$hasIssuableHealthStatusFeature, hasIssueWeightsFeature=$hasIssueWeightsFeature and hasBlockedIssuesFeature=$hasBlockedIssuesFeature' ,
2021-06-08 01:23:25 +05:30
( {
2023-03-04 22:38:38 +05:30
hasIssuableHealthStatusFeature ,
2021-06-08 01:23:25 +05:30
hasIssueWeightsFeature ,
hasBlockedIssuesFeature ,
length ,
2023-03-04 22:38:38 +05:30
containsHealthStatus ,
2021-06-08 01:23:25 +05:30
containsWeight ,
containsBlocking ,
} ) => {
2023-03-04 22:38:38 +05:30
const sortOptions = getSortOptions ( {
hasBlockedIssuesFeature ,
hasIssuableHealthStatusFeature ,
hasIssueWeightsFeature ,
} ) ;
2021-06-08 01:23:25 +05:30
it ( 'returns the correct length of sort options' , ( ) => {
expect ( sortOptions ) . toHaveLength ( length ) ;
} ) ;
2023-03-04 22:38:38 +05:30
it ( ` ${ containsHealthStatus ? 'contains' : 'does not contain' } health status option ` , ( ) => {
expect ( sortOptions . some ( ( option ) => option . title === 'Health' ) ) . toBe ( containsHealthStatus ) ;
} ) ;
2021-06-08 01:23:25 +05:30
it ( ` ${ containsWeight ? 'contains' : 'does not contain' } weight option ` , ( ) => {
expect ( sortOptions . some ( ( option ) => option . title === 'Weight' ) ) . toBe ( containsWeight ) ;
} ) ;
it ( ` ${ containsBlocking ? 'contains' : 'does not contain' } blocking option ` , ( ) => {
expect ( sortOptions . some ( ( option ) => option . title === 'Blocking' ) ) . toBe ( containsBlocking ) ;
} ) ;
} ,
) ;
} ) ;
describe ( 'getFilterTokens' , ( ) => {
it ( 'returns filtered tokens given "window.location.search"' , ( ) => {
expect ( getFilterTokens ( locationSearch ) ) . toEqual ( filteredTokens ) ;
} ) ;
it ( 'returns filtered tokens given "window.location.search" with special values' , ( ) => {
expect ( getFilterTokens ( locationSearchWithSpecialValues ) ) . toEqual (
filteredTokensWithSpecialValues ,
) ;
} ) ;
2022-07-16 23:28:13 +05:30
it . each `
description | argument
$ { 'an undefined value' } | $ { undefined }
$ { 'an irrelevant value' } | $ { '?unrecognised=parameter' }
` ('returns an empty filtered search term given $ description', ({ argument }) => {
expect ( getFilterTokens ( argument ) ) . toEqual ( [
{
id : expect . any ( String ) ,
type : FILTERED _SEARCH _TERM ,
value : { data : '' } ,
} ,
] ) ;
} ) ;
2021-06-08 01:23:25 +05:30
} ) ;
2021-09-30 23:02:18 +05:30
describe ( 'convertToApiParams' , ( ) => {
2022-06-21 17:19:12 +05:30
beforeEach ( ( ) => {
setWindowLocation ( TEST _HOST ) ;
} ) ;
2021-06-08 01:23:25 +05:30
it ( 'returns api params given filtered tokens' , ( ) => {
2021-09-30 23:02:18 +05:30
expect ( convertToApiParams ( filteredTokens ) ) . toEqual ( apiParams ) ;
2021-06-08 01:23:25 +05:30
} ) ;
it ( 'returns api params given filtered tokens with special values' , ( ) => {
2022-06-21 17:19:12 +05:30
setWindowLocation ( '?assignee_id=123' ) ;
2021-09-30 23:02:18 +05:30
expect ( convertToApiParams ( filteredTokensWithSpecialValues ) ) . toEqual ( apiParamsWithSpecialValues ) ;
2021-06-08 01:23:25 +05:30
} ) ;
2021-09-30 23:02:18 +05:30
} ) ;
2021-06-08 01:23:25 +05:30
2021-09-30 23:02:18 +05:30
describe ( 'convertToUrlParams' , ( ) => {
2022-06-21 17:19:12 +05:30
beforeEach ( ( ) => {
setWindowLocation ( TEST _HOST ) ;
} ) ;
2021-06-08 01:23:25 +05:30
it ( 'returns url params given filtered tokens' , ( ) => {
2021-09-30 23:02:18 +05:30
expect ( convertToUrlParams ( filteredTokens ) ) . toEqual ( urlParams ) ;
2021-06-08 01:23:25 +05:30
} ) ;
it ( 'returns url params given filtered tokens with special values' , ( ) => {
2022-06-21 17:19:12 +05:30
setWindowLocation ( '?assignee_id=123' ) ;
2021-09-30 23:02:18 +05:30
expect ( convertToUrlParams ( filteredTokensWithSpecialValues ) ) . toEqual ( urlParamsWithSpecialValues ) ;
2021-06-08 01:23:25 +05:30
} ) ;
} ) ;
describe ( 'convertToSearchQuery' , ( ) => {
it ( 'returns search string given filtered tokens' , ( ) => {
expect ( convertToSearchQuery ( filteredTokens ) ) . toBe ( 'find issues' ) ;
} ) ;
} ) ;