@@ -45,8 +45,15 @@ import {
4545 TemplatePlotsById
4646} from './plotDataStore'
4747import { setMaxNbPlotsPerRow } from './webviewSlice'
48- import { toggleDragAndDropMode as toggleTemplatePlotsDragAndDropMode } from './templatePlots/templatePlotsSlice'
49- import { toggleDragAndDropMode as toggleCustomPlotsDragAndDropMode } from './customPlots/customPlotsSlice'
48+ import {
49+ templatePlotsInitialState ,
50+ toggleDragAndDropMode as toggleTemplatePlotsDragAndDropMode
51+ } from './templatePlots/templatePlotsSlice'
52+ import {
53+ customPlotsInitialState ,
54+ toggleDragAndDropMode as toggleCustomPlotsDragAndDropMode
55+ } from './customPlots/customPlotsSlice'
56+ import { comparisonTableInitialState } from './comparisonTable/comparisonTableSlice'
5057import { plotsReducers , plotsStore } from '../store'
5158import { vsCodeApi } from '../../shared/api'
5259import {
@@ -700,42 +707,6 @@ describe('App', () => {
700707 expect ( screen . queryByText ( 'Images' ) ) . not . toBeInTheDocument ( )
701708 } )
702709
703- it ( 'should hide plots when their section is collapsed (setting to null can break some Vega plots)' , async ( ) => {
704- renderAppWithOptionalData ( {
705- custom : customPlotsFixture
706- } )
707-
708- const summaryElement = await screen . findByText ( 'Custom' )
709- const visiblePlots = await screen . findAllByLabelText ( 'Vega visualization' )
710- for ( const visiblePlot of visiblePlots ) {
711- expect ( visiblePlot ) . toBeInTheDocument ( )
712- expect ( visiblePlot ) . toBeVisible ( )
713- }
714-
715- fireEvent . click ( summaryElement , {
716- bubbles : true ,
717- cancelable : true
718- } )
719-
720- expect ( mockPostMessage ) . toHaveBeenCalledWith ( {
721- payload : { [ PlotsSection . CUSTOM_PLOTS ] : true } ,
722- type : MessageFromWebviewType . TOGGLE_PLOTS_SECTION
723- } )
724-
725- sendSetDataMessage ( {
726- sectionCollapsed : {
727- ...DEFAULT_SECTION_COLLAPSED ,
728- [ PlotsSection . CUSTOM_PLOTS ] : true
729- }
730- } )
731-
732- const hiddenPlots = await screen . findAllByLabelText ( 'Vega visualization' )
733- for ( const hiddenPlot of hiddenPlots ) {
734- expect ( hiddenPlot ) . toBeInTheDocument ( )
735- expect ( hiddenPlot ) . not . toBeVisible ( )
736- }
737- } )
738-
739710 it ( 'should not toggle the custom plots section when its header is clicked and its title is selected' , async ( ) => {
740711 renderAppWithOptionalData ( {
741712 custom : customPlotsFixture
@@ -851,6 +822,95 @@ describe('App', () => {
851822 } )
852823 } )
853824
825+ it ( 'should clear the template plots state when closing the section' , ( ) => {
826+ const store = renderAppWithOptionalData ( {
827+ template : templatePlotsFixture
828+ } )
829+
830+ const toggle = within (
831+ screen . getByTestId ( `${ PlotsSection . TEMPLATE_PLOTS } -section-details` )
832+ ) . getAllByRole ( 'button' ) [ 0 ]
833+ fireEvent . click ( toggle )
834+
835+ expect ( store . getState ( ) . template ) . toMatchObject ( templatePlotsInitialState )
836+ } )
837+
838+ it ( 'should clear the custom plots state when closing the section' , ( ) => {
839+ const store = renderAppWithOptionalData ( {
840+ custom : customPlotsFixture
841+ } )
842+
843+ const toggle = within (
844+ screen . getByTestId ( `${ PlotsSection . CUSTOM_PLOTS } -section-details` )
845+ ) . getAllByRole ( 'button' ) [ 0 ]
846+ fireEvent . click ( toggle )
847+
848+ expect ( store . getState ( ) . custom ) . toMatchObject ( customPlotsInitialState )
849+ } )
850+
851+ it ( 'should clear the comparison table state when closing the section' , ( ) => {
852+ const store = renderAppWithOptionalData ( {
853+ comparison : comparisonTableFixture
854+ } )
855+
856+ const toggle = within (
857+ screen . getByTestId ( `${ PlotsSection . COMPARISON_TABLE } -section-details` )
858+ ) . getAllByRole ( 'button' ) [ 0 ]
859+ fireEvent . click ( toggle )
860+
861+ expect ( store . getState ( ) . comparison ) . toMatchObject (
862+ comparisonTableInitialState
863+ )
864+ } )
865+
866+ it ( 'should send a message to refresh the template plots when closing the section' , ( ) => {
867+ renderAppWithOptionalData ( {
868+ template : templatePlotsFixture
869+ } )
870+
871+ const toggle = within (
872+ screen . getByTestId ( `${ PlotsSection . TEMPLATE_PLOTS } -section-details` )
873+ ) . getAllByRole ( 'button' ) [ 0 ]
874+ fireEvent . click ( toggle )
875+
876+ expect ( mockPostMessage ) . toHaveBeenCalledWith ( {
877+ payload : PlotsSection . TEMPLATE_PLOTS ,
878+ type : MessageFromWebviewType . REFRESH_PLOTS
879+ } )
880+ } )
881+
882+ it ( 'should send a message to refresh the custom plots when closing the section' , ( ) => {
883+ renderAppWithOptionalData ( {
884+ custom : customPlotsFixture
885+ } )
886+
887+ const toggle = within (
888+ screen . getByTestId ( `${ PlotsSection . CUSTOM_PLOTS } -section-details` )
889+ ) . getAllByRole ( 'button' ) [ 0 ]
890+ fireEvent . click ( toggle )
891+
892+ expect ( mockPostMessage ) . toHaveBeenCalledWith ( {
893+ payload : PlotsSection . CUSTOM_PLOTS ,
894+ type : MessageFromWebviewType . REFRESH_PLOTS
895+ } )
896+ } )
897+
898+ it ( 'should send a message to refresh the comparison table when closing the section' , ( ) => {
899+ renderAppWithOptionalData ( {
900+ comparison : comparisonTableFixture
901+ } )
902+
903+ const toggle = within (
904+ screen . getByTestId ( `${ PlotsSection . COMPARISON_TABLE } -section-details` )
905+ ) . getAllByRole ( 'button' ) [ 0 ]
906+ fireEvent . click ( toggle )
907+
908+ expect ( mockPostMessage ) . toHaveBeenCalledWith ( {
909+ payload : PlotsSection . COMPARISON_TABLE ,
910+ type : MessageFromWebviewType . REFRESH_PLOTS
911+ } )
912+ } )
913+
854914 it ( 'should display a slider to pick the number of items per row if there are items and the action is available' , ( ) => {
855915 const store = renderAppWithOptionalData ( {
856916 custom : customPlotsFixture
0 commit comments