Skip to content

Commit

Permalink
[ACA-4633] Fix error script dropdown sometimes not having a label (#2899
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Thomas Hunter committed Jan 12, 2023
1 parent 2397c81 commit b4503c1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
{{ 'ACA_FOLDER_RULES.RULE_DETAILS.OPTIONS.IS_ASYNCHRONOUS' | translate }}
</mat-checkbox>

<mat-form-field [ngClass]="{ 'hide-error-script-dropdown': hideErrorScriptDropdown }">
<mat-form-field
data-automation-id="rule-option-form-field-errorScript"
floatLabel="always"
[ngClass]="{ 'hide-error-script-dropdown': hideErrorScriptDropdown }">

<mat-select
formControlName="errorScript"
placeholder="{{ 'ACA_FOLDER_RULES.RULE_DETAILS.OPTIONS.ERROR_SCRIPT' | translate}}"
Expand All @@ -23,6 +27,7 @@
</ng-template>

</mat-select>

</mat-form-field>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { RuleOptionsUiComponent } from './rule-options.ui-component';
import { CoreTestingModule } from '@alfresco/adf-core';
import { By } from '@angular/platform-browser';
import { errorScriptConstraintMock } from '../../mock/actions.mock';
import { MAT_FORM_FIELD_DEFAULT_OPTIONS } from '@angular/material/form-field';

describe('RuleOptionsUiComponent', () => {
let fixture: ComponentFixture<RuleOptionsUiComponent>;
Expand All @@ -46,7 +47,8 @@ describe('RuleOptionsUiComponent', () => {
TestBed.configureTestingModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [FormsModule, ReactiveFormsModule, CoreTestingModule],
declarations: [RuleOptionsUiComponent]
declarations: [RuleOptionsUiComponent],
providers: [{ provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, useValue: { floatLabel: 'never' } }]
});

fixture = TestBed.createComponent(RuleOptionsUiComponent);
Expand Down Expand Up @@ -133,4 +135,20 @@ describe('RuleOptionsUiComponent', () => {
expect((matOptions[1].nativeElement as HTMLElement).innerText.trim()).toBe('Script 1');
expect((matOptions[2].nativeElement as HTMLElement).innerText.trim()).toBe('Script 2');
});

it('should always show a label for the error script dropdown even when MAT_FORM_FIELD_DEFAULT_OPTIONS sets floatLabel to never', () => {
component.writeValue({
isEnabled: true,
isInheritable: false,
isAsynchronous: true,
errorScript: ''
});
component.errorScriptConstraint = errorScriptConstraintMock;
fixture.detectChanges();

const matFormField = fixture.debugElement.query(By.css(`[data-automation-id="rule-option-form-field-errorScript"] .mat-form-field-label`));
fixture.detectChanges();
expect(matFormField).not.toBeNull();
expect(matFormField.componentInstance['floatLabel']).toBe('always');
});
});

0 comments on commit b4503c1

Please sign in to comment.