11import { calculatePrefixColumnSize , Dev } from './Dev.js'
22import { fetchAppPreviewMode } from '../../fetch.js'
33import { testDeveloperPlatformClient , testUIExtension } from '../../../../models/app/app.test-data.js'
4+ import { devSessionStatus } from '../../processes/dev-session.js'
45import {
56 getLastFrameAfterUnmount ,
67 render ,
@@ -12,14 +13,15 @@ import {
1213} from '@shopify/cli-kit/node/testing/ui'
1314import { AbortController , AbortSignal } from '@shopify/cli-kit/node/abort'
1415import React from 'react'
15- import { describe , expect , test , vi } from 'vitest'
16+ import { describe , expect , test , vi , beforeEach } from 'vitest'
1617import { unstyled } from '@shopify/cli-kit/node/output'
1718import { openURL } from '@shopify/cli-kit/node/system'
1819import { Writable } from 'stream'
1920
2021vi . mock ( '@shopify/cli-kit/node/system' )
2122vi . mock ( '../../../context.js' )
2223vi . mock ( '../../fetch.js' )
24+ vi . mock ( '../../processes/dev-session.js' )
2325
2426const developerPlatformClient = testDeveloperPlatformClient ( )
2527
@@ -40,6 +42,10 @@ const developerPreview = {
4042}
4143
4244describe ( 'Dev' , ( ) => {
45+ beforeEach ( ( ) => {
46+ vi . mocked ( devSessionStatus ) . mockReturnValue ( { isDevSessionReady : true } )
47+ } )
48+
4349 test ( 'renders a stream of concurrent outputs from sub-processes, shortcuts and a preview url' , async ( ) => {
4450 // Given
4551 let backendPromiseResolve : ( ) => void
@@ -968,6 +974,66 @@ describe('Dev', () => {
968974 // unmount so that polling is cleared after every test
969975 renderInstance . unmount ( )
970976 } )
977+
978+ test ( 'updates UI when devSessionEnabled changes from false to true' , async ( ) => {
979+ // Given
980+ vi . mocked ( devSessionStatus ) . mockReturnValue ( { isDevSessionReady : false } )
981+
982+ const renderInstance = render (
983+ < Dev
984+ processes = { [ ] }
985+ abortController = { new AbortController ( ) }
986+ previewUrl = "https://shopify.com"
987+ graphiqlUrl = "https://graphiql.shopify.com"
988+ graphiqlPort = { 1234 }
989+ app = { {
990+ ...testApp ,
991+ canEnablePreviewMode : false ,
992+ developerPlatformClient : {
993+ ...testDeveloperPlatformClient ( ) ,
994+ supportsDevSessions : true ,
995+ } ,
996+ } }
997+ developerPreview = { developerPreview }
998+ shopFqdn = "mystore.shopify.io"
999+ /> ,
1000+ )
1001+
1002+ // Initial state - dev session not ready
1003+ expect ( unstyled ( renderInstance . lastFrame ( ) ! ) . replace ( / \d / g, '0' ) ) . toMatchInlineSnapshot ( `
1004+ "
1005+ ────────────────────────────────────────────────────────────────────────────────────────────────────
1006+
1007+ › Press q │ quit
1008+
1009+ Preview URL: https://shopify.com
1010+ GraphiQL URL: http://localhost:0000/graphiql
1011+ "
1012+ ` )
1013+
1014+ // When dev session becomes ready
1015+ vi . mocked ( devSessionStatus ) . mockReturnValue ( { isDevSessionReady : true } )
1016+
1017+ // Wait for the polling interval to update the UI
1018+ await waitForContent ( renderInstance , 'preview in your browser' )
1019+
1020+ // Then - preview shortcut should be visible
1021+ expect ( unstyled ( renderInstance . lastFrame ( ) ! ) . replace ( / \d / g, '0' ) ) . toMatchInlineSnapshot ( `
1022+ "
1023+ ────────────────────────────────────────────────────────────────────────────────────────────────────
1024+
1025+ › Press g │ open GraphiQL (Admin API) in your browser
1026+ › Press p │ preview in your browser
1027+ › Press q │ quit
1028+
1029+ Preview URL: https://shopify.com
1030+ GraphiQL URL: http://localhost:0000/graphiql
1031+ "
1032+ ` )
1033+
1034+ // unmount so that polling is cleared after every test
1035+ renderInstance . unmount ( )
1036+ } )
9711037} )
9721038
9731039describe ( 'calculatePrefixColumnSize' , ( ) => {
0 commit comments