forked from abpframework/abp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(core): add ellipsis directive test
- Loading branch information
Showing
2 changed files
with
60 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
npm/ng-packs/packages/core/src/lib/tests/ellipsis.directive.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator/jest'; | ||
import { EllipsisDirective } from '../directives/ellipsis.directive'; | ||
|
||
describe('EllipsisDirective', () => { | ||
let spectator: SpectatorDirective<EllipsisDirective>; | ||
let directive: EllipsisDirective; | ||
let el: HTMLDivElement; | ||
const createDirective = createDirectiveFactory({ | ||
directive: EllipsisDirective, | ||
}); | ||
|
||
beforeEach(() => { | ||
spectator = createDirective( | ||
'<div [abpEllipsis]="width" [abpEllipsisEnabled]="true" [title]="title">test content</div>', | ||
{ | ||
hostProps: { | ||
title: 'test title', | ||
width: '100px', | ||
}, | ||
}, | ||
); | ||
directive = spectator.directive; | ||
el = spectator.query('div'); | ||
}); | ||
|
||
test('should be created', () => { | ||
expect(directive).toBeTruthy(); | ||
}); | ||
|
||
test('should have 100px ellipsis width', () => { | ||
expect(directive.width).toBe('100px'); | ||
}); | ||
|
||
test('should be enabled if abpEllipsisEnabled input is true', () => { | ||
expect(directive.enabled).toBe(true); | ||
}); | ||
|
||
test('should have given title', () => { | ||
expect(directive.title).toBe('test title'); | ||
}); | ||
|
||
test('should have element innerText as title if not specified', () => { | ||
spectator.setHostInput({ title: undefined }); | ||
expect(directive.title).toBe(el.innerText); | ||
}); | ||
|
||
test('should add abp-ellipsis-inline class to element if width is given', () => { | ||
expect(el).toHaveClass('abp-ellipsis-inline'); | ||
}); | ||
|
||
test('should add abp-ellipsis class to element if width is not given', () => { | ||
spectator.setHostInput({ width: undefined }); | ||
expect(el).toHaveClass('abp-ellipsis'); | ||
}); | ||
}); |