summaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/drawingBoard/service-planning/drawing-board-header/drawing-board-header.service.spec.ts
blob: 76fc28a9e528bae4021fc423978c7ecf9b891a4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
import {getTestBed, TestBed} from '@angular/core/testing';
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
import {DefaultDataGeneratorService} from "../../../shared/services/defaultDataServiceGenerator/default.data.generator.service";
import {MockNgRedux, NgReduxTestingModule} from "@angular-redux/store/testing";
import {DrawingBoardHeaderService} from "./drawing-board-header.service";
import {ActivatedRoute} from '@angular/router';
import {ServiceInstanceActions} from "../../../shared/models/serviceInstanceActions";
import {AppState} from "../../../shared/store/reducers";
import {NgRedux} from "@angular-redux/store";
import {addServiceAction} from "../../../shared/storeUtil/utils/service/service.actions";
import {ErrorMsgService} from "../../../shared/components/error-msg/error-msg.service";
import {DrawingBoardModes} from "../drawing-board.modes";
import each from "jest-each";

class MockAppStore<T>{
  getState()  {
    return {
      service : {
        serviceInstance : {
          "serviceInstanceId" : {
            action: 'None'
          }
        }
      }
    }
  }
}

describe('Generate path to old View/Edit ', () => {
  let injector;
  let service: DrawingBoardHeaderService;
  let httpMock: HttpTestingController;
  let store :  NgRedux<AppState>;

  beforeAll(done => (async () => {
    TestBed.configureTestingModule({
      imports: [HttpClientTestingModule, NgReduxTestingModule],
      providers: [
        DrawingBoardHeaderService,
        DefaultDataGeneratorService,
        MockNgRedux,
        ErrorMsgService,
        {
          provide: ActivatedRoute,
          useValue: {
            snapshot : {
              queryParams:{
                'subscriberId' : 'subscriberId',
                'subscriberName' : 'subscriberName',
                'serviceType' : 'serviceType',
                'serviceInstanceId' : 'serviceInstanceId'
              }
            }
          },
        }]
    });
    await TestBed.compileComponents();

    injector = getTestBed();
    service = injector.get(DrawingBoardHeaderService);
    httpMock = injector.get(HttpTestingController);
    store = injector.get(NgRedux);

  })().then(done).catch(done.fail));


  test('should generate url to old view/edit ', () => {
    const query: string = 'subscriberId=subscriberId&subscriberName=subscriberName&serviceType=serviceType&serviceInstanceId=serviceInstanceId';
    const path =  '../../serviceModels.htm#/instantiate?' + query;
    let result = service.generateOldViewEditPath();
   expect(result).toEqual(path);
  });

  test('should call update action for Delete',()=>{

    jest.spyOn(store, 'dispatch');
    service.deleteService("serviceInstanceId", true);
    expect(store.dispatch).toHaveBeenCalledWith(addServiceAction("serviceInstanceId", ServiceInstanceActions.Delete));
  });

  test('should call update action for undo delete',()=>{
    jest.spyOn(store, 'dispatch');
    service.deleteService("serviceInstanceId", false);
    expect(store.dispatch).toHaveBeenCalledWith(addServiceAction("serviceInstanceId", ServiceInstanceActions.None));
  });

  test('deployShouldBeDisabled with validationCounter greater then 0',()=>{
    jest.spyOn(store, 'getState').mockReturnValue(<any>{
      service: {
        serviceInstance : {
          'serviceInstanceId' : {
            validationCounter : 1
          }
        }
      }
    });
    let result = service.deployShouldBeDisabled("serviceInstanceId", DrawingBoardModes.RETRY_EDIT);
    expect(result).toBeTruthy();
  });

  test('deployShouldBeDisabled with validationCounter is 0 and not dirty',()=>{
    jest.spyOn(store, 'getState').mockReturnValue(<any>{
      service: {
        serviceInstance : {
          'serviceInstanceId' : {
            validationCounter : 0,
            isDirty : false
          }
        }
      }
    });
    let result = service.deployShouldBeDisabled("serviceInstanceId", DrawingBoardModes.RETRY_EDIT);
    expect(result).toBeFalsy();
  });

  test('deployShouldBeDisabled with validationCounter is 0 and dirty',()=>{
    jest.spyOn(store, 'getState').mockReturnValue(<any>{
      service: {
        serviceInstance : {
          'serviceInstanceId' : {
            validationCounter : 0,
            action : 'None',
            isDirty : true
          }
        }
      }
    });
    let result = service.deployShouldBeDisabled("serviceInstanceId", DrawingBoardModes.RETRY_EDIT);
    expect(result).not.toBeTruthy();
  });

  test('deployShouldBeDisabled with validationCounter is 0 and not and action is None and dirty',()=>{
    jest.spyOn(store, 'getState').mockReturnValue(<any>{
      service: {
        serviceInstance : {
          'serviceInstanceId' : {
            validationCounter : 0,
            action : ServiceInstanceActions.None,
            isDirty : true
          }
        }
      }
    });
    let result = service.deployShouldBeDisabled("serviceInstanceId", DrawingBoardModes.RETRY_EDIT);
    expect(result).not.toBeTruthy();
  });


  test('getModeButton',()=>{
    let result : string = service.getModeButton("EDIT");
    expect(result).toEqual('UPDATE');

    result  = service.getModeButton("");
    expect(result).toEqual('DEPLOY');

    result  = service.getModeButton("RETRY_EDIT");
    expect(result).toEqual('REDEPLOY');
  });
  test('getButtonText',()=>{
    expect(service.getButtonText(DrawingBoardModes.VIEW)).toEqual('EDIT');
    expect(service.getButtonText(DrawingBoardModes.RETRY)).toEqual('REDEPLOY');

  });
  const showEditServiceDataProvider = [
    ['Create action CREATE mode', DrawingBoardModes.CREATE ,ServiceInstanceActions.Create, true],
    ['Create action RETRY_EDIT mode',DrawingBoardModes.RETRY_EDIT,  ServiceInstanceActions.Create,  true],
    ['Create action EDIT mode',DrawingBoardModes.EDIT, ServiceInstanceActions.Create,  true],
    ['Create action RETRY mode',DrawingBoardModes.RETRY, ServiceInstanceActions.Create,  false],
    ['None action EDIT mode',DrawingBoardModes.EDIT,  ServiceInstanceActions.None, false],
    ['None action RETRY_EDIT mode', DrawingBoardModes.RETRY_EDIT, ServiceInstanceActions.None, false]];
  each(showEditServiceDataProvider).test('showEditService service with %s', (description, mode, action, enabled) => {
    jest.spyOn(store, 'getState').mockReturnValue(<any>{
      service: {
        serviceInstance : {
          'serviceInstanceId' : {
            action : action
          }
        }
      }
    });
    expect(service.showEditService(mode, 'serviceInstanceId')).toBe(enabled);

  });

  const showResumeServiceDataProvider = [
    ['all conditions of resume- should show resume',true, 'MACRO', 'VPE', 'AssiGNed', true],
    ['flag is disabled- should not show resume ',false, 'MACRO', 'VPE', 'AssiGNed', false],
    ['transport service (PNF)- should not show resume', true, 'Macro', 'transport', 'Assigned', false],
    ['instantiationType is a-la-carte- should not show resume', true, 'ALaCarte', 'VPE', 'Assigned', false],
    ['orchestration Status is not assigned- should not show resume', true, 'Macro', 'VPE', 'Created', false],
    ['orchestration Status is Inventoried - should show resume', true, 'Macro', 'VPE', 'iNventOriEd', true]
  ];

  each(showResumeServiceDataProvider).test('showResumeService when %s', (description, flagResumeMacroService,instantiationType, subscriptionServiceType, orchStatus, shouldShowResumeService) => {
    jest.spyOn(store, 'getState').mockReturnValue(<any>{
      global: {
        flags:{
          'FLAG_1908_RESUME_MACRO_SERVICE': flagResumeMacroService
        }
      },
      service: {
        serviceInstance : {
          'serviceModelId' : {
            'vidNotions': {
              'instantiationType': instantiationType
            },
            'subscriptionServiceType':subscriptionServiceType,
            'orchStatus': orchStatus
          }
        }
      }
    });
    expect(service.showResumeService('serviceModelId')).toBe(shouldShowResumeService);

  });


  const toggleResumeServiceDataProvider = [
    [ServiceInstanceActions.None, true],
    [ServiceInstanceActions.Resume, false]
  ];

  each(toggleResumeServiceDataProvider).test('toggleResumeService - should call %s for resume/ undo Resume',(serviceAction, isResume)=>{
    jest.spyOn(store, 'dispatch');
    service.toggleResumeService("serviceInstanceId", isResume);
    expect(store.dispatch).toHaveBeenCalledWith(addServiceAction("serviceInstanceId", serviceAction));
  });

});