@@ -243,7 +243,6 @@ export const SelectTemplateVersion: Story = {
243243export const OnError : Story = {
244244 decorators : [ withGlobalSnackbar ] ,
245245 beforeEach : ( ) => {
246- spyOn ( API , "getTemplates" ) . mockResolvedValue ( [ MockTemplate ] ) ;
247246 spyOn ( API , "getTemplate" ) . mockResolvedValue ( MockTemplate ) ;
248247 spyOn ( API . experimental , "getTasks" ) . mockResolvedValue ( MockTasks ) ;
249248 spyOn ( API . experimental , "createTask" ) . mockRejectedValue (
@@ -349,3 +348,62 @@ export const ExternalAuthError: Story = {
349348 } ) ;
350349 } ,
351350} ;
351+
352+ const tmplWithExternalAuth = {
353+ ...MockTemplateVersion ,
354+ id : "2" ,
355+ name : "With external" ,
356+ } ;
357+
358+ export const CheckExternalAuthOnChangingVersions : Story = {
359+ args : {
360+ templates : [
361+ {
362+ ...MockTemplate ,
363+ active_version_id : tmplWithExternalAuth . id ,
364+ } ,
365+ ] ,
366+ } ,
367+ beforeEach : ( ) => {
368+ spyOn ( API , "getTemplateVersions" ) . mockResolvedValue ( [
369+ {
370+ ...MockTemplateVersion ,
371+ id : "1" ,
372+ name : "No external" ,
373+ } ,
374+ tmplWithExternalAuth ,
375+ ] ) ;
376+ spyOn ( API , "getTemplateVersionExternalAuth" ) . mockImplementation (
377+ ( versionId : string ) => {
378+ return Promise . resolve (
379+ versionId === tmplWithExternalAuth . id
380+ ? [ MockTemplateVersionExternalAuthGithub ]
381+ : [ ] ,
382+ ) ;
383+ } ,
384+ ) ;
385+ } ,
386+ play : async ( { canvasElement, step } ) => {
387+ const canvas = within ( canvasElement ) ;
388+
389+ await step ( "Renders external authentication" , async ( ) => {
390+ await canvas . findByRole ( "button" , { name : / c o n n e c t t o g i t h u b / i } ) ;
391+ } ) ;
392+
393+ await step ( "Change into version without external auth" , async ( ) => {
394+ const body = within ( canvasElement . ownerDocument . body ) ;
395+ const versionSelect = await canvas . findByLabelText ( / t e m p l a t e v e r s i o n / i) ;
396+ await userEvent . click ( versionSelect ) ;
397+ const versionOption = await body . findByRole ( "option" , {
398+ name : / n o e x t e r n a l / i,
399+ } ) ;
400+ await userEvent . click ( versionOption ) ;
401+ } ) ;
402+
403+ await step ( "Don't render external authentication" , async ( ) => {
404+ expect (
405+ canvas . queryByRole ( "button" , { name : / c o n n e c t t o g i t h u b / i } ) ,
406+ ) . not . toBeInTheDocument ( ) ;
407+ } ) ;
408+ } ,
409+ } ;
0 commit comments