Skip to content

Commit

Permalink
fix: fix flexible-text test
Browse files Browse the repository at this point in the history
  • Loading branch information
mengshuicmq committed Jul 17, 2019
1 parent 9d894c8 commit b73bc69
Showing 1 changed file with 26 additions and 41 deletions.
67 changes: 26 additions & 41 deletions src/flexible-text/test/flexible-text.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { async, ComponentFixture, TestBed, fakeAsync } from '@angular/core/testing';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ThyFlexibleTextModule } from '../flexible-text.module';
import { ThyFlexibleTextComponent } from '../flexible-text.component';
import { Component, ViewChild } from '@angular/core';
Expand All @@ -7,16 +7,14 @@ import { ThyTooltipModule } from '../../tooltip';
@Component({
selector: 'thy-demo-flexible-text',
template: `
<div *ngFor="let item of titles">
<thy-flexible-text
class="flexible-text-section"
#FlexibleText
[thyContent]="item.title"
[thyPlacement]="item.placement"
>
{{ item.title }}
</thy-flexible-text>
</div>
<thy-flexible-text
class="flexible-text-section"
#FlexibleText
[thyContent]="item.title"
[thyPlacement]="item.placement"
>
{{ item.title }}
</thy-flexible-text>
`,
styles: [
`
Expand All @@ -32,26 +30,11 @@ import { ThyTooltipModule } from '../../tooltip';
})
class FlexibleTextTestComponent {
@ViewChild('FlexibleText') flexibleText: ThyFlexibleTextComponent;

titles = [
{
title: `周杰伦练琴辛酸史家长进游戏群控诉韩国一桑拿房起火伊斯兰堡会谈推迟游客夫妻美国被捕黄晓明否认拒演京东回应收集隐私救护
车高速被堵沈祥福回应炮轰烟台回应广告牌美国奥罗周杰伦练琴辛酸史家长进游戏群控诉韩国一桑拿房起火伊斯兰堡会谈推迟游客夫妻美国被捕黄晓明否认拒演京东回应收集隐私救护
车高速被堵沈祥福回应炮轰烟台回应广告牌美国奥罗`,
value: 0,
placement: 'bottom'
},
{
title: `标题未超出一定宽度,tooltip不提示全部内容`,
value: 1,
placement: 'top'
},
{
title: `文本内容超出当前所设最大宽度,超出部分省略,并显示省略号,tooltip提示全部内容`,
value: 2,
placement: 'top'
}
];
item = {
title: ``,
value: 0,
placement: 'bottom'
};
}

describe('FlexibleTextComponent', () => {
Expand All @@ -68,16 +51,18 @@ describe('FlexibleTextComponent', () => {
fixture.detectChanges();
}));

it('should show and hide the tooltip', fakeAsync(() => {
it('should hide the tooltip', () => {
const component = componentInstance.flexibleText;
expect(component.isOverflow).toBe(false);
});

it('should show the tooltip', () => {
const component = componentInstance.flexibleText;
componentInstance.item.title = `周杰伦练琴辛酸史家长进游戏群控诉韩国一桑拿房起火伊斯兰堡会谈推迟游客夫妻美国被捕黄晓明否认拒演京东回应收集隐私救护
车高速被堵沈祥福回应炮轰烟台回应广告牌美国奥罗周杰伦练琴辛酸史家长进游戏群控诉韩国一桑拿房起火伊斯兰堡会谈推迟游客夫妻美国被捕黄晓明否认拒演京东回应收集隐私救护
车高速被堵沈祥福回应炮轰烟台回应广告牌美国奥罗`;
fixture.detectChanges();
component.applyOverflow();
const compEl = component.textContainer.nativeElement;
if (compEl.clientWidth < compEl.scrollWidth) {
component.isOverflow = true;
expect(component.isOverflow).toBe(true);
} else {
component.isOverflow = false;
expect(component.isOverflow).toBe(false);
}
}));
expect(component.isOverflow).toBe(true);
});
});

0 comments on commit b73bc69

Please sign in to comment.