Skip to content

Commit

Permalink
[ACS-6211] Addressed code review findings. Added label div for when c…
Browse files Browse the repository at this point in the history
…ard-view-selectitem.component is in non-editable mode. Added corresponding tests
  • Loading branch information
swapnil-verma-gl committed Nov 24, 2023
1 parent 9b80015 commit 703c444
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<ng-container *ngIf="!property.isEmpty() || isEditable()">
<div class="adf-property-field">
<div
*ngIf="!isEditable()"
class="adf-select-item-padding adf-property-value"
[attr.data-automation-id]="'select-readonly-value-' + property.key"
data-automation-class="read-only-value">{{ (property.displayValue | async) | translate }}
<div *ngIf="!isEditable()">
<div
[attr.data-automation-id]="'card-select-label-' + property.key"
class="adf-property-label"
>{{ property.label | translate }}</div>
<div
class="adf-select-item-padding adf-property-value"
[attr.data-automation-id]="'select-readonly-value-' + property.key"
data-automation-class="read-only-value">{{ (property.displayValue | async) | translate }}
</div>
</div>
<div *ngIf="isEditable()">
<mat-form-field class="adf-property-value" appearance="standard">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { AppConfigService } from '../../../app-config/app-config.service';
import { HarnessLoader } from '@angular/cdk/testing';
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { MatSelectHarness } from '@angular/material/select/testing';
import { MatLabel } from '@angular/material/form-field';

describe('CardViewSelectItemComponent', () => {
let loader: HarnessLoader;
Expand Down Expand Up @@ -73,6 +74,25 @@ describe('CardViewSelectItemComponent', () => {
});

describe('Rendering', () => {
it('should render custom label when editable is set to false', () => {
component.property = new CardViewSelectItemModel({
...mockDefaultProps,
editable: false
});
fixture.detectChanges();
const labelValue = fixture.debugElement.query(By.css('.adf-property-label'));
expect(labelValue).not.toBeNull();
expect(labelValue.nativeElement.innerText).toBe('Select box label');
});

it('should render mat label when editable is set to true', () => {
component.editable = true;
fixture.detectChanges();
const labelValue = fixture.debugElement.query(By.directive(MatLabel));
expect(labelValue).not.toBeNull();
expect(labelValue.nativeElement.innerText).toBe('Select box label');
});

it('should render readOnly value is editable property is FALSE', () => {
component.property = new CardViewSelectItemModel({
...mockDefaultProps,
Expand Down

0 comments on commit 703c444

Please sign in to comment.