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

Revert "OZG-6908 remove generic error message from button"

This reverts commit b9567e9c.
parent 6ba80a1d
No related branches found
No related tags found
No related merge requests found
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { createCommandResource } from 'libs/command-shared/test/command';
import {
createCommandErrorStateResource,
createCommandResource,
} from 'libs/command-shared/test/command';
import { createApiError } from 'libs/tech-shared/test/error';
import { ButtonWithSpinnerComponent } from './button-with-spinner.component';
import * as ResourceUtils from 'libs/tech-shared/src/lib/resource/resource.util';
......@@ -79,4 +83,30 @@ describe('ButtonWithSpinnerComponent', () => {
expect(isLoading).toBeTruthy();
});
});
describe('isError', () => {
it('should return false if error is not set', () => {
component.stateResource.error = null;
const isError: boolean = component.isError;
expect(isError).toBeFalsy();
});
it('should return false if error is set and error is ApiError', () => {
component.stateResource.error = createApiError();
const isError: boolean = component.isError;
expect(isError).toBeFalsy();
});
it('should return true if error is set and error is not ApiError', () => {
component.stateResource = createCommandErrorStateResource();
const isError: boolean = component.isError;
expect(isError).toBeTruthy();
});
});
});
......@@ -13,14 +13,21 @@ type ButtonVariants = VariantProps<typeof buttonVariants>;
standalone: true,
imports: [CommonModule, ButtonComponent, ErrorMessageComponent],
styles: [':host {@apply flex flex-col w-fit}'],
template: `<ods-button
template: ` <ods-error-message
*ngIf="isError"
text="Ein Fehler ist aufgetreten."
subText="Versuchen Sie es noch einmal."
>
</ods-error-message>
<ods-button
[text]="text"
[variant]="variant"
[size]="size"
[dataTestId]="dataTestId"
[isLoading]="isLoading"
(click)="clickEmitter.emit()"
/>`,
>
</ods-button>`,
})
export class ButtonWithSpinnerComponent implements OnInit {
@Input() text: string = '';
......@@ -44,6 +51,8 @@ export class ButtonWithSpinnerComponent implements OnInit {
}
get isError(): boolean {
return isLoaded(this.stateResource) && hasCommandError(<CommandResource>this.stateResource.resource);
return (
isLoaded(this.stateResource) && hasCommandError(<CommandResource>this.stateResource.resource)
);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment