Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xelaint committed Jan 8, 2025
1 parent 9fb2502 commit 180dbf1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ import { DaffFormFieldControl } from '../form-field-control';
import { DaffFormFieldMissingControlMessage } from '../form-field-errors';

@Component({ template: `
<daff-form-field [formSubmitted]="formSubmittedValue">
<daff-form-field>
<input daff-input [formControl]="formControl">
<daff-error-message></daff-error-message>
</daff-form-field>` })
class WrapperComponent {
formSubmittedValue: boolean;
formControl = new UntypedFormControl('', Validators.required);
}

Expand Down Expand Up @@ -118,13 +117,12 @@ describe('@daffodil/design | DaffFormFieldComponent | Usage', () => {
});

@Component({ template: `
<daff-form-field [formSubmitted]="formSubmittedValue">
<daff-form-field>
<daff-error-message></daff-error-message>
</daff-form-field>` })

class WrapperWithoutControlComponent {
formSubmittedValue: boolean;
}
class WrapperWithoutControlComponent {}

describe('@daffodil/design | DaffFormFieldComponent | Usage Without Control', () => {
let fixture: ComponentFixture<WrapperWithoutControlComponent>;

Expand Down
37 changes: 30 additions & 7 deletions libs/design/src/atoms/form/hint/hint.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,54 @@
import {
Component,
DebugElement,
} from '@angular/core';
import {
waitForAsync,
ComponentFixture,
TestBed,
} from '@angular/core/testing';
import { By } from '@angular/platform-browser';

import { DaffHintComponent } from './hint.component';

@Component({
template: `<daff-hint>Hint</daff-hint>`,
standalone: true,
imports: [
DaffHintComponent,
],
})

class WrapperComponent {}

describe('@daffodil/design | DaffHintComponent', () => {
let fixture: ComponentFixture<DaffHintComponent>;
let component: DaffHintComponent;
let wrapper: WrapperComponent;
let de: DebugElement;
let fixture: ComponentFixture<WrapperComponent>;

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [
DaffHintComponent,
imports: [
WrapperComponent,
],
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(DaffHintComponent);
component = fixture.componentInstance;
fixture = TestBed.createComponent(WrapperComponent);
wrapper = fixture.componentInstance;
de = fixture.debugElement.query(By.css('daff-hint'));
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
expect(wrapper).toBeTruthy();
});

it('should add a class of "daff-hint" to the host element', () => {
expect(de.classes).toEqual(jasmine.objectContaining({
'daff-hint': true,
}));
});
});
13 changes: 2 additions & 11 deletions libs/design/src/atoms/form/input/input.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@ import { By } from '@angular/platform-browser';
import { DaffInputComponent } from './input.component';

@Component({
template: `<input daff-input [formSubmitted]="formSubmittedValue">`,
template: `<input daff-input>`,
})
class WrapperComponent {
formSubmittedValue: boolean;
}
class WrapperComponent {}

describe('@daffodil/design | DaffInputComponent', () => {
let wrapper: WrapperComponent;
let fixture: ComponentFixture<WrapperComponent>;
let stubFormControl;
let stubFormSubmitted: boolean;
let component: DaffInputComponent;
let componentDE: DebugElement;

Expand All @@ -39,11 +36,9 @@ describe('@daffodil/design | DaffInputComponent', () => {

beforeEach(() => {
stubFormControl = new UntypedFormControl();
stubFormSubmitted = false;

fixture = TestBed.createComponent(WrapperComponent);
wrapper = fixture.componentInstance;
wrapper.formSubmittedValue = stubFormSubmitted;
fixture.detectChanges();

componentDE = fixture.debugElement.query(By.css('[daff-input]'));
Expand All @@ -54,10 +49,6 @@ describe('@daffodil/design | DaffInputComponent', () => {
expect(wrapper).toBeTruthy();
});

it('should be able to take formSubmitted as input', () => {
expect(component.formSubmitted).toEqual(stubFormSubmitted);
});

describe('onFocus', () => {
it('should call focus on the native element', () => {
spyOn(componentDE.nativeElement, 'focus');
Expand Down

0 comments on commit 180dbf1

Please sign in to comment.