11import { fetchExtensionTemplates } from './fetch-template-specifications.js'
22import { ExtensionFlavorValue } from './extension.js'
33import { testDeveloperPlatformClient , testOrganizationApp } from '../../models/app/app.test-data.js'
4- import { ExtensionFlavor } from '../../models/app/template.js'
5- import { describe , expect , test , vi } from 'vitest'
6- import * as experimentModule from '@shopify/cli-kit/node/is-polaris-unified-enabled'
7-
8- vi . mock ( '@shopify/cli-kit/node/is-polaris-unified-enabled' , ( ) => ( {
9- isPolarisUnifiedEnabled : vi . fn ( ) . mockReturnValue ( false ) ,
10- } ) )
4+ import { describe , expect , test } from 'vitest'
115
126describe ( 'fetchTemplateSpecifications' , ( ) => {
137 test ( 'returns the remote specs' , async ( ) => {
@@ -34,12 +28,7 @@ describe('fetchTemplateSpecifications', () => {
3428 } )
3529
3630 describe ( 'ui_extension' , ( ) => {
37- const preactFlavor : ExtensionFlavor = {
38- name : 'Preact' ,
39- value : 'preact' as ExtensionFlavorValue ,
40- }
41-
42- const oldFlavors = [
31+ const allFlavors = [
4332 {
4433 name : 'JavaScript React' ,
4534 value : 'react' as ExtensionFlavorValue ,
@@ -60,8 +49,11 @@ describe('fetchTemplateSpecifications', () => {
6049 value : 'typescript' as ExtensionFlavorValue ,
6150 path : 'admin-action' ,
6251 } ,
52+ {
53+ name : 'Preact' ,
54+ value : 'preact' as ExtensionFlavorValue ,
55+ } ,
6356 ]
64- const allFlavors = [ ...oldFlavors , preactFlavor ]
6557
6658 async function getTemplates ( ) {
6759 const { templates} = await fetchExtensionTemplates (
@@ -90,86 +82,12 @@ describe('fetchTemplateSpecifications', () => {
9082 return templates
9183 }
9284
93- test ( 'returns only the preact flavor when POLARIS_UNIFIED is enabled' , async ( ) => {
94- // Given
95- vi . spyOn ( experimentModule , 'isPolarisUnifiedEnabled' ) . mockReturnValueOnce ( true )
96-
85+ test ( 'includes all flavors' , async ( ) => {
9786 // When
9887 const templates = await getTemplates ( )
9988
10089 // Then
101- expect ( templates [ 0 ] ! . supportedFlavors ) . toEqual ( [ preactFlavor ] )
102- } )
103-
104- test ( 'excludes the preact flavor by default' , async ( ) => {
105- // When
106- const templates = await getTemplates ( )
107-
108- // Then
109- expect ( templates [ 0 ] ! . supportedFlavors ) . toEqual ( oldFlavors )
110- } )
111-
112- test ( 'filter out templates that have no flavors available by default' , async ( ) => {
113- // When
114- const { templates} = await fetchExtensionTemplates (
115- testDeveloperPlatformClient ( {
116- templateSpecifications : ( ) =>
117- Promise . resolve ( {
118- templates : [
119- {
120- identifier : 'ui_extension' ,
121- name : 'UI Extension' ,
122- defaultName : 'ui-extension' ,
123- group : 'Merchant Admin' ,
124- supportLinks : [ ] ,
125- type : 'ui_extension' ,
126- url : 'https://github.com/Shopify/extensions-templates' ,
127- extensionPoints : [ ] ,
128- supportedFlavors : [ preactFlavor ] ,
129- } ,
130- ] ,
131- groupOrder : [ ] ,
132- } ) ,
133- } ) ,
134- testOrganizationApp ( ) ,
135- [ 'ui_extension' ] ,
136- )
137-
138- // Then
139- expect ( templates ) . toEqual ( [ ] )
140- } )
141-
142- test ( 'filter out templates that have no flavors available POLARIS_UNIFIED is enabled' , async ( ) => {
143- // Given
144- vi . spyOn ( experimentModule , 'isPolarisUnifiedEnabled' ) . mockReturnValueOnce ( true )
145-
146- // When
147- const { templates} = await fetchExtensionTemplates (
148- testDeveloperPlatformClient ( {
149- templateSpecifications : ( ) =>
150- Promise . resolve ( {
151- templates : [
152- {
153- identifier : 'ui_extension' ,
154- name : 'UI Extension' ,
155- defaultName : 'ui-extension' ,
156- group : 'Merchant Admin' ,
157- supportLinks : [ ] ,
158- type : 'ui_extension' ,
159- url : 'https://github.com/Shopify/extensions-templates' ,
160- extensionPoints : [ ] ,
161- supportedFlavors : oldFlavors ,
162- } ,
163- ] ,
164- groupOrder : [ ] ,
165- } ) ,
166- } ) ,
167- testOrganizationApp ( ) ,
168- [ 'ui_extension' ] ,
169- )
170-
171- // Then
172- expect ( templates ) . toEqual ( [ ] )
90+ expect ( templates [ 0 ] ! . supportedFlavors ) . toEqual ( allFlavors )
17391 } )
17492 } )
17593} )
0 commit comments