@ -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 mo dal = new ModalModel ( ) ;
dialog . show ( ) ;
mo dal. show ( ) ;
checkValue ( dialog , true ) ;
checkValue ( mo dal, true ) ;
} ) ;
it ( 'should become open after toggle' , ( ) = > {
const dialog = new ModalView ( false ) ;
const mo dal = new ModalModel ( ) ;
dialog . toggle ( ) ;
mo dal. toggle ( ) ;
checkValue ( dialog , true ) ;
checkValue ( mo dal, true ) ;
} ) ;
it ( 'should become closed after hide' , ( ) = > {
const di alog = new ModalView ( true ) ;
const mo dal = new ModalModel ( ) . show ( ) ;
di alog . hide ( ) ;
mo dal. hide ( ) ;
checkValue ( di alog , false ) ;
checkValue ( mo dal, false ) ;
} ) ;
it ( 'should become closed after toggle' , ( ) = > {
const di alog = new ModalView ( true ) ;
const mo dal = new ModalModel ( ) . show ( ) ;
di alog . toggle ( ) ;
mo dal. toggle ( ) ;
checkValue ( di alog , false ) ;
checkValue ( mo dal, false ) ;
} ) ;
function checkValue ( dialog : ModalView , expected : boolean ) {
let result : boolean ;
it ( 'should hide other modal' , ( ) = > {
const modal1 = new ModalModel ( ) . show ( ) ;
const modal2 = new ModalModel ( ) ;
dialog . isOpen . subscribe ( value = > {
result = value ;
} ) . unsubscribe ( ) ;
modal2 . toggle ( ) ;
expect ( result ! ) . toBe ( expected ) ;
}
checkValue ( modal1 , false ) ;
checkValue ( modal2 , true ) ;
} ) ;
} ) ;
function checkValue ( modal : Openable , expected : boolean ) {
let result : boolean ;
modal . isOpen . subscribe ( value = > {
result = value ;
} ) . unsubscribe ( ) ;
expect ( result ! ) . toBe ( expected ) ;
}