Skip to content
Snippets Groups Projects
Verified Commit a8f15f7c authored by Philipp S. Sommer's avatar Philipp S. Sommer
Browse files

implement test for function container

parent 1bd74146
No related branches found
No related tags found
1 merge request!1Initial implementation
......@@ -13,30 +13,6 @@ SPDX-License-Identifier: Apache-2.0
<title>Vite + React + TS</title>
</head>
<body>
<script id="function-schema" type="application/json">
{
"description": "Find R and B values for an ICON grid.",
"properties": {
"func_name": {
"const": "icon_rb",
"description": "The name of the function. Must be 'icon_rb'",
"enum": ["icon_rb"],
"title": "Func Name",
"type": "string"
},
"delta": {
"description": "The target grid width in kilometer.",
"exclusiveMinimum": 0.0,
"title": "Delta",
"type": "number"
}
},
"required": ["func_name", "delta"],
"title": "FuncIconRb",
"type": "object"
}
</script>
<script>
function showinLog(response) {
console.log(response);
......@@ -49,6 +25,7 @@ SPDX-License-Identifier: Apache-2.0
topic="mytesttopic"
description="A list of the grid definitions with the closest grid width."
on-response="showinLog"
function-name="test_function"
>
</function-container>
<script type="module" src="/src/main.tsx"></script>
......
......@@ -96,11 +96,12 @@ function FunctionContainer({
};
if (typeof finalSchema === 'undefined') {
dasfConnection.getApiInfo().then((api_info) => {
console.log(functionName);
if (typeof functionName === 'undefined') {
setFinalSchema(api_info.functions[0].rpcSchema);
} else {
setFinalSchema(
api_info.functions.filter((f) => f.name == functionName)[0],
api_info.functions.filter((f) => f.name == functionName)[0].rpcSchema,
);
}
});
......
......@@ -11,7 +11,9 @@ const WebFunctionContainer = r2wc(FunctionContainer, {
websocketUrl: 'string',
topic: 'string',
description: 'string',
functionName: 'string',
onResponse: 'function',
onError: 'function',
},
});
......
// SPDX-FileCopyrightText: 2025 Helmholtz-Zentrum hereon GmbH
//
// SPDX-License-Identifier: Apache-2.0
import { render } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';
import { userEvent } from '@vitest/browser/context';
import FunctionContainer from '../src/components/FunctionContainer';
import { DASFConnection, WebsocketUrlBuilder } from '@dasf/dasf-messaging';
import { exec } from 'child_process';
function createConnection(uri?: string): DASFConnection {
const websocketUrl = uri
? uri
: import.meta.env.VITE_WEBSOCKET_URL || 'ws://localhost:8080/ws';
const topic = 'mytesttopic';
return new DASFConnection(new WebsocketUrlBuilder(websocketUrl, topic));
}
describe('FunctionContainer', () => {
it('test FunctionContainer submission', async () => {
const connection = createConnection();
const result = [];
const handleResponse = (response) => {
result.push(response);
};
const container = render(
<FunctionContainer
connection={connection}
functionName="test_function"
onResponse={handleResponse}
/>,
);
await vi.waitFor(() => container.getByRole('button'), {
timeout: 3000,
interval: 20,
});
const submitButton = container.getByRole('button');
expect(submitButton.innerHTML).toBe('Submit');
await submitButton.click();
await vi.waitFor(
() => {
if (result.length != 1) throw Error('No response yet');
},
{
timeout: 3000,
interval: 20,
},
);
expect(result[0]).toEqual(1);
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment