Skip to content
Snippets Groups Projects
Commit b3e8c98a authored by OZGCloud's avatar OZGCloud
Browse files

OZG-2966 OZG-3096 dont show <span> if text is missing; cleanup; format

parent f9bfa02c
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,8 @@ import { UserProfileResource } from '@goofy-client/user-profile-shared'; ...@@ -8,6 +8,8 @@ import { UserProfileResource } from '@goofy-client/user-profile-shared';
styleUrls: ['./user-profile-in-header.component.scss'], styleUrls: ['./user-profile-in-header.component.scss'],
}) })
export class UserProfileInHeaderComponent { export class UserProfileInHeaderComponent {
@Output() public logoutEmitter: EventEmitter<void> = new EventEmitter<void>()
@Input() public currentUserResource: StateResource<UserProfileResource>; @Input() public currentUserResource: StateResource<UserProfileResource>;
@Output() public logoutEmitter: EventEmitter<void> = new EventEmitter<void>()
} }
<button mat-stroked-button <button mat-stroked-button data-test-class="icon-button" [attr.data-test-id]="dataTestId"
[color]="color" [color]="color" [type]="type" [disabled]="isDisabled" [matTooltip]="toolTip"
[type]="type" (click)="clickEmitter.emit($event)">
[disabled]="isDisabled"
[matTooltip]="toolTip"
(click)="clickEmitter.emit($event)"
[attr.data-test-id]="dataTestId"
data-test-class="icon-button">
<mat-icon <mat-icon *ngIf="icon" data-test-class="icon"
*ngIf="icon" [style.visibility]="isDisabled ? 'hidden' : 'visible'">
[style.visibility]="isDisabled ? 'hidden' : 'visible'"
data-test-class="icon">
{{ icon }} {{ icon }}
</mat-icon> </mat-icon>
<mat-icon <mat-icon *ngIf="svgIcon" data-test-class="icon"
*ngIf="svgIcon"
[svgIcon]="svgIcon" [svgIcon]="svgIcon"
[style.visibility]="isDisabled ? 'hidden' : 'visible'" [style.visibility]="isDisabled ? 'hidden' : 'visible'">
data-test-class="icon">
</mat-icon> </mat-icon>
<span>{{ text }}</span> <span *ngIf="text" data-test-class="button-with-spinner-text">{{ text }}</span>
<goofy-client-spinner <goofy-client-spinner
[diameter]="22" [diameter]="22" padding="0"
padding="0" [stateResource]="getStateResource()" [show]="showSpinner">
[stateResource]="getStateResource()"
[show]="showSpinner">
</goofy-client-spinner> </goofy-client-spinner>
</button> </button>
...@@ -4,6 +4,7 @@ import { MatRipple } from '@angular/material/core'; ...@@ -4,6 +4,7 @@ import { MatRipple } from '@angular/material/core';
import { MatIcon } from '@angular/material/icon'; import { MatIcon } from '@angular/material/icon';
import { MatTooltipModule } from '@angular/material/tooltip'; import { MatTooltipModule } from '@angular/material/tooltip';
import { createEmptyStateResource } from '@goofy-client/tech-shared'; import { createEmptyStateResource } from '@goofy-client/tech-shared';
import { getDataTestClassOf } from 'libs/tech-shared/test/data-test';
import { MockComponent } from 'ng-mocks'; import { MockComponent } from 'ng-mocks';
import { SpinnerComponent } from '../spinner/spinner.component'; import { SpinnerComponent } from '../spinner/spinner.component';
import { ButtonWithSpinnerComponent } from './button-with-spinner.component'; import { ButtonWithSpinnerComponent } from './button-with-spinner.component';
...@@ -12,8 +13,9 @@ describe('ButtonWithSpinnerComponent', () => { ...@@ -12,8 +13,9 @@ describe('ButtonWithSpinnerComponent', () => {
let component: ButtonWithSpinnerComponent; let component: ButtonWithSpinnerComponent;
let fixture: ComponentFixture<ButtonWithSpinnerComponent>; let fixture: ComponentFixture<ButtonWithSpinnerComponent>;
const buttonSelector = '[data-test-class="icon-button"]' const buttonSelector: string = getDataTestClassOf('icon-button');
const iconSelector = '[data-test-class="icon"]' const iconSelector: string = getDataTestClassOf('icon');
const text: string = getDataTestClassOf('button-with-spinner-text');
beforeEach(async () => { beforeEach(async () => {
await TestBed.configureTestingModule({ await TestBed.configureTestingModule({
...@@ -33,7 +35,6 @@ describe('ButtonWithSpinnerComponent', () => { ...@@ -33,7 +35,6 @@ describe('ButtonWithSpinnerComponent', () => {
beforeEach(() => { beforeEach(() => {
fixture = TestBed.createComponent(ButtonWithSpinnerComponent); fixture = TestBed.createComponent(ButtonWithSpinnerComponent);
component = fixture.componentInstance; component = fixture.componentInstance;
component.icon = 'add';
fixture.detectChanges(); fixture.detectChanges();
}); });
...@@ -42,38 +43,70 @@ describe('ButtonWithSpinnerComponent', () => { ...@@ -42,38 +43,70 @@ describe('ButtonWithSpinnerComponent', () => {
}); });
describe('Button', () => { describe('Button', () => {
it('should NOT disabled initial', () => { it('should NOT disabled initial', () => {
const button = fixture.nativeElement.querySelector(buttonSelector);
component.stateResource = createEmptyStateResource(); component.stateResource = createEmptyStateResource();
fixture.detectChanges(); fixture.detectChanges();
const button = fixture.nativeElement.querySelector(buttonSelector);
expect(button).not.toBeDisabled() expect(button).not.toBeDisabled()
}); });
it('should disabled if loading', () => { it('should disabled if loading', () => {
const button = fixture.nativeElement.querySelector(buttonSelector);
component.stateResource = createEmptyStateResource(true); component.stateResource = createEmptyStateResource(true);
fixture.detectChanges(); fixture.detectChanges();
const button = fixture.nativeElement.querySelector(buttonSelector);
expect(button).toBeDisabled(); expect(button).toBeDisabled();
}); });
}) })
describe('Icon', () => { describe('Icon', () => {
beforeEach(() => {
component.icon = 'add';
fixture.detectChanges();
})
it('should visible initial', () => { it('should visible initial', () => {
const icon = fixture.nativeElement.querySelector(iconSelector);
component.stateResource = createEmptyStateResource(); component.stateResource = createEmptyStateResource();
fixture.detectChanges(); fixture.detectChanges();
const icon = fixture.nativeElement.querySelector(iconSelector);
expect(icon).toBeVisible(); expect(icon).toBeVisible();
}); });
it('should not visible if loading', () => { it('should not visible if loading', () => {
const icon = fixture.nativeElement.querySelector(iconSelector);
component.stateResource = createEmptyStateResource(true); component.stateResource = createEmptyStateResource(true);
fixture.detectChanges(); fixture.detectChanges();
const icon = fixture.nativeElement.querySelector(iconSelector);
expect(icon).not.toBeVisible(); expect(icon).not.toBeVisible();
}); });
}) })
describe('Text', () => {
it('should visible if exist', () => {
component.text = 'Test text';
fixture.detectChanges();
const textElement = fixture.nativeElement.querySelector(text);
expect(textElement).toBeInTheDocument();
});
it('should not visible if is null', () => {
component.text = null;
fixture.detectChanges();
const textElement = fixture.nativeElement.querySelector(text);
expect(textElement).not.toBeInTheDocument();
});
})
}); });
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment