@@ -2,6 +2,7 @@ import type { Editor } from '../../../src';
22import EditorModel from '../../../src/editor/model/Editor' ;
33import type Commands from '../../../src/commands' ;
44import type { Command , CommandFunction , CommandOptions } from '../../../src/commands/view/CommandAbstract' ;
5+ import CommandAbstract from '../../../src/commands/view/CommandAbstract' ;
56
67describe ( 'Commands' , ( ) => {
78 describe ( 'Main' , ( ) => {
@@ -170,6 +171,48 @@ describe('Commands', () => {
170171 result = obj . run ( commName , customOptions ) ;
171172 expect ( result ) . toEqual ( { ...customOptions , ...defaultOptions } ) ;
172173 } ) ;
174+
175+ test ( 'Command constructor aliases keep independent ids and events' , ( ) => {
176+ class SharedCommand extends CommandAbstract {
177+ run ( ) {
178+ return commResultRun ;
179+ }
180+
181+ stop ( ) {
182+ return commResultStop ;
183+ }
184+ }
185+
186+ const runSpy = jest . fn ( ) ;
187+ const stopSpy = jest . fn ( ) ;
188+
189+ obj . add ( 'core:test' , SharedCommand ) ;
190+ obj . add ( 'test' , SharedCommand ) ;
191+
192+ expect ( obj . get ( 'core:test' ) ?. id ) . toBe ( 'core:test' ) ;
193+ expect ( obj . get ( 'test' ) ?. id ) . toBe ( 'test' ) ;
194+
195+ em . on ( 'command:run:core:test' , runSpy ) ;
196+ em . on ( 'command:stop:core:test' , stopSpy ) ;
197+
198+ obj . run ( 'core:test' ) ;
199+ expect ( obj . isActive ( 'core:test' ) ) . toBe ( true ) ;
200+ expect ( obj . isActive ( 'test' ) ) . toBe ( false ) ;
201+ expect ( runSpy ) . toHaveBeenCalledTimes ( 1 ) ;
202+
203+ obj . stop ( 'core:test' ) ;
204+ expect ( obj . isActive ( 'core:test' ) ) . toBe ( false ) ;
205+ expect ( stopSpy ) . toHaveBeenCalledTimes ( 1 ) ;
206+ } ) ;
207+
208+ test ( 'Default command aliases keep their registered ids' , ( ) => {
209+ expect ( obj . get ( 'core:preview' ) ?. id ) . toBe ( 'core:preview' ) ;
210+ expect ( obj . get ( 'preview' ) ?. id ) . toBe ( 'preview' ) ;
211+ expect ( obj . get ( 'core:fullscreen' ) ?. id ) . toBe ( 'core:fullscreen' ) ;
212+ expect ( obj . get ( 'fullscreen' ) ?. id ) . toBe ( 'fullscreen' ) ;
213+ expect ( obj . get ( 'core:component-outline' ) ?. id ) . toBe ( 'core:component-outline' ) ;
214+ expect ( obj . get ( 'sw-visibility' ) ?. id ) . toBe ( 'sw-visibility' ) ;
215+ } ) ;
173216 } ) ;
174217} ) ;
175218
0 commit comments