Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(testing): adds link harness #8771

Merged
merged 8 commits into from
Sep 3, 2024
65 changes: 65 additions & 0 deletions projects/core/components/link/test/link.directive.spec.ts
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();
});
});
});
1 change: 1 addition & 0 deletions projects/testing/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export * from './card.harness';
export * from './dialog.harness';
export * from './dropdown-open.harness';
export * from './island.harness';
export * from './link.harness';
export * from './loader.harness';
export * from './primitive-textfield.harness';
export * from './select.harness';
Expand Down
13 changes: 13 additions & 0 deletions projects/testing/core/link.harness.ts
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
);
}
}