-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(asset): add asset data source (#62)
Co-authored-by: Carson Moore <carson.moore@ni.com>
- Loading branch information
1 parent
0e230a3
commit b641456
Showing
28 changed files
with
1,089 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
* @mure @cameronwaterman | ||
|
||
/src/datasources/asset @CiprianAnton @kkerezsi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { render, screen } from '@testing-library/react' | ||
import { FetchError } from '@grafana/runtime'; | ||
import { act } from 'react-dom/test-utils'; | ||
import { FloatingError, parseErrorMessage } from './errors'; | ||
import { SystemLinkError } from "./types"; | ||
import React from 'react'; | ||
import { errorCodes } from "../datasources/data-frame/constants"; | ||
|
||
test('renders with error message', () => { | ||
render(<FloatingError message='error msg'/>) | ||
|
||
expect(screen.getByText('error msg')).toBeInTheDocument() | ||
}) | ||
|
||
test('does not render without error message', () => { | ||
const { container } = render(<FloatingError message=''/>) | ||
|
||
expect(container.innerHTML).toBeFalsy() | ||
}) | ||
|
||
test('hides after timeout', () => { | ||
jest.useFakeTimers(); | ||
|
||
const { container } = render(<FloatingError message='error msg'/>) | ||
act(() => jest.runAllTimers()) | ||
|
||
expect(container.innerHTML).toBeFalsy() | ||
}) | ||
|
||
test('parses error message', () => { | ||
const errorMock: Error = { | ||
name: 'error', | ||
message: 'error message' | ||
} | ||
|
||
const result = parseErrorMessage(errorMock) | ||
|
||
expect(result).toBe(errorMock.message) | ||
}) | ||
|
||
test('parses fetch error message', () => { | ||
const fetchErrorMock: FetchError = { | ||
status: 404, | ||
data: { message: 'error message' }, | ||
config: { url: 'URL' } | ||
} | ||
|
||
const result = parseErrorMessage(fetchErrorMock as any) | ||
|
||
expect(result).toBe(fetchErrorMock.data.message) | ||
}) | ||
|
||
test('parses fetch error status text', () => { | ||
const fetchErrorMock: FetchError = { | ||
status: 404, | ||
data: {}, | ||
statusText: 'statusText', | ||
config: { url: 'URL' } | ||
} | ||
|
||
const result = parseErrorMessage(fetchErrorMock as any) | ||
|
||
expect(result).toBe(fetchErrorMock.statusText) | ||
}) | ||
|
||
test('parses SystemLink error code', () => { | ||
const systemLinkError: SystemLinkError = { | ||
error: { | ||
name: 'name', | ||
args: [], | ||
code: -255130, | ||
message: 'error message' | ||
} | ||
} | ||
const fetchErrorMock: FetchError = { | ||
status: 404, | ||
data: systemLinkError, | ||
statusText: 'statusText', | ||
config: { url: 'URL' } | ||
} | ||
|
||
const result = parseErrorMessage(fetchErrorMock as any) | ||
|
||
expect(result).toBe(errorCodes[fetchErrorMock.data.error.code] ?? fetchErrorMock.data.error.message) | ||
}) | ||
|
||
test('parses SystemLink error message', () => { | ||
const systemLinkError: SystemLinkError = { | ||
error: { | ||
name: 'name', | ||
args: [], | ||
code: 123, | ||
message: 'error message' | ||
} | ||
} | ||
const fetchErrorMock: FetchError = { | ||
status: 404, | ||
data: systemLinkError, | ||
statusText: 'statusText', | ||
config: { url: 'URL' } | ||
} | ||
|
||
const result = parseErrorMessage(fetchErrorMock as any) | ||
|
||
expect(result).toBe(errorCodes[fetchErrorMock.data.error.code] ?? fetchErrorMock.data.error.message) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,34 @@ | ||
import { SystemMetadata } from "../datasources/system/types"; | ||
|
||
export interface Workspace { | ||
name: string; | ||
id: string; | ||
id: string, | ||
name: string, | ||
default: boolean, | ||
enabled: boolean, | ||
} | ||
|
||
export interface QuerySystemsRequest { | ||
skip?: number, | ||
take?: number, | ||
filter?: string, | ||
projection?: string, | ||
orderBy?: string | ||
} | ||
|
||
export interface QuerySystemsResponse { | ||
data: SystemMetadata[] | ||
count: number | ||
} | ||
|
||
export type DeepPartial<T> = { | ||
[Key in keyof T]?: DeepPartial<T[Key]>; | ||
}; | ||
|
||
export interface SystemLinkError { | ||
error: { | ||
args: string[]; | ||
code: number; | ||
message: string; | ||
name: string; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.