Skip to content

Commit

Permalink
test(module:mention): add test
Browse files Browse the repository at this point in the history
  • Loading branch information
hsuanxyz committed Jun 24, 2019
1 parent 66514c2 commit cb05f5c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
36 changes: 35 additions & 1 deletion components/mention/nz-mention.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,32 @@ describe('mention', () => {
expect(overlayContainerElement.textContent).toEqual('');
expect(textarea.value).toEqual('@angular ');
}));

it('should support switch trigger', fakeAsync(() => {
fixture.componentInstance.inputTrigger = true;
fixture.detectChanges();
const input = fixture.debugElement.query(By.css('input')).nativeElement;
const mention = fixture.componentInstance.mention;

expect(fixture.debugElement.query(By.css('textarea'))).toBeFalsy();
expect(input).toBeTruthy();

input.value = '@a';
fixture.detectChanges();
dispatchFakeEvent(input, 'click');
fixture.detectChanges();
flush();

expect(mention.isOpen).toBe(true);

const option = overlayContainerElement.querySelector('.ant-mention-dropdown-item') as HTMLElement;
option.click();
fixture.detectChanges();

tick(500);
expect(mention.isOpen).toBe(false);
expect(overlayContainerElement.textContent).toEqual('');
}));
});

describe('keyboard events', () => {
Expand Down Expand Up @@ -434,13 +460,21 @@ describe('mention', () => {
@Component({
template: `
<nz-mention [nzSuggestions]="suggestions">
<textarea nz-input [nzAutosize]="{ minRows: 4, maxRows: 4 }" [(ngModel)]="inputValue" nzMentionTrigger>
<textarea
*ngIf="!inputTrigger"
nz-input
[nzAutosize]="{ minRows: 4, maxRows: 4 }"
[(ngModel)]="inputValue"
nzMentionTrigger
>
</textarea>
<input *ngIf="inputTrigger" nz-input [(ngModel)]="inputValue" nzMentionTrigger />
</nz-mention>
`
})
class NzTestSimpleMentionComponent {
inputValue: string = '@angular';
inputTrigger = false;
suggestions = ['angular', 'ant-design', 'mention', '中文', 'にほんご'];
@ViewChild(NzMentionComponent, { static: false }) mention: NzMentionComponent;
@ViewChild(NzMentionTriggerDirective, { static: false }) trigger: NzMentionTriggerDirective;
Expand Down
1 change: 1 addition & 0 deletions components/mention/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * from './nz-mention.module';
export * from './nz-mention.component';
export * from './nz-mention-trigger';
export * from './nz-mention-suggestions';
export * from './nz-mention.service';

0 comments on commit cb05f5c

Please sign in to comment.