@@ -520,45 +520,73 @@ describe('config argument', function() {
520520 } ) ;
521521
522522 describe ( 'plotlyServerURL:' , function ( ) {
523- let gd ;
523+ var gd ;
524+ var form ;
525+
526+ beforeEach ( function ( ) {
527+ gd = createGraphDiv ( ) ;
528+ spyOn ( HTMLFormElement . prototype , 'submit' ) . and . callFake ( function ( ) {
529+ form = this ;
530+ } ) ;
531+ } ) ;
524532
525- beforeEach ( ( ) => { gd = createGraphDiv ( ) ; } ) ;
526533 afterEach ( destroyGraphDiv ) ;
527534
528- it ( 'should default to an empty string' , async ( ) => {
529- await Plotly . newPlot ( gd , [ ] , { } ) ;
530- expect ( gd . _context . plotlyServerURL ) . toBe ( '' ) ;
531- } ) ;
535+ it ( 'should not default to an external plotly cloud' , function ( done ) {
536+ Plotly . newPlot ( gd , [ ] , { } )
537+ . then ( function ( ) {
538+ expect ( gd . _context . plotlyServerURL ) . not . toBe ( 'https://plot.ly' ) ;
539+ expect ( gd . _context . plotlyServerURL ) . not . toBe ( 'https://chart-studio.plotly.com' ) ;
540+ expect ( gd . _context . plotlyServerURL ) . toBe ( '' ) ;
532541
533- it ( 'can be configured via the config argument' , async ( ) => {
534- await Plotly . newPlot ( gd , [ ] , { } , { plotlyServerURL : 'https://cloud.plotly.com' } ) ;
535- expect ( gd . _context . plotlyServerURL ) . toBe ( 'https://cloud.plotly.com' ) ;
542+ Plotly . Plots . sendDataToCloud ( gd ) ;
543+ expect ( form ) . toBe ( undefined ) ;
544+ } )
545+ . then ( done , done . fail ) ;
536546 } ) ;
537- } ) ;
538547
539- describe ( 'Plotly.Plots.sendDataToCloud' , function ( ) {
540- let gd ;
541- let openSpy ;
548+ it ( 'should be able to connect to Chart Studio Cloud when set to https://chart-studio.plotly.com' , function ( done ) {
549+ Plotly . newPlot ( gd , [ ] , { } , {
550+ plotlyServerURL : 'https://chart-studio.plotly.com'
551+ } )
552+ . then ( function ( ) {
553+ expect ( gd . _context . plotlyServerURL ) . toBe ( 'https://chart-studio.plotly.com' ) ;
542554
543- beforeEach ( ( ) => {
544- gd = createGraphDiv ( ) ;
545- openSpy = spyOn ( window , 'open' ) . and . returnValue ( { postMessage : ( ) => { } } ) ;
555+ Plotly . Plots . sendDataToCloud ( gd ) ;
556+ expect ( form . action ) . toBe ( 'https://chart-studio.plotly.com/external' ) ;
557+ expect ( form . method ) . toBe ( 'post' ) ;
558+ } )
559+ . then ( done , done . fail ) ;
546560 } ) ;
547- afterEach ( destroyGraphDiv ) ;
548561
549- it ( 'opens the given serverURL in a new tab' , async ( ) => {
550- await Plotly . newPlot ( gd , [ ] , { } ) ;
551- Plotly . Plots . sendDataToCloud ( gd , 'https://cloud.plotly.com' ) ;
552- expect ( openSpy ) . toHaveBeenCalledWith ( 'https://cloud.plotly.com' , '_blank' ) ;
562+ it ( 'can be set to other base urls' , function ( done ) {
563+ Plotly . newPlot ( gd , [ ] , { } , { plotlyServerURL : 'dummy' } )
564+ . then ( function ( ) {
565+ expect ( gd . _context . plotlyServerURL ) . toBe ( 'dummy' ) ;
566+
567+ Plotly . Plots . sendDataToCloud ( gd ) ;
568+ expect ( form . action ) . toContain ( '/dummy/external' ) ;
569+ expect ( form . method ) . toBe ( 'post' ) ;
570+ } )
571+ . then ( done , done . fail ) ;
553572 } ) ;
554573
555- it ( 'emits plotly_exportfail when the popup is blocked' , async ( ) => {
556- openSpy . and . returnValue ( null ) ;
557- let failed = false ;
558- await Plotly . newPlot ( gd , [ ] , { } ) ;
559- gd . on ( 'plotly_exportfail' , ( ) => { failed = true ; } ) ;
560- Plotly . Plots . sendDataToCloud ( gd , 'https://cloud.plotly.com' ) ;
561- expect ( failed ) . toBe ( true ) ;
574+ it ( 'has lesser priotiy then window env' , function ( done ) {
575+ window . PLOTLYENV = { BASE_URL : 'yo' } ;
576+
577+ Plotly . newPlot ( gd , [ ] , { } , { plotlyServerURL : 'dummy' } )
578+ . then ( function ( ) {
579+ expect ( gd . _context . plotlyServerURL ) . toBe ( 'dummy' ) ;
580+
581+ Plotly . Plots . sendDataToCloud ( gd ) ;
582+ expect ( form . action ) . toContain ( '/yo/external' ) ;
583+ expect ( form . method ) . toBe ( 'post' ) ;
584+ } )
585+ . catch ( failTest )
586+ . then ( function ( ) {
587+ delete window . PLOTLY_ENV ;
588+ done ( ) ;
589+ } ) ;
562590 } ) ;
563591 } ) ;
564592
0 commit comments