@@ -5,103 +5,102 @@ import { Maybe } from '../utils/types';
55import { AbstractViewModel } from './abstract-view-model' ;
66import { ViewModel } from './view-model' ;
77
8- const createTestViewModel = ( {
8+ export class TestViewModelImpl extends AbstractViewModel < any , any > {
9+ spies = {
10+ mount : vi . fn ( ) ,
11+ unmount : vi . fn ( ) ,
12+ payloadChanged : vi . fn ( ) ,
13+ didMount : vi . fn ( ) ,
14+ didUnmount : vi . fn ( ) ,
15+ } ;
16+
17+ protected getParentViewModel (
18+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
19+ parentViewModelId : Maybe < string > ,
20+ ) : ViewModel < any , ViewModel < any , any > > | null {
21+ throw new Error ( 'Method not implemented.' ) ;
22+ }
23+
24+ didMount ( ) : void {
25+ this . spies . didMount ( ) ;
26+ }
27+
28+ mount ( ) : void {
29+ super . mount ( ) ;
30+ this . spies . mount ( ) ;
31+ }
32+
33+ unmount ( ) : void {
34+ super . unmount ( ) ;
35+ this . spies . unmount ( ) ;
36+ }
37+
38+ payloadChanged ( payload : any ) : void {
39+ this . spies . payloadChanged ( payload ) ;
40+ }
41+
42+ didUnmount ( ) : void {
43+ this . spies . didUnmount ( ) ;
44+ }
45+ }
46+ export const createTestViewModel = ( {
947 id = '1' ,
1048 payload = { } ,
1149} : {
1250 id ?: string ;
1351 payload ?: any ;
1452} = { } ) => {
15- class ViewModelImpl extends AbstractViewModel < any > {
16- spies = {
17- mount : vi . fn ( ) ,
18- unmount : vi . fn ( ) ,
19- payloadChanged : vi . fn ( ) ,
20- didMount : vi . fn ( ) ,
21- didUnmount : vi . fn ( ) ,
22- } ;
23-
24- protected getParentViewModel (
25- // eslint-disable-next-line @typescript-eslint/no-unused-vars
26- parentViewModelId : Maybe < string > ,
27- ) : ViewModel < any , ViewModel < any , any > > | null {
28- throw new Error ( 'Method not implemented.' ) ;
29- }
30-
31- didMount ( ) : void {
32- this . spies . didMount ( ) ;
33- }
34-
35- mount ( ) : void {
36- super . mount ( ) ;
37- this . spies . mount ( ) ;
38- }
39-
40- unmount ( ) : void {
41- super . unmount ( ) ;
42- this . spies . unmount ( ) ;
43- }
44-
45- payloadChanged ( payload : any ) : void {
46- this . spies . payloadChanged ( payload ) ;
47- }
48-
49- didUnmount ( ) : void {
50- this . spies . didUnmount ( ) ;
51- }
52- }
53-
54- const vm = new ViewModelImpl ( { id, payload } ) ;
53+ const vm = new TestViewModelImpl ( { id, payload } ) ;
5554
5655 return vm ;
5756} ;
5857
5958describe ( 'AbstractViewModel' , ( ) => {
6059 it ( 'create instance' , ( ) => {
61- const vm = createTestViewModel ( ) ;
60+ const vm = new TestViewModelImpl ( { id : '1' , payload : { } } ) ;
6261 expect ( vm ) . toBeDefined ( ) ;
6362 } ) ;
6463
6564 it ( 'has id' , ( ) => {
66- const vm = createTestViewModel ( { id : '1' } ) ;
65+ const vm = new TestViewModelImpl ( { id : '1' , payload : { } } ) ;
6766 expect ( vm . id ) . toBe ( '1' ) ;
6867 } ) ;
6968
7069 it ( 'has payload' , ( ) => {
71- const vm = createTestViewModel ( { payload : { test : 1 } } ) ;
70+ const vm = new TestViewModelImpl ( { id : '1' , payload : { test : 1 } } ) ;
7271 expect ( vm . payload ) . toEqual ( { test : 1 } ) ;
7372 } ) ;
7473
7574 it ( 'has isMounted' , ( ) => {
76- const vm = createTestViewModel ( ) ;
75+ const vm = new TestViewModelImpl ( { id : '1' , payload : { } } ) ;
7776 expect ( vm . isMounted ) . toBe ( false ) ;
7877 } ) ;
7978
8079 it ( 'has mount method' , ( ) => {
81- const vm = createTestViewModel ( ) ;
80+ const vm = new TestViewModelImpl ( { id : '1' , payload : { } } ) ;
8281 expect ( vm . mount ) . toBeDefined ( ) ;
8382 } ) ;
8483
8584 it ( 'has unmount method' , ( ) => {
86- const vm = createTestViewModel ( ) ;
85+ const vm = new TestViewModelImpl ( { id : '1' , payload : { } } ) ;
8786 expect ( vm . unmount ) . toBeDefined ( ) ;
8887 } ) ;
8988
9089 it ( 'has dispose' , ( ) => {
91- const vm = createTestViewModel ( ) ;
90+ const vm = new TestViewModelImpl ( { id : '1' , payload : { } } ) ;
9291 expect ( vm . dispose ) . toBeDefined ( ) ;
9392 } ) ;
9493
9594 it ( 'mount should be called once' , ( ) => {
96- const vm = createTestViewModel ( ) ;
95+ const vm = new TestViewModelImpl ( { id : '1' , payload : { } } ) ;
9796
9897 vm . mount ( ) ;
9998
10099 expect ( vm . spies . mount ) . toHaveBeenCalledOnce ( ) ;
101100 } ) ;
102101
103102 it ( 'didMount should be called after mount' , ( ) => {
104- const vm = createTestViewModel ( ) ;
103+ const vm = new TestViewModelImpl ( { id : '1' , payload : { } } ) ;
105104
106105 vm . mount ( ) ;
107106
0 commit comments