@@ -32,6 +32,7 @@ import {
3232import { AppHostAPI , AppHostServicesEntryPointName , AppHostServicesProvider } from '../src/appHostServices'
3333import { ConsoleHostLogger } from '../src/loggers'
3434import { createCircularEntryPoints , createDirectCircularEntryPoints } from './appHost.mock'
35+ import { createSignalItemsDataStructure } from './createSignalItemsDataStructure'
3536
3637const testHostOptions : AppHostOptions = {
3738 monitoring : { disableMonitoring : true }
@@ -1792,4 +1793,92 @@ If the API is intended to be public, it should be declared as "public: true" in
17921793 )
17931794 } )
17941795 } )
1796+
1797+ describe ( 'Custom Items Data Structure via AppHost Options (plugins)' , ( ) => {
1798+ it ( 'should use customCreateExtensionSlot from appHostOptions when contributing and removing items' , async ( ) => {
1799+ interface SlotItem {
1800+ value : string
1801+ }
1802+ const slotKey : SlotKey < SlotItem > = { name : 'host_options_signal_slot' }
1803+
1804+ interface SlotContributionAPI {
1805+ contributeItem ( fromShell : Shell , item : SlotItem ) : void
1806+ getItems ( ) : SlotItem [ ]
1807+ }
1808+ const SlotContributionAPIKey : SlotKey < SlotContributionAPI > = {
1809+ name : 'SLOT_CONTRIBUTION_API'
1810+ }
1811+
1812+ const itemsSpy = jest . fn ( )
1813+
1814+ const { createDataStructure, effect } = createSignalItemsDataStructure ( )
1815+
1816+ const slotOwnerEntryPoint : EntryPoint = {
1817+ name : 'SLOT_OWNER_ENTRY_POINT' ,
1818+ declareAPIs ( ) {
1819+ return [ SlotContributionAPIKey ]
1820+ } ,
1821+ attach ( shell : Shell ) {
1822+ const slot = shell . declareSlot ( slotKey )
1823+ shell . contributeAPI ( SlotContributionAPIKey , ( ) => ( {
1824+ contributeItem ( fromShell : Shell , item : SlotItem ) {
1825+ slot . contribute ( fromShell , item )
1826+ } ,
1827+ getItems ( ) {
1828+ return slot . getItems ( ) . map ( item => item . contribution )
1829+ }
1830+ } ) )
1831+ }
1832+ }
1833+
1834+ const ContributorEntryPoint : EntryPoint = {
1835+ name : 'CONTRIBUTOR_ENTRY_POINT' ,
1836+ getDependencyAPIs ( ) {
1837+ return [ SlotContributionAPIKey , ListenerAPI ]
1838+ } ,
1839+ extend ( shell : Shell ) {
1840+ const api = shell . getAPI ( SlotContributionAPIKey )
1841+ api . contributeItem ( shell , { value : 'item1' } )
1842+ api . contributeItem ( shell , { value : 'item2' } )
1843+ }
1844+ }
1845+
1846+ const ListenerAPI : SlotKey < { } > = { name : 'LISTENER_API' }
1847+
1848+ const ListenerEntryPoint : EntryPoint = {
1849+ name : 'LISTENER_ENTRY_POINT' ,
1850+ declareAPIs ( ) {
1851+ return [ ListenerAPI ]
1852+ } ,
1853+ getDependencyAPIs ( ) {
1854+ return [ SlotContributionAPIKey ]
1855+ } ,
1856+ // move to attach to make sure
1857+ attach ( shell : Shell ) {
1858+ const slotContributionAPI = shell . getAPI ( SlotContributionAPIKey )
1859+ effect ( ( ) => {
1860+ slotContributionAPI . getItems ( )
1861+ itemsSpy ( )
1862+ } )
1863+ // contribute an api to make sure that the contribution depends on it and happens after.
1864+ shell . contributeAPI ( ListenerAPI , ( ) => ( { } ) )
1865+ }
1866+ }
1867+
1868+ const host = createAppHost ( [ slotOwnerEntryPoint , ContributorEntryPoint , ListenerEntryPoint ] , {
1869+ monitoring : { } ,
1870+ plugins : {
1871+ extensionSlot : {
1872+ customCreateExtensionSlot : createDataStructure
1873+ }
1874+ }
1875+ } )
1876+
1877+ // first was created and then two time
1878+ expect ( itemsSpy ) . toBeCalledTimes ( 3 )
1879+
1880+ await host . removeShells ( [ ContributorEntryPoint . name ] )
1881+ expect ( itemsSpy ) . toBeCalledTimes ( 4 )
1882+ } )
1883+ } )
17951884} )
0 commit comments