-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
447 additions
and
22 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
48 changes: 48 additions & 0 deletions
48
hivemq-edge/src/frontend/src/api/hooks/useDomainModel/useGetDomainTag.spec.ts
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,48 @@ | ||
import { beforeEach, expect } from 'vitest' | ||
import { renderHook, waitFor } from '@testing-library/react' | ||
|
||
import { server } from '@/__test-utils__/msw/mockServer.ts' | ||
import { SimpleWrapper as wrapper } from '@/__test-utils__/hooks/SimpleWrapper.tsx' | ||
import { useGetDomainTag } from '@/api/hooks/useDomainModel/useGetDomainTag.ts' | ||
import { DomainTag } from '@/api/__generated__' | ||
import { ProblemDetails } from '@/api/types/http-problem-details.ts' | ||
import { MOCK_DEVICE_TAG_FAKE } from '@/api/hooks/useProtocolAdapters/__handlers__' | ||
|
||
import { handlers } from './__handlers__' | ||
|
||
describe('useGetDomainTag', () => { | ||
beforeEach(() => { | ||
server.use(...handlers) | ||
}) | ||
|
||
afterEach(() => { | ||
server.resetHandlers() | ||
}) | ||
|
||
it('should load the data', async () => { | ||
const mockTag = 'tag/test' | ||
const { result } = renderHook(() => useGetDomainTag(mockTag), { wrapper }) | ||
await waitFor(() => { | ||
expect(result.current.isLoading).toBeFalsy() | ||
expect(result.current.isSuccess).toBeTruthy() | ||
}) | ||
expect(result.current.data).toStrictEqual<DomainTag>({ | ||
protocolId: 'modbus', | ||
tagDefinition: { | ||
endIdx: 1, | ||
startIdx: 0, | ||
}, | ||
tagName: mockTag, | ||
}) | ||
}) | ||
|
||
it('should return an error', async () => { | ||
const { result } = renderHook(() => useGetDomainTag(MOCK_DEVICE_TAG_FAKE), { wrapper }) | ||
await waitFor(() => { | ||
expect(result.current.isLoading).toBeFalsy() | ||
}) | ||
expect(result.current.data).toStrictEqual(undefined) | ||
expect(result.current.error?.status).toStrictEqual(404) | ||
expect(result.current.error?.body).toStrictEqual<ProblemDetails>({ title: 'The tag is not found', status: 404 }) | ||
}) | ||
}) |
45 changes: 45 additions & 0 deletions
45
hivemq-edge/src/frontend/src/api/hooks/useDomainModel/useGetDomainTagSchema.spec.ts
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,45 @@ | ||
import { beforeEach, expect } from 'vitest' | ||
import { renderHook, waitFor } from '@testing-library/react' | ||
|
||
import { server } from '@/__test-utils__/msw/mockServer.ts' | ||
import { SimpleWrapper as wrapper } from '@/__test-utils__/hooks/SimpleWrapper.tsx' | ||
import { MockAdapterType } from '@/__test-utils__/adapters/types.ts' | ||
|
||
import { type TagSchema } from '@/api/__generated__' | ||
import { useGetDomainTagSchema } from '@/api/hooks/useDomainModel/useGetDomainTagSchema.ts' | ||
|
||
import { handlers } from './__handlers__' | ||
|
||
describe('useGetDomainTagSchema', () => { | ||
beforeEach(() => { | ||
server.use(...handlers) | ||
}) | ||
|
||
afterEach(() => { | ||
server.resetHandlers() | ||
}) | ||
|
||
it('should load the data', async () => { | ||
const { result } = renderHook(() => useGetDomainTagSchema(MockAdapterType.OPC_UA), { wrapper }) | ||
await waitFor(() => { | ||
expect(result.current.isLoading).toBeFalsy() | ||
expect(result.current.isSuccess).toBeTruthy() | ||
}) | ||
expect(result.current.data).toStrictEqual<TagSchema>({ | ||
protocolId: 'opcua', | ||
configSchema: expect.objectContaining({ | ||
$schema: 'https://json-schema.org/draft/2020-12/schema', | ||
}), | ||
}) | ||
}) | ||
|
||
it('should not load if protocolId is not given', async () => { | ||
const { result } = renderHook(() => useGetDomainTagSchema(undefined), { wrapper }) | ||
await waitFor(() => { | ||
expect(result.current.isLoading).toBeFalsy() | ||
expect(result.current.isFetched).toBeFalsy() | ||
}) | ||
expect(result.current.data).toBeUndefined() | ||
expect(result.current.error).toBeNull() | ||
}) | ||
}) |
40 changes: 40 additions & 0 deletions
40
hivemq-edge/src/frontend/src/api/hooks/useDomainModel/useGetSamplesForTopic.spec.ts
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,40 @@ | ||
import { beforeEach, expect } from 'vitest' | ||
import { renderHook, waitFor } from '@testing-library/react' | ||
|
||
import { server } from '@/__test-utils__/msw/mockServer.ts' | ||
import { SimpleWrapper as wrapper } from '@/__test-utils__/hooks/SimpleWrapper.tsx' | ||
import { type PayloadSampleList } from '@/api/__generated__' | ||
import { useGetSamplesForTopic } from '@/api/hooks/useDomainModel/useGetSamplesForTopic.ts' | ||
|
||
import { handlers } from './__handlers__' | ||
|
||
describe('useGetSamplesForTopic', () => { | ||
beforeEach(() => { | ||
server.use(...handlers) | ||
}) | ||
|
||
afterEach(() => { | ||
server.resetHandlers() | ||
}) | ||
|
||
it('should load the data', async () => { | ||
const { result } = renderHook(() => useGetSamplesForTopic('test/topic1', true), { wrapper }) | ||
await waitFor(() => { | ||
expect(result.current.isLoading).toBeFalsy() | ||
expect(result.current.isSuccess).toBeTruthy() | ||
}) | ||
expect(result.current.data).toStrictEqual<PayloadSampleList>({ | ||
items: [], | ||
}) | ||
}) | ||
|
||
it('should not load if not seeded', async () => { | ||
const { result } = renderHook(() => useGetSamplesForTopic('test/topic1', false), { wrapper }) | ||
await waitFor(() => { | ||
expect(result.current.isLoading).toBeFalsy() | ||
expect(result.current.isFetched).toBeFalsy() | ||
}) | ||
expect(result.current.data).toBeUndefined() | ||
expect(result.current.error).toBeNull() | ||
}) | ||
}) |
43 changes: 43 additions & 0 deletions
43
hivemq-edge/src/frontend/src/api/hooks/useDomainModel/useGetSchemaForTopic.spec.ts
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,43 @@ | ||
import { beforeEach, expect } from 'vitest' | ||
import { renderHook, waitFor } from '@testing-library/react' | ||
|
||
import { server } from '@/__test-utils__/msw/mockServer.ts' | ||
import { SimpleWrapper as wrapper } from '@/__test-utils__/hooks/SimpleWrapper.tsx' | ||
import { type JsonNode } from '@/api/__generated__' | ||
import { useGetSchemaForTopic } from '@/api/hooks/useDomainModel/useGetSchemaForTopic.ts' | ||
|
||
import { handlers } from './__handlers__' | ||
|
||
describe('useGetSchemaForTopic', () => { | ||
beforeEach(() => { | ||
server.use(...handlers) | ||
}) | ||
|
||
afterEach(() => { | ||
server.resetHandlers() | ||
}) | ||
|
||
it('should load the data', async () => { | ||
const { result } = renderHook(() => useGetSchemaForTopic('test/topic1', true), { wrapper }) | ||
await waitFor(() => { | ||
expect(result.current.isLoading).toBeFalsy() | ||
expect(result.current.isSuccess).toBeTruthy() | ||
}) | ||
expect(result.current.data).toStrictEqual<JsonNode>( | ||
expect.objectContaining({ | ||
title: 'dGVzdC90b3BpYzE=', | ||
type: 'object', | ||
}) | ||
) | ||
}) | ||
|
||
it('should not load if not seeded', async () => { | ||
const { result } = renderHook(() => useGetSchemaForTopic('test/topic1', false), { wrapper }) | ||
await waitFor(() => { | ||
expect(result.current.isLoading).toBeFalsy() | ||
expect(result.current.isFetched).toBeFalsy() | ||
}) | ||
expect(result.current.data).toBeUndefined() | ||
expect(result.current.error).toBeNull() | ||
}) | ||
}) |
39 changes: 39 additions & 0 deletions
39
hivemq-edge/src/frontend/src/api/hooks/useDomainModel/useListDomainTags.spec.ts
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,39 @@ | ||
import { beforeEach, expect } from 'vitest' | ||
import { renderHook, waitFor } from '@testing-library/react' | ||
|
||
import { server } from '@/__test-utils__/msw/mockServer.ts' | ||
import { SimpleWrapper as wrapper } from '@/__test-utils__/hooks/SimpleWrapper.tsx' | ||
import { type DomainTagList } from '@/api/__generated__' | ||
import { useListDomainTags } from '@/api/hooks/useDomainModel/useListDomainTags.ts' | ||
|
||
import { handlers } from './__handlers__' | ||
|
||
describe('useListDomainTags', () => { | ||
beforeEach(() => { | ||
server.use(...handlers) | ||
}) | ||
|
||
afterEach(() => { | ||
server.resetHandlers() | ||
}) | ||
|
||
it('should load the data', async () => { | ||
const { result } = renderHook(() => useListDomainTags(), { wrapper }) | ||
await waitFor(() => { | ||
expect(result.current.isLoading).toBeFalsy() | ||
expect(result.current.isSuccess).toBeTruthy() | ||
}) | ||
expect(result.current.data).toStrictEqual<DomainTagList>({ | ||
items: [ | ||
{ | ||
protocolId: 'modbus', | ||
tagDefinition: { | ||
endIdx: 1, | ||
startIdx: 0, | ||
}, | ||
tagName: 'test/tag1', | ||
}, | ||
], | ||
}) | ||
}) | ||
}) |
44 changes: 44 additions & 0 deletions
44
hivemq-edge/src/frontend/src/api/hooks/useDomainModel/useSamplingForTopic.spec.ts
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,44 @@ | ||
import { beforeEach, expect } from 'vitest' | ||
import { renderHook, waitFor } from '@testing-library/react' | ||
|
||
import { server } from '@/__test-utils__/msw/mockServer.ts' | ||
import { SimpleWrapper as wrapper } from '@/__test-utils__/hooks/SimpleWrapper.tsx' | ||
import { useSamplingForTopic } from '@/api/hooks/useDomainModel/useSamplingForTopic.ts' | ||
|
||
import { handlers } from './__handlers__' | ||
import { type JsonNode } from '@/api/__generated__' | ||
|
||
describe('useSamplingForTopic', () => { | ||
beforeEach(() => { | ||
server.use(...handlers) | ||
}) | ||
|
||
afterEach(() => { | ||
server.resetHandlers() | ||
}) | ||
|
||
it('should load the data', async () => { | ||
const mockTopic = 'topic/test' | ||
const { result } = renderHook(() => useSamplingForTopic(mockTopic), { wrapper }) | ||
await waitFor(() => { | ||
expect(result.current.isLoading).toBeFalsy() | ||
expect(result.current.isSuccess).toBeTruthy() | ||
}) | ||
|
||
expect(result.current.data).toStrictEqual<JsonNode>( | ||
expect.objectContaining({ | ||
title: 'dG9waWMvdGVzdA==', | ||
type: 'object', | ||
}) | ||
) | ||
|
||
// there is no samples so examples are the same as original | ||
expect(result.current.schema).toStrictEqual(result.current.data) | ||
|
||
// // TODO[NVL] Not the way to test the refetch - find better | ||
// expect(result.current.isLoading).toBeFalsy() | ||
// act(() => { | ||
// result.current.refetch() | ||
// }) | ||
}) | ||
}) |
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.