@@ -31,21 +31,19 @@ function visitAndWait(width: number, height: number, options?: { page?: number }
3131 }
3232}
3333
34- const expectDesc = ( values : number [ ] ) =>
35- expect ( values , `values should be in descending order: ${ values . join ( ', ' ) } ` ) . to . deep . equal (
36- [ ...values ] . sort ( ( a , b ) => b - a ) ,
37- )
34+ type UsdValue = { text : string ; parsed : number }
3835
39- const expectAsc = ( values : number [ ] ) =>
40- expect ( values , `values should be in ascending order: ${ values . join ( ', ' ) } ` ) . to . deep . equal (
41- [ ... values ] . sort ( ( a , b ) => a - b ) ,
42- )
36+ const expectOrder = ( actual : UsdValue [ ] , order : 'asc' | 'desc' ) => {
37+ const expected = [ ... actual ] . sort ( ( a , b ) => ( a . parsed - b . parsed ) * { asc : 1 , desc : - 1 } [ order ] )
38+ expect ( JSON . stringify ( actual ) , `Table values should be in ${ order } order` ) . to . equal ( JSON . stringify ( expected ) )
39+ }
4340
4441const getTopUsdValues = ( columnId : 'volume' | 'tvl' , n = 5 ) =>
4542 cy . get ( `[data-testid="data-table-cell-${ columnId } "]` ) . then ( ( $cells ) =>
4643 Cypress . $ . makeArray ( $cells )
4744 . slice ( 0 , n )
48- . map ( ( el ) => parseCompactUsd ( ( el as HTMLElement ) . innerText ) ) ,
45+ . map ( ( el ) => ( el as HTMLElement ) . innerText )
46+ . map ( ( text ) : UsdValue => ( { text, parsed : parseCompactUsd ( text ) } ) ) ,
4947 )
5048
5149describe ( 'DEX Pools' , ( ) => {
@@ -61,7 +59,7 @@ describe('DEX Pools', () => {
6159 visitAndWait ( width , height )
6260 } )
6361
64- function sortBy ( field : string ) {
62+ function sortBy ( field : string , expectedOrder : 'asc' | 'desc' | false ) {
6563 if ( breakpoint === 'mobile' ) {
6664 cy . get ( '[data-testid="btn-drawer-sort-dex-pools"]' ) . click ( )
6765 cy . get ( `[data-testid="drawer-sort-menu-dex-pools"] li[value="${ field } "]` ) . click ( )
@@ -70,6 +68,11 @@ describe('DEX Pools', () => {
7068 cy . get ( `[data-testid="data-table-header-${ field } "]` ) . click ( )
7169 cy . get ( '[data-testid="drawer-sort-menu-dex-pools"]' ) . should ( 'not.exist' )
7270 }
71+ if ( expectedOrder ) {
72+ cy . get ( `[data-testid="icon-sort-${ field } -${ expectedOrder } "]` ) . should ( 'be.visible' )
73+ } else {
74+ cy . get ( `[data-testid^="icon-sort-${ field } "]` ) . should ( 'not.exist' )
75+ }
7376 }
7477
7578 function clickFilterChip ( chip : string , isMobile = breakpoint === 'mobile' ) {
@@ -82,22 +85,22 @@ describe('DEX Pools', () => {
8285 }
8386
8487 it ( 'sorts by volume' , ( ) => {
85- getTopUsdValues ( 'volume' ) . then ( ( vals ) => expectDesc ( vals ) ) // initial is Volume desc
88+ getTopUsdValues ( 'volume' ) . then ( ( vals ) => expectOrder ( vals , 'desc' ) ) // initial is Volume desc
8689 cy . url ( ) . should ( 'not.include' , 'volume' ) // initial sort not in URL
87- sortBy ( 'volume' )
88- cy . get ( '[data-testid="icon-sort- volume-desc"]' ) . should ( 'be.visible ')
89- getTopUsdValues ( 'volume' ) . then ( ( vals ) => expectAsc ( vals ) )
90+ if ( breakpoint === 'mobile' ) return // on mobile, we cannot sort ascending at the moment
91+ sortBy ( ' volume' , 'asc ')
92+ getTopUsdValues ( 'volume' ) . then ( ( vals ) => expectOrder ( vals , 'asc' ) )
9093 cy . url ( ) . should ( 'include' , 'sort=volume' )
9194 } )
9295
9396 it ( 'sorts by TVL (desc/asc)' , ( ) => {
9497 cy . url ( ) . should ( 'not.include' , 'tvl' ) // initial sort not in URL
95- sortBy ( 'tvl' )
96- getTopUsdValues ( 'tvl' ) . then ( ( vals ) => expectDesc ( vals ) )
98+ sortBy ( 'tvl' , 'desc' )
99+ getTopUsdValues ( 'tvl' ) . then ( ( vals ) => expectOrder ( vals , 'desc' ) )
97100 cy . url ( ) . should ( 'include' , 'sort=-tvl' )
98- cy . get ( '[data-testid="icon-sort-tvl-desc"]' ) . should ( 'be.visible' )
99- sortBy ( 'tvl' )
100- getTopUsdValues ( 'tvl' ) . then ( ( vals ) => expectAsc ( vals ) )
101+ if ( breakpoint === 'mobile' ) return // on mobile, we cannot sort ascending at the moment
102+ sortBy ( 'tvl' , 'asc' )
103+ getTopUsdValues ( 'tvl' ) . then ( ( vals ) => expectOrder ( vals , 'asc' ) )
101104 cy . url ( ) . should ( 'include' , 'sort=tvl' )
102105 } )
103106
0 commit comments