@@ -1027,6 +1027,98 @@ describe('Title automargining', function() {
10271027 } ) ;
10281028} ) ;
10291029
1030+ describe ( "Subtitle clearing via relayout" , function ( ) {
1031+ "use strict" ;
1032+
1033+ var data = [ { x : [ 1 , 2 , 3 ] , y : [ 1 , 2 , 3 ] } ] ;
1034+ var gd ;
1035+
1036+ beforeEach ( function ( ) {
1037+ gd = createGraphDiv ( ) ;
1038+ } ) ;
1039+
1040+ afterEach ( destroyGraphDiv ) ;
1041+
1042+ it ( "should properly clear subtitle when set to null" , function ( done ) {
1043+ Plotly . newPlot ( gd , data , {
1044+ title : {
1045+ text : "Main Title" ,
1046+ subtitle : { text : "Subtitle Text" } ,
1047+ } ,
1048+ } )
1049+ . then ( function ( ) {
1050+ var subtitleSel = d3Select ( ".gtitle-subtitle" ) ;
1051+ expect ( subtitleSel . empty ( ) ) . toBe (
1052+ false ,
1053+ "Subtitle should exist initially"
1054+ ) ;
1055+ expect ( subtitleSel . text ( ) ) . toBe ( "Subtitle Text" ) ;
1056+
1057+ return Plotly . relayout ( gd , { "title.subtitle.text" : null } ) ;
1058+ } )
1059+ . then ( function ( ) {
1060+ var subtitleSel = d3Select ( ".gtitle-subtitle" ) ;
1061+ expect ( subtitleSel . empty ( ) ) . toBe (
1062+ true ,
1063+ "Subtitle should be removed when set to null"
1064+ ) ;
1065+ } )
1066+ . then ( done , done . fail ) ;
1067+ } ) ;
1068+
1069+ it ( "should properly clear subtitle when set to empty string" , function ( done ) {
1070+ Plotly . newPlot ( gd , data , {
1071+ title : {
1072+ text : "Main Title" ,
1073+ subtitle : { text : "Subtitle Text" } ,
1074+ } ,
1075+ } )
1076+ . then ( function ( ) {
1077+ var subtitleSel = d3Select ( ".gtitle-subtitle" ) ;
1078+ expect ( subtitleSel . empty ( ) ) . toBe (
1079+ false ,
1080+ "Subtitle should exist initially"
1081+ ) ;
1082+
1083+ return Plotly . relayout ( gd , { "title.subtitle.text" : "" } ) ;
1084+ } )
1085+ . then ( function ( ) {
1086+ var subtitleSel = d3Select ( ".gtitle-subtitle" ) ;
1087+ expect ( subtitleSel . empty ( ) ) . toBe (
1088+ true ,
1089+ "Subtitle should be removed when set to empty string"
1090+ ) ;
1091+ } )
1092+ . then ( done , done . fail ) ;
1093+ } ) ;
1094+
1095+ it ( "should properly clear subtitle when set to whitespace" , function ( done ) {
1096+ Plotly . newPlot ( gd , data , {
1097+ title : {
1098+ text : "Main Title" ,
1099+ subtitle : { text : "Subtitle Text" } ,
1100+ } ,
1101+ } )
1102+ . then ( function ( ) {
1103+ var subtitleSel = d3Select ( ".gtitle-subtitle" ) ;
1104+ expect ( subtitleSel . empty ( ) ) . toBe (
1105+ false ,
1106+ "Subtitle should exist initially"
1107+ ) ;
1108+
1109+ return Plotly . relayout ( gd , { "title.subtitle.text" : " " } ) ;
1110+ } )
1111+ . then ( function ( ) {
1112+ var subtitleSel = d3Select ( ".gtitle-subtitle" ) ;
1113+ expect ( subtitleSel . empty ( ) ) . toBe (
1114+ true ,
1115+ "Subtitle should be removed when set to whitespace"
1116+ ) ;
1117+ } )
1118+ . then ( done , done . fail ) ;
1119+ } ) ;
1120+ } ) ;
1121+
10301122function expectTitle ( expTitle ) {
10311123 expectTitleFn ( expTitle ) ( ) ;
10321124}
0 commit comments