Skip to content

Commit 710bca9

Browse files
committed
feat: Add new unit tests
Signed-off-by: Pascal Zimmermann <pascal.zimmermann@theiotstudio.com>
1 parent 5b0a2fb commit 710bca9

7 files changed

Lines changed: 482 additions & 6 deletions

influxdb/jest.config.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
1-
import type { Config } from 'jest';
2-
import sharedConfig from '../jest.shared';
3-
const config: Config = {
4-
...sharedConfig,
5-
displayName: 'influxdb',
1+
const path = require('path');
2+
const fs = require('fs');
3+
4+
// Read and parse the shared jest config inline to avoid module resolution issues
5+
const swcrcPath = path.join(__dirname, '..', '.cjs.swcrc');
6+
const swcrc = JSON.parse(fs.readFileSync(swcrcPath, 'utf-8'));
7+
8+
module.exports = {
9+
testEnvironment: 'jsdom',
10+
roots: ['<rootDir>/src'],
11+
moduleNameMapper: {
12+
'^echarts/(.*)$': 'echarts',
13+
'^use-resize-observer$': 'use-resize-observer/polyfilled',
14+
'\\.(css|less)$': '<rootDir>/../stylesMock.js',
15+
},
16+
transformIgnorePatterns: ['node_modules/(?!(lodash-es|yaml))'],
17+
transform: {
18+
'^.+\\.(ts|tsx|js|jsx)$': ['@swc/jest', { ...swcrc, exclude: [], swcrc: false }],
19+
},
20+
setupFilesAfterEnv: ['<rootDir>/src/setup-tests.ts'],
621
};
7-
export default config;
22+

influxdb/src/setup-tests.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright The Perses Authors
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
import '@testing-library/jest-dom';
15+
16+
// Always mock e-charts during tests since we don't have a proper canvas in jsdom
17+
jest.mock('echarts');
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright The Perses Authors
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
import * as InfluxDBDatasourceModule from '../datasource/influxdb/InfluxDBDatasource';
15+
import * as InfluxDBTimeSeriesQueryModule from '../queries/influxdb-time-series-query/InfluxDBTimeSeriesQuery';
16+
17+
describe('Module Federation Expose Modules', () => {
18+
describe('InfluxDBDatasource.ts', () => {
19+
it('should export default InfluxDBDatasource', () => {
20+
expect(InfluxDBDatasourceModule.default).toBeDefined();
21+
expect(InfluxDBDatasourceModule.default).toHaveProperty('createClient');
22+
});
23+
24+
it('should have all required datasource properties', () => {
25+
const datasource = InfluxDBDatasourceModule.default;
26+
expect(datasource).toHaveProperty('createClient');
27+
expect(datasource).toHaveProperty('createInitialOptions');
28+
expect(datasource).toHaveProperty('OptionsEditorComponent');
29+
});
30+
});
31+
32+
describe('influxdb-time-series-query.ts', () => {
33+
it('should export default InfluxDBTimeSeriesQuery', () => {
34+
expect(InfluxDBTimeSeriesQueryModule.default).toBeDefined();
35+
expect(InfluxDBTimeSeriesQueryModule.default).toHaveProperty('getTimeSeriesData');
36+
});
37+
38+
it('should have all required query properties', () => {
39+
const query = InfluxDBTimeSeriesQueryModule.default;
40+
expect(query).toHaveProperty('getTimeSeriesData');
41+
expect(query).toHaveProperty('createInitialOptions');
42+
expect(query).toHaveProperty('OptionsEditorComponent');
43+
});
44+
});
45+
});
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Copyright The Perses Authors
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
import { InfluxDBDatasource, InfluxDBSpec } from '../datasource/influxdb/InfluxDBDatasource';
15+
16+
describe('InfluxDBDatasource', () => {
17+
it('should have createClient method', () => {
18+
expect(InfluxDBDatasource).toHaveProperty('createClient');
19+
expect(typeof InfluxDBDatasource.createClient).toBe('function');
20+
});
21+
22+
it('should have OptionsEditorComponent', () => {
23+
expect(InfluxDBDatasource).toHaveProperty('OptionsEditorComponent');
24+
});
25+
26+
it('should have createInitialOptions method', () => {
27+
expect(InfluxDBDatasource).toHaveProperty('createInitialOptions');
28+
expect(typeof InfluxDBDatasource.createInitialOptions).toBe('function');
29+
});
30+
31+
it('should create initial options with version and database', () => {
32+
const initialOptions = InfluxDBDatasource.createInitialOptions();
33+
expect(initialOptions).toEqual({
34+
version: 'v1',
35+
database: '',
36+
});
37+
});
38+
39+
it('should throw error when no URL is provided', () => {
40+
const spec: InfluxDBSpec = {
41+
version: 'v1',
42+
database: 'testdb',
43+
};
44+
const options = {
45+
proxyUrl: undefined,
46+
};
47+
48+
expect(() => {
49+
InfluxDBDatasource.createClient(spec, options);
50+
}).toThrow('No URL specified for InfluxDB client');
51+
});
52+
53+
it('should use directUrl when provided', () => {
54+
const spec: InfluxDBSpec = {
55+
version: 'v1',
56+
database: 'testdb',
57+
directUrl: 'http://localhost:8086',
58+
};
59+
const options = {
60+
proxyUrl: 'http://proxy:8086',
61+
};
62+
63+
const client = InfluxDBDatasource.createClient(spec, options);
64+
expect(client.options.datasourceUrl).toBe('http://localhost:8086');
65+
});
66+
67+
it('should fall back to proxyUrl when directUrl is not provided', () => {
68+
const spec: InfluxDBSpec = {
69+
version: 'v1',
70+
database: 'testdb',
71+
};
72+
const options = {
73+
proxyUrl: 'http://proxy:8086',
74+
};
75+
76+
const client = InfluxDBDatasource.createClient(spec, options);
77+
expect(client.options.datasourceUrl).toBe('http://proxy:8086');
78+
});
79+
});
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// Copyright The Perses Authors
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
import { getPluginModule } from '../getPluginModule';
15+
import packageJson from '../../package.json';
16+
17+
interface PluginSpec {
18+
kind: string;
19+
spec: {
20+
name: string;
21+
display: {
22+
name: string;
23+
};
24+
};
25+
}
26+
27+
describe('InfluxDB Plugin Integration', () => {
28+
describe('Plugin Module Resource', () => {
29+
it('should return valid PluginModuleResource', () => {
30+
const pluginModule = getPluginModule();
31+
expect(pluginModule.kind).toBe('PluginModule');
32+
});
33+
34+
it('should have correct metadata from package.json', () => {
35+
const pluginModule = getPluginModule();
36+
expect(pluginModule.metadata.name).toBe(packageJson.name);
37+
expect(pluginModule.metadata.version).toBe(packageJson.version);
38+
});
39+
40+
it('should include all plugins from package.json perses config', () => {
41+
const pluginModule = getPluginModule();
42+
const expectedPlugins = packageJson.perses.plugins;
43+
expect(pluginModule.spec.plugins).toEqual(expectedPlugins);
44+
});
45+
46+
it('should have correct plugin kinds', () => {
47+
const pluginModule = getPluginModule();
48+
const pluginKinds = pluginModule.spec.plugins.map((p: PluginSpec) => p.kind);
49+
expect(pluginKinds).toContain('Datasource');
50+
expect(pluginKinds).toContain('TimeSeriesQuery');
51+
});
52+
53+
it('should have correct plugin names', () => {
54+
const pluginModule = getPluginModule();
55+
const pluginNames = pluginModule.spec.plugins.map((p: PluginSpec) => p.spec.name);
56+
expect(pluginNames).toContain('InfluxDBDatasource');
57+
expect(pluginNames).toContain('InfluxDBTimeSeriesQuery');
58+
});
59+
});
60+
61+
describe('Plugin Metadata', () => {
62+
it('should have display names for all plugins', () => {
63+
const pluginModule = getPluginModule();
64+
pluginModule.spec.plugins.forEach((plugin: PluginSpec) => {
65+
expect(plugin.spec.display).toBeDefined();
66+
expect(plugin.spec.display.name).toBeDefined();
67+
expect(plugin.spec.display.name).toBeTruthy();
68+
});
69+
});
70+
71+
it('should have valid plugin specifications', () => {
72+
const pluginModule = getPluginModule();
73+
pluginModule.spec.plugins.forEach((plugin: PluginSpec) => {
74+
expect(plugin.kind).toBeTruthy();
75+
expect(plugin.spec).toBeDefined();
76+
expect(plugin.spec.name).toBeDefined();
77+
});
78+
});
79+
});
80+
81+
describe('Datasource Plugin Configuration', () => {
82+
it('should have InfluxDB Datasource configured', () => {
83+
const pluginModule = getPluginModule();
84+
const datasourcePlugin = pluginModule.spec.plugins.find(
85+
(p: PluginSpec) => p.kind === 'Datasource' && p.spec.name === 'InfluxDBDatasource'
86+
);
87+
expect(datasourcePlugin).toBeDefined();
88+
});
89+
90+
it('should have correct Datasource display name', () => {
91+
const pluginModule = getPluginModule();
92+
const datasourcePlugin = pluginModule.spec.plugins.find(
93+
(p: PluginSpec) => p.kind === 'Datasource' && p.spec.name === 'InfluxDBDatasource'
94+
);
95+
expect(datasourcePlugin?.spec.display.name).toBe('InfluxDB Datasource');
96+
});
97+
});
98+
99+
describe('TimeSeriesQuery Plugin Configuration', () => {
100+
it('should have TimeSeriesQuery plugin configured', () => {
101+
const pluginModule = getPluginModule();
102+
const queryPlugin = pluginModule.spec.plugins.find(
103+
(p: PluginSpec) => p.kind === 'TimeSeriesQuery' && p.spec.name === 'InfluxDBTimeSeriesQuery'
104+
);
105+
expect(queryPlugin).toBeDefined();
106+
});
107+
108+
it('should have correct TimeSeriesQuery display name', () => {
109+
const pluginModule = getPluginModule();
110+
const queryPlugin = pluginModule.spec.plugins.find(
111+
(p: PluginSpec) => p.kind === 'TimeSeriesQuery' && p.spec.name === 'InfluxDBTimeSeriesQuery'
112+
);
113+
expect(queryPlugin?.spec.display.name).toBe('InfluxDB Time Series Query');
114+
});
115+
});
116+
});
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Copyright The Perses Authors
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
import * as InfluxDBDatasourceModule from '../datasource/influxdb/InfluxDBDatasource';
15+
import * as InfluxDBTimeSeriesQueryModule from '../queries/influxdb-time-series-query/InfluxDBTimeSeriesQuery';
16+
17+
describe('Module Federation Exports', () => {
18+
describe('InfluxDBDatasource Module', () => {
19+
it('should export default InfluxDBDatasource', () => {
20+
expect(InfluxDBDatasourceModule.default).toBeDefined();
21+
expect(InfluxDBDatasourceModule.default).toHaveProperty('createClient');
22+
});
23+
24+
it('should export named InfluxDBDatasource', () => {
25+
expect(InfluxDBDatasourceModule.InfluxDBDatasource).toBeDefined();
26+
expect(InfluxDBDatasourceModule.InfluxDBDatasource).toEqual(InfluxDBDatasourceModule.default);
27+
});
28+
29+
it('should have all required datasource plugin properties', () => {
30+
const datasource = InfluxDBDatasourceModule.default;
31+
expect(datasource).toHaveProperty('createClient');
32+
expect(datasource).toHaveProperty('createInitialOptions');
33+
expect(datasource).toHaveProperty('OptionsEditorComponent');
34+
});
35+
});
36+
37+
describe('InfluxDBTimeSeriesQuery Module', () => {
38+
it('should export default InfluxDBTimeSeriesQuery', () => {
39+
expect(InfluxDBTimeSeriesQueryModule.default).toBeDefined();
40+
expect(InfluxDBTimeSeriesQueryModule.default).toHaveProperty('getTimeSeriesData');
41+
});
42+
43+
it('should export named InfluxDBTimeSeriesQuery', () => {
44+
expect(InfluxDBTimeSeriesQueryModule.InfluxDBTimeSeriesQuery).toBeDefined();
45+
expect(InfluxDBTimeSeriesQueryModule.InfluxDBTimeSeriesQuery).toEqual(InfluxDBTimeSeriesQueryModule.default);
46+
});
47+
48+
it('should have all required query plugin properties', () => {
49+
const query = InfluxDBTimeSeriesQueryModule.default;
50+
expect(query).toHaveProperty('getTimeSeriesData');
51+
expect(query).toHaveProperty('createInitialOptions');
52+
expect(query).toHaveProperty('OptionsEditorComponent');
53+
});
54+
});
55+
56+
describe('Bootstrap Module', () => {
57+
it('should export all required modules from bootstrap', async () => {
58+
const bootstrap = await import('../bootstrap');
59+
expect(bootstrap.getPluginModule).toBeDefined();
60+
expect(bootstrap.InfluxDBDatasource).toBeDefined();
61+
expect(bootstrap.InfluxDBTimeSeriesQuery).toBeDefined();
62+
});
63+
64+
it('should export correct InfluxDBDatasource from bootstrap', async () => {
65+
const bootstrap = await import('../bootstrap');
66+
const datasource = bootstrap.InfluxDBDatasource;
67+
expect(datasource).toHaveProperty('createClient');
68+
expect(datasource).toHaveProperty('createInitialOptions');
69+
expect(datasource).toHaveProperty('OptionsEditorComponent');
70+
});
71+
72+
it('should export correct InfluxDBTimeSeriesQuery from bootstrap', async () => {
73+
const bootstrap = await import('../bootstrap');
74+
expect(bootstrap.InfluxDBTimeSeriesQuery).toEqual(InfluxDBTimeSeriesQueryModule.InfluxDBTimeSeriesQuery);
75+
});
76+
77+
it('should return valid PluginModule metadata', async () => {
78+
const bootstrap = await import('../bootstrap');
79+
const pluginModule = bootstrap.getPluginModule();
80+
expect(pluginModule.kind).toBe('PluginModule');
81+
expect(pluginModule.metadata).toHaveProperty('name');
82+
expect(pluginModule.metadata).toHaveProperty('version');
83+
expect(pluginModule.spec).toHaveProperty('plugins');
84+
});
85+
});
86+
});

0 commit comments

Comments
 (0)