import { withLineUp , waitReady , LineUpJSType , LineUp } from './utils/lineup' ; import { generateData } from './utils/data' ; import { groupByString } from './utils/ui' ; describe ( 'restore_aggregation_state' , ( ) => { let lineup ; let lineUpJS ; let logs = [ ] ; function restoreLogs ( ) { const data = lineup . data ; logs . forEach ( ( log ) => { const ranking = data . getRankings ( ) [ log . ranking ] ; if ( Array . isArray ( log . group ) ) { const groups = ranking . getFlatGroups ( ) . filter ( ( d ) => log . group . includes ( d . name ) ) ; data . setTopNAggregated ( ranking , groups , log . current ) ; } else { const group = ranking . getFlatGroups ( ) . find ( ( d ) => d . name === log . group ) ; if ( group ) { data . setTopNAggregated ( ranking , group , log . current ) ; } } } ) ; } before ( withLineUp ( ( l , document ) => { lineUpJS = l ; const arr = generateData ( { cat : 2 , categories : [ 'c1' , 'c2' ] , count : 25 , missingString : 0.1 , } ) ; lineup = lineUpJS . builder ( arr ) . deriveColumns ( ) . deriveColors ( ) . animated ( false ) . build ( document . body ) ; lineup . data . on ( 'aggregate' , ( r , g , previous , current ) => { console . log ( 'on aggregate' , r , g , previous , current ) ; logs . push ( { ranking : lineup . data . getRankings ( ) . indexOf ( r ) , group : Array . isArray ( g ) ? g . map ( ( g ) => g . name ) : g . name , previous , current , } ) ; } ) ; waitReady ( lineup ) ; } ) ) ; beforeEach ( ( ) => { logs = [ ] ; } ) ; afterEach ( ( ) => { lineup . data . clearRankings ( ) ; lineup . data . deriveDefault ( ) ; } ) ; it ( 'build and restore' , ( ) => { const data = lineup . data ; groupByString ( ) ; cy . get ( '.lu-renderer-string.lu-group' ) . first ( ) . should ( ( el ) => expect ( el . text ( ) . trim ( ) ) . equal ( '' ) ) ; cy . get ( '.lu-renderer-string.lu-group' ) . eq ( 1 ) . should ( 'contain' , 'Row 0, Row 3' ) ; cy . get ( '.lu-renderer-string.lu-group' ) . last ( ) . should ( 'contain' , 'Row 2, Row 20' ) ; let old ; cy . get ( '.lu' ) . wait ( 200 ) . then ( ( ) => { const r = data . getFirstRanking ( ) ; old = r . getFlatGroups ( ) . map ( ( g ) => data . getAggregationState ( r , g ) ) ; data . clearRankings ( ) ; data . deriveDefault ( ) ; } ) ; groupByString ( false ) ; cy . get ( '.lu' ) . wait ( 200 ) . then ( ( ) => { console . log ( 'logs' , logs ) ; restoreLogs ( ) ; const r = data . getFirstRanking ( ) ; expect ( r . getFlatGroups ( ) . map ( ( g ) => data . getAggregationState ( r , g ) ) ) . to . members ( old ) ; } ) ; cy . get ( '.lu-renderer-string.lu-group' ) . first ( ) . should ( ( el ) => expect ( el . text ( ) . trim ( ) ) . equal ( '' ) ) ; cy . get ( '.lu-renderer-string.lu-group' ) . eq ( 1 ) . should ( 'contain' , 'Row 0, Row 3' ) ; cy . get ( '.lu-renderer-string.lu-group' ) . last ( ) . should ( 'contain' , 'Row 2, Row 20' ) ; } ) ; it ( 'build and restore multi' , ( ) => { cy . get ( '[data-type=categorical] .lu-action-group' ) . first ( ) . click ( ) ; cy . get ( 'body' ) . type ( '{ctrl}' , { release : false } ) ; cy . get ( '[data-type=categorical] .lu-action-group' ) . last ( ) . click ( { } ) ; cy . get ( 'body' ) . type ( '{ctrl}' ) ; cy . wait ( 100 ) . get ( '.lu-agg-level.lu-agg-expand' ) . first ( ) . click ( ) ; cy . get ( '.lu-renderer-string.lu-group' ) . first ( ) . should ( 'contain' , 'Row 4, Row 10' ) ; cy . wait ( 100 ) . get ( '.lu-agg-level.lu-agg-expand[data-level="0"]' ) . eq ( 1 ) . click ( ) ; cy . get ( '.lu-renderer-string.lu-group' ) . eq ( 1 ) . should ( 'contain' , 'Row 3, Row 8' ) ; const data = lineup . data ; let old ; cy . get ( '.lu' ) . then ( ( ) => { const r = data . getFirstRanking ( ) ; old = r . getFlatGroups ( ) . map ( ( g ) => data . getAggregationState ( r , g ) ) ; data . clearRankings ( ) ; data . deriveDefault ( ) ; } ) ; cy . wait ( 100 ) . get ( '[data-type=categorical] .lu-action-group' ) . first ( ) . click ( ) ; cy . get ( 'body' ) . type ( '{ctrl}' , { release : false } ) ; cy . get ( '[data-type=categorical] .lu-action-group' ) . last ( ) . click ( { } ) ; cy . get ( 'body' ) . type ( '{ctrl}' ) ; cy . get ( '.lu' ) . then ( ( ) => { restoreLogs ( ) ; const r = data . getFirstRanking ( ) ; expect ( r . getFlatGroups ( ) . map ( ( g ) => data . getAggregationState ( r , g ) ) ) . to . members ( old ) ; } ) ; cy . wait ( 100 ) . get ( '.lu-renderer-string.lu-group' ) . first ( ) . should ( 'contain' , 'Row 4, Row 10' ) ; cy . get ( '.lu-renderer-string.lu-group' ) . eq ( 1 ) . should ( 'contain' , 'Row 3, Row 8' ) ; } ) ; } ) ;