summaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/shared/components/messageModal
diff options
context:
space:
mode:
Diffstat (limited to 'vid-webpack-master/src/app/shared/components/messageModal')
-rw-r--r--vid-webpack-master/src/app/shared/components/messageModal/message-modal.model.ts15
-rw-r--r--vid-webpack-master/src/app/shared/components/messageModal/message-modal.service.spec.ts56
-rw-r--r--vid-webpack-master/src/app/shared/components/messageModal/message-modal.service.ts39
3 files changed, 110 insertions, 0 deletions
diff --git a/vid-webpack-master/src/app/shared/components/messageModal/message-modal.model.ts b/vid-webpack-master/src/app/shared/components/messageModal/message-modal.model.ts
new file mode 100644
index 000000000..d29144095
--- /dev/null
+++ b/vid-webpack-master/src/app/shared/components/messageModal/message-modal.model.ts
@@ -0,0 +1,15 @@
+import {ButtonType} from "../customModal/models/button.type";
+
+export class MessageModalModel {
+ title : string;
+ text : string;
+ type : 'error' | 'info' | 'success';
+ buttons : {text: string, size: string, type : ButtonType, closeModal: boolean}[];
+
+ constructor( title : string, text : string, type , buttons : {text: string, size: string, type : ButtonType, closeModal: boolean}[]){
+ this.title = title;
+ this.text = text;
+ this.type = type;
+ this.buttons = buttons;
+ }
+}
diff --git a/vid-webpack-master/src/app/shared/components/messageModal/message-modal.service.spec.ts b/vid-webpack-master/src/app/shared/components/messageModal/message-modal.service.spec.ts
new file mode 100644
index 000000000..ffaccb198
--- /dev/null
+++ b/vid-webpack-master/src/app/shared/components/messageModal/message-modal.service.spec.ts
@@ -0,0 +1,56 @@
+import {MessageModal} from "./message-modal.service";
+import {getTestBed, TestBed} from "@angular/core/testing";
+import {SdcUiCommon} from "onap-ui-angular";
+import each from "jest-each";
+import {MessageBoxService} from "../messageBox/messageBox.service";
+import {MessageModalModel} from "./message-modal.model";
+import {MessageBoxData} from "../messageBox/messageBox.data";
+
+
+describe('Message Modal Service', () => {
+ let injector;
+ let service: MessageModal;
+
+ beforeAll(done => (async () => {
+ TestBed.configureTestingModule({
+ imports: [],
+ providers: [MessageModal]
+ });
+ await TestBed.compileComponents();
+
+ injector = getTestBed();
+ service = injector.get(MessageModal);
+ })().then(done).catch(done.fail));
+
+
+ each([
+ ["error", SdcUiCommon.ModalType.error],
+ ["info", SdcUiCommon.ModalType.info],
+ ["success", SdcUiCommon.ModalType.success]
+ ]).test('getModalType with type %s should return %s', (inputMessageType, expectedResult) => {
+
+ let message = {
+ type: inputMessageType
+ };
+
+ const type = MessageModal.getModalType(<any>message)
+ expect(type).toEqual(expectedResult);
+ });
+
+ test('showMessageModal should call open modal with all data' , async (done)=>{
+ spyOn(MessageBoxService.openModal, 'next');
+ let message : MessageModalModel = new MessageModalModel('title', 'text', "success", []);
+
+ MessageModal.showMessageModal(message);
+ setTimeout(()=>{
+ const messageBoxData = new MessageBoxData( message.title,
+ message.text,
+ SdcUiCommon.ModalType.success,
+ SdcUiCommon.ModalSize.medium,
+ message.buttons)
+ expect(MessageBoxService.openModal.next).toHaveBeenCalledWith(messageBoxData);
+ done();
+ }, 500)
+ });
+
+});
diff --git a/vid-webpack-master/src/app/shared/components/messageModal/message-modal.service.ts b/vid-webpack-master/src/app/shared/components/messageModal/message-modal.service.ts
new file mode 100644
index 000000000..e1f85bdb0
--- /dev/null
+++ b/vid-webpack-master/src/app/shared/components/messageModal/message-modal.service.ts
@@ -0,0 +1,39 @@
+import {Injectable} from "@angular/core";
+import {MessageBoxService} from '../messageBox/messageBox.service';
+import {MessageBoxData} from '../messageBox/messageBox.data';
+import {SdcUiCommon} from "onap-ui-angular";
+import {MessageModalModel} from "./message-modal.model";
+
+@Injectable()
+export class MessageModal {
+ static showMessageModal(message: MessageModalModel): void {
+ setTimeout(() => {
+ let messageBoxData: MessageBoxData = new MessageBoxData(
+ message.title,
+ message.text,
+ this.getModalType(message),
+ SdcUiCommon.ModalSize.medium,
+ message.buttons);
+ MessageBoxService.openModal.next(messageBoxData);
+ }
+ , 500);
+ };
+
+
+ static getModalType = (message: MessageModalModel): string => {
+ switch (message.type) {
+ case "error": {
+ return SdcUiCommon.ModalType.error
+ }
+ case "info": {
+ return SdcUiCommon.ModalType.info;
+ }
+ case "success": {
+ return SdcUiCommon.ModalType.success;
+ }
+ }
+ };
+}
+
+
+