Skip to content

Commit

Permalink
feat(testing): adds link harness (#8771)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohan-mu authored Sep 3, 2024
1 parent 974c1f3 commit e38cdb5
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
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
);
}
}

0 comments on commit e38cdb5

Please sign in to comment.