import { DebugElement } from '@angular/core' ; import { ComponentFixture , fakeAsync } from '@angular/core/testing' ; import { of } from 'rxjs' ; import { createTestContext } from '@delon/testing' ; import { NzSafeAny } from 'ng-zorro-antd/core/types' ; import { configureSFTestSuite , SFPage , TestFormComponent } from '../../../spec/base.spec' ; import { SFSchema } from '../../../src/schema/index' ; import { MentionWidget } from './mention.widget' ; const DATA = [ 'asdf' , 'cipchk' , '中文' , 'にほんご' ] ; describe ( 'form: widget: mention' , ( ) => { let fixture ; let dl ; let context ; let page ; const widget = 'mention' ; configureSFTestSuite ( ) ; beforeEach ( ( ) => { ( { fixture , dl , context } = createTestContext ( TestFormComponent ) ) ; page = new SFPage ( context . comp ) ; page . cleanOverlay ( ) . prop ( dl , context , fixture ) ; } ) ; function getWidget ( ) { return page . getWidget < MentionWidget > ( `sf-${ widget }` ) ; } it ( 'should be working' , fakeAsync ( ( ) => { const s = { properties : { a : { type : 'string' , enum : DATA , ui : { widget , select : jasmine . createSpy ( ) } } } } ; page . newSchema ( s ) . typeChar ( '@' ) . checkCount ( '.ant-mention-dropdown-item' , DATA . length , true ) . typeEvent ( 'click' , '.ant-mention-dropdown-item' ) ; expect ( ( s . properties ! . a . ui as NzSafeAny ) . select ) . toHaveBeenCalled ( ) ; } ) ) ; it ( 'should be validator mention count via minimum or maximum' , fakeAsync ( ( ) => { const s = { properties : { a : { type : 'string' , minimum : 1 , maximum : 2 , ui : { widget , asyncData : ( ) => of ( DATA ) } } } } ; page . newSchema ( s ) . typeChar ( '@' ) . checkError ( `最少提及 1 次` ) ; spyOn ( getWidget ( ) [ 'mentionChild' ] , 'getMentions' ) . and . returnValue ( [ '' , '' , '' , '' ] ) ; page . typeChar ( '@' ) . checkError ( `最多提及 2 次` ) ; } ) ) ; it ( 'should be remove search' , fakeAsync ( ( ) => { const s = { properties : { a : { type : 'string' , enum : DATA , minimum : 1 , maximum : 2 , ui : { widget , loadData : ( ) => of ( [ '1' ] ) } } } } ; page . newSchema ( s ) . dc ( 1 ) . typeChar ( '@' ) . checkElText ( '.ant-mention-dropdown-item' , '1' , true ) ; } ) ) ; } ) ;