@@ -185,6 +185,24 @@ describe('Login', () => {
185185 cy . url ( ) . should ( 'eq' , 'http://127.0.0.1:3000/login' ) ;
186186 } ) ;
187187
188+ it ( 'should redirect to login page when navigating to a plugin then back to the plugin after login' , ( ) => {
189+ cy . visit ( '/plugin1' ) ;
190+
191+ cy . contains ( 'Sign in' ) . should ( 'be.visible' ) ;
192+
193+ cy . contains ( 'Username*' ) . parent ( ) . find ( 'input' ) . type ( ' username ' ) ;
194+ cy . contains ( 'Password*' ) . parent ( ) . find ( 'input' ) . type ( 'password' ) ;
195+
196+ cy . contains ( 'Username*' )
197+ . parent ( )
198+ . parent ( )
199+ . contains ( 'button' , 'Sign in' )
200+ . click ( ) ;
201+
202+ cy . url ( ) . should ( 'eq' , 'http://127.0.0.1:3000/plugin1' ) ;
203+ cy . get ( '#demo_plugin' ) . contains ( 'Demo Plugin' ) . should ( 'be.visible' ) ;
204+ } ) ;
205+
188206 it ( 'should not be logged in if invalid or unsigned token in localStorage' , ( ) => {
189207 // if token cannot be deciphered
190208 cy . contains ( 'Sign in' ) . should ( 'be.visible' ) ;
@@ -320,17 +338,19 @@ describe('Login', () => {
320338 ] ) ;
321339 cy . intercept ( 'POST' , '/login' , ( req ) => {
322340 req . reply ( loginResponse ) ;
323- } ) ;
341+ } ) . as ( 'login' ) ;
324342 cy . intercept ( 'POST' , '/verify' , ( req ) => {
325343 req . reply ( verifyResponse ) ;
326- } ) ;
344+ } ) . as ( 'verify' ) ;
327345 } ) ;
328346
329347 it ( 'should allow access to plugins and yet still show the Sign in button' , ( ) => {
330348 verifyResponse = verifySuccess ;
331349 loginResponse = loginSuccess ;
332350 cy . visit ( '/plugin1' ) ;
333351
352+ cy . wait ( '@login' ) ;
353+
334354 cy . get ( '#demo_plugin' ) . contains ( 'Demo Plugin' ) . should ( 'be.visible' ) ;
335355 cy . contains ( 'Sign in' ) . should ( 'be.visible' ) ;
336356
@@ -340,9 +360,13 @@ describe('Login', () => {
340360 cy . contains ( 'Sign in' ) . should ( 'be.visible' ) ;
341361
342362 // test that autologin works after token validation + refresh fail
343- verifyResponse = failure ;
363+ cy . window ( ) . then ( ( ) => {
364+ // use cy.window command just so that this line is async and executed at the right time
365+ verifyResponse = failure ;
366+ } ) ;
344367 cy . intercept ( 'POST' , '/refresh' , { statusCode : 403 } ) ;
345368 cy . reload ( ) ;
369+ cy . wait ( '@login' ) ;
346370 cy . get ( '#demo_plugin' ) . contains ( 'Demo Plugin' ) . should ( 'be.visible' ) ;
347371 cy . contains ( 'Sign in' ) . should ( 'be.visible' ) ;
348372 } ) ;
@@ -356,7 +380,10 @@ describe('Login', () => {
356380 cy . contains ( 'h1' , 'Sign in' ) . should ( 'be.visible' ) ;
357381
358382 // test that autologin fails after token validation + refresh fail
359- verifyResponse = failure ;
383+ cy . window ( ) . then ( ( ) => {
384+ // use cy.window command just so that this line is async and executed at the right time
385+ verifyResponse = failure ;
386+ } ) ;
360387 cy . intercept ( 'POST' , '/refresh' , { statusCode : 403 } ) ;
361388 cy . window ( ) . then ( ( $window ) =>
362389 $window . localStorage . setItem ( 'scigateway:token' , 'invalidtoken' )
@@ -374,6 +401,37 @@ describe('Login', () => {
374401 cy . get ( '#demo_plugin' ) . contains ( 'Demo Plugin' ) . should ( 'be.visible' ) ;
375402 } ) ;
376403
404+ it ( 'can remove toasts with esc keydown when a plugin error occurs' , ( ) => {
405+ cy . intercept ( '/settings.json' , {
406+ plugins : [
407+ {
408+ name : 'demo_plugin' ,
409+ src : '/plugins/main.js' ,
410+ enable : true ,
411+ location : 'main' ,
412+ } ,
413+ ] ,
414+ 'ui-strings' : 'res/default.json' ,
415+ 'auth-provider' : 'icat' ,
416+ authUrl : 'http://localhost:8000' ,
417+ autoLogin : true ,
418+ 'help-tour-steps' : [ ] ,
419+ } ) ;
420+ verifyResponse = verifySuccess ;
421+ loginResponse = loginSuccess ;
422+ cy . visit ( '/plugin1' ) ;
423+
424+ cy . contains (
425+ 'Failed to load plugin demo_plugin from /plugins/main.js.'
426+ ) . should ( 'exist' ) ;
427+
428+ cy . get ( 'body' ) . type ( '{esc}' ) ;
429+
430+ cy . contains (
431+ 'Failed to load plugin demo_plugin from /plugins/main.js.'
432+ ) . should ( 'not.exist' ) ;
433+ } ) ;
434+
377435 it ( 'should be able to switch authenticators and still be "auto logged in"' , ( ) => {
378436 verifyResponse = verifySuccess ;
379437 loginResponse = loginSuccess ;
@@ -421,6 +479,8 @@ describe('Login', () => {
421479 cy . contains ( 'Sign out' ) . click ( ) ;
422480
423481 cy . contains ( 'Sign in' ) . should ( 'be.visible' ) ;
482+ cy . wait ( '@login' ) ;
483+
424484 cy . contains ( 'a' , 'Demo Plugin' ) . should ( 'be.visible' ) ;
425485 cy . contains ( 'a' , 'Demo Plugin' ) . click ( ) ;
426486
0 commit comments