|
|
|
@ -5,75 +5,115 @@ |
|
|
|
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
|
|
|
*/ |
|
|
|
|
|
|
|
import { ModalView } from './modal-view'; |
|
|
|
import { DialogModel, ModalModel, Openable } from './modal-view'; |
|
|
|
|
|
|
|
describe('ModalView', () => { |
|
|
|
describe('DialogModel', () => { |
|
|
|
it('should have default values', () => { |
|
|
|
const dialog = new ModalView(); |
|
|
|
const dialog = new DialogModel(); |
|
|
|
|
|
|
|
checkValue(dialog, false); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should become open after show', () => { |
|
|
|
const dialog = new DialogModel(); |
|
|
|
|
|
|
|
dialog.show(); |
|
|
|
|
|
|
|
expect(dialog.closeAlways).toBeFalsy(); |
|
|
|
checkValue(dialog, true); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should have initial true value', () => { |
|
|
|
const dialog = new ModalView(true); |
|
|
|
it('should become open after toggle', () => { |
|
|
|
const dialog = new DialogModel(); |
|
|
|
|
|
|
|
dialog.toggle(); |
|
|
|
|
|
|
|
checkValue(dialog, true); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should have initial false value', () => { |
|
|
|
const dialog = new ModalView(false); |
|
|
|
it('should become closed after hide', () => { |
|
|
|
const dialog = new DialogModel().show(); |
|
|
|
|
|
|
|
dialog.hide(); |
|
|
|
|
|
|
|
checkValue(dialog, false); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should have close always set by constructor', () => { |
|
|
|
const dialog = new ModalView(false, true); |
|
|
|
it('should become closed after toggle', () => { |
|
|
|
const dialog = new DialogModel().show(); |
|
|
|
|
|
|
|
dialog.toggle(); |
|
|
|
|
|
|
|
expect(dialog.closeAlways).toBeTruthy(); |
|
|
|
checkValue(dialog, false); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should not hide other dialog', () => { |
|
|
|
const dialog1 = new DialogModel().show(); |
|
|
|
const dialog2 = new DialogModel(); |
|
|
|
|
|
|
|
dialog2.toggle(); |
|
|
|
|
|
|
|
checkValue(dialog1, true); |
|
|
|
checkValue(dialog2, true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
describe('ModalModel', () => { |
|
|
|
it('should have default values', () => { |
|
|
|
const modal = new ModalModel(); |
|
|
|
|
|
|
|
checkValue(modal, false); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should become open after show', () => { |
|
|
|
const dialog = new ModalView(false); |
|
|
|
const modal = new ModalModel(); |
|
|
|
|
|
|
|
dialog.show(); |
|
|
|
modal.show(); |
|
|
|
|
|
|
|
checkValue(dialog, true); |
|
|
|
checkValue(modal, true); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should become open after toggle', () => { |
|
|
|
const dialog = new ModalView(false); |
|
|
|
const modal = new ModalModel(); |
|
|
|
|
|
|
|
dialog.toggle(); |
|
|
|
modal.toggle(); |
|
|
|
|
|
|
|
checkValue(dialog, true); |
|
|
|
checkValue(modal, true); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should become closed after hide', () => { |
|
|
|
const dialog = new ModalView(true); |
|
|
|
const modal = new ModalModel().show(); |
|
|
|
|
|
|
|
dialog.hide(); |
|
|
|
modal.hide(); |
|
|
|
|
|
|
|
checkValue(dialog, false); |
|
|
|
checkValue(modal, false); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should become closed after toggle', () => { |
|
|
|
const dialog = new ModalView(true); |
|
|
|
const modal = new ModalModel().show(); |
|
|
|
|
|
|
|
dialog.toggle(); |
|
|
|
modal.toggle(); |
|
|
|
|
|
|
|
checkValue(dialog, false); |
|
|
|
checkValue(modal, false); |
|
|
|
}); |
|
|
|
|
|
|
|
function checkValue(dialog: ModalView, expected: boolean) { |
|
|
|
it('should hide other modal', () => { |
|
|
|
const modal1 = new ModalModel().show(); |
|
|
|
const modal2 = new ModalModel(); |
|
|
|
|
|
|
|
modal2.toggle(); |
|
|
|
|
|
|
|
checkValue(modal1, false); |
|
|
|
checkValue(modal2, true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
function checkValue(modal: Openable, expected: boolean) { |
|
|
|
let result: boolean; |
|
|
|
|
|
|
|
dialog.isOpen.subscribe(value => { |
|
|
|
modal.isOpen.subscribe(value => { |
|
|
|
result = value; |
|
|
|
}).unsubscribe(); |
|
|
|
|
|
|
|
expect(result!).toBe(expected); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|