-
Notifications
You must be signed in to change notification settings - Fork 474
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(testing): adds link harness (#8771)
- Loading branch information
Showing
3 changed files
with
79 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import type {HarnessLoader} from '@angular/cdk/testing'; | ||
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed'; | ||
import {Component} from '@angular/core'; | ||
import {type ComponentFixture, TestBed} from '@angular/core/testing'; | ||
import {TuiLinkHarness} from '@taiga-ui/testing'; | ||
|
||
import {TuiLink} from '../link.directive'; | ||
|
||
describe('LinkDirective', () => { | ||
@Component({ | ||
standalone: true, | ||
imports: [TuiLink], | ||
template: ` | ||
<a | ||
id="link-no-pseudo" | ||
href="#" | ||
tuiLink | ||
> | ||
No Pseudo | ||
</a> | ||
<a | ||
id="pseudo-link" | ||
href="#" | ||
tuiLink | ||
[pseudo]="true" | ||
> | ||
Pseudo Link | ||
</a> | ||
`, | ||
}) | ||
class Test {} | ||
|
||
let fixture: ComponentFixture<Test>; | ||
let loader: HarnessLoader; | ||
|
||
beforeEach(async () => { | ||
TestBed.configureTestingModule({ | ||
imports: [Test], | ||
}); | ||
await TestBed.compileComponents(); | ||
fixture = TestBed.createComponent(Test); | ||
loader = TestbedHarnessEnvironment.loader(fixture); | ||
|
||
fixture.detectChanges(); | ||
}); | ||
|
||
describe('pseudo:', () => { | ||
it('should not have underline when pseudo is false', async () => { | ||
const link = await loader.getHarness( | ||
TuiLinkHarness.with({selector: '#link-no-pseudo'}), | ||
); | ||
|
||
expect(await link.isPseudo()).toBeFalsy(); | ||
}); | ||
|
||
it('should have underline when pseudo is true', async () => { | ||
const link = await loader.getHarness( | ||
TuiLinkHarness.with({selector: '#pseudo-link'}), | ||
); | ||
|
||
expect(await link.isPseudo()).toBeTruthy(); | ||
}); | ||
}); | ||
}); |
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
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,13 @@ | ||
import {TuiComponentHarness} from '@taiga-ui/testing/utils'; | ||
|
||
export class TuiLinkHarness extends TuiComponentHarness { | ||
public static hostSelector = 'a[tuiLink], button[tuiLink]'; | ||
|
||
public async isPseudo(): Promise<boolean> { | ||
return ( | ||
(await (await this.host()).getAttribute('style'))?.includes( | ||
'text-decoration-line: underline', | ||
) ?? false | ||
); | ||
} | ||
} |