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 size harness for button #8760

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions projects/core/components/button/test/button.directive.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
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 {TuiButtonHarness} from '@taiga-ui/testing';

import {TuiButton} from '../button.directive';

describe('ButtonDirective', () => {
@Component({
standalone: true,
imports: [TuiButton],
template: `
<button
id="size-unspecified"
tuiButton
>
Unspecified
</button>

<button
id="size-l"
size="l"
tuiButton
>
Large
</button>

<button
id="size-m"
size="m"
tuiButton
>
Medium
</button>

<button
id="size-s"
size="s"
tuiButton
>
Small
</button>

<button
id="size-xs"
size="xs"
tuiButton
>
Extra small
</button>
`,
})
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('size:', () => {
it('if not specified, button size l', async () => {
const harness = await loader.getHarness(
TuiButtonHarness.with({selector: '#size-unspecified'}),
);
const size = await harness.getSize();

expect(size).toBe('l');
});

it('if the value is l, the size of the button is l', async () => {
const harness = await loader.getHarness(
TuiButtonHarness.with({selector: '#size-l'}),
);
const size = await harness.getSize();

expect(size).toBe('l');
});

it('if the value is m, the size of the button is m', async () => {
const harness = await loader.getHarness(
TuiButtonHarness.with({selector: '#size-m'}),
);
const size = await harness.getSize();

expect(size).toBe('m');
});

it('if the value is s, the size of the button is s', async () => {
const harness = await loader.getHarness(
TuiButtonHarness.with({selector: '#size-s'}),
);
const size = await harness.getSize();

expect(size).toBe('s');
});

it('if the value is xs, the size of the button is xs', async () => {
const harness = await loader.getHarness(
TuiButtonHarness.with({selector: '#size-xs'}),
);
const size = await harness.getSize();

expect(size).toBe('xs');
});
});
});
4 changes: 4 additions & 0 deletions projects/testing/core/button.harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ export class TuiButtonHarness extends TuiComponentHarness {
public async hasClass(input: string): Promise<boolean> {
return (await this.host()).hasClass(input);
}

public async getSize(): Promise<string | null> {
splincode marked this conversation as resolved.
Show resolved Hide resolved
return (await this.host()).getAttribute('data-size');
}
}
Loading