mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 12:12:13 +08:00

* Get rid of _dashboardLoadFailed * Get rid of dashboardNotFound meta * Update public dashboards tests * Fix DashboardPage tests * DashboardPageProxy tests * DashboardScenePageStateManager test fix * Beterer * Fix merge * Nits * Fix test * remove debugger * Update get folder to throw * translate error title * Update public/app/features/apiserver/types.ts Co-authored-by: Ivan Ortega Alba <ivanortegaalba@gmail.com> * Update public/app/features/dashboard/services/DashboardLoaderSrv.ts Co-authored-by: Ivan Ortega Alba <ivanortegaalba@gmail.com> * Update public/app/features/dashboard/services/DashboardLoaderSrv.ts Co-authored-by: Ivan Ortega Alba <ivanortegaalba@gmail.com> * Update public/app/features/dashboard/services/DashboardLoaderSrv.ts Co-authored-by: Haris Rozajac <58232930+harisrozajac@users.noreply.github.com> * Betterer * Update test cases * More test updates * More translations --------- Co-authored-by: Ivan Ortega Alba <ivanortegaalba@gmail.com> Co-authored-by: Haris Rozajac <58232930+harisrozajac@users.noreply.github.com>
72 lines
2.1 KiB
TypeScript
72 lines
2.1 KiB
TypeScript
import { FetchError } from '@grafana/runtime';
|
|
import { getMessageFromError } from 'app/core/utils/errors';
|
|
import { LoadError } from 'app/features/dashboard-scene/pages/DashboardScenePageStateManager';
|
|
|
|
describe('errors functions', () => {
|
|
let message: string | null;
|
|
|
|
describe('when getMessageFromError gets an error string', () => {
|
|
beforeEach(() => {
|
|
message = getMessageFromError('error string');
|
|
});
|
|
|
|
it('should return the string', () => {
|
|
expect(message).toBe('error string');
|
|
});
|
|
});
|
|
|
|
describe('when getMessageFromError gets an error object with message field', () => {
|
|
beforeEach(() => {
|
|
message = getMessageFromError(new Error('error string'));
|
|
});
|
|
|
|
it('should return the message text', () => {
|
|
expect(message).toBe('error string');
|
|
});
|
|
});
|
|
|
|
describe('when getMessageFromError gets an error object with data.message field', () => {
|
|
beforeEach(() => {
|
|
message = getMessageFromError({ data: { message: 'error string' }, status: 500 } as FetchError);
|
|
});
|
|
|
|
it('should return the message text', () => {
|
|
expect(message).toBe('error string');
|
|
});
|
|
});
|
|
|
|
describe('when getMessageFromError gets an error object with statusText field', () => {
|
|
beforeEach(() => {
|
|
message = getMessageFromError({ data: 'foo', statusText: 'error string', status: 500 } as FetchError);
|
|
});
|
|
|
|
it('should return the statusText text', () => {
|
|
expect(message).toBe('error string');
|
|
});
|
|
});
|
|
|
|
describe('when getMessageFromError gets an error object', () => {
|
|
beforeEach(() => {
|
|
message = getMessageFromError({ customError: 'error string' });
|
|
});
|
|
|
|
it('should return the stringified error', () => {
|
|
expect(message).toBe('{"customError":"error string"}');
|
|
});
|
|
});
|
|
|
|
describe('when getMessageFromError gets an LoadError object', () => {
|
|
beforeEach(() => {
|
|
const error: LoadError = {
|
|
message: 'error string',
|
|
status: 500,
|
|
};
|
|
message = getMessageFromError(error);
|
|
});
|
|
|
|
it('should return the stringified error', () => {
|
|
expect(message).toBe('error string');
|
|
});
|
|
});
|
|
});
|