From 391d752137f58e77da462e950236972b5b473e05 Mon Sep 17 00:00:00 2001 From: Robert Hurst Date: Mon, 18 Nov 2024 18:07:40 +0200 Subject: [PATCH] Update test assests --- tests/_mapp.test.mjs | 4 +- tests/assets/infoj/template_infoj.json | 4 +- .../layer.json} | 0 .../layers/template_test/query_template.json | 1 + tests/browser/local.test.mjs | 2 +- tests/mod/query.test.mjs | 1 - tests/mod/workspace/_workspace.test.mjs | 57 ++++--------------- tests/mod/workspace/getLayer.test.mjs | 29 ++++++++++ tests/mod/workspace/getLocale.test.mjs | 26 +++++++++ tests/mod/workspace/getTemplate.test.mjs | 11 ++++ tests/workspace.json | 5 +- 11 files changed, 87 insertions(+), 53 deletions(-) rename tests/assets/layers/{template_test.json => template_test/layer.json} (100%) create mode 100644 tests/assets/layers/template_test/query_template.json create mode 100644 tests/mod/workspace/getLayer.test.mjs create mode 100644 tests/mod/workspace/getLocale.test.mjs create mode 100644 tests/mod/workspace/getTemplate.test.mjs diff --git a/tests/_mapp.test.mjs b/tests/_mapp.test.mjs index 6b261e7f6e..d6943c8645 100644 --- a/tests/_mapp.test.mjs +++ b/tests/_mapp.test.mjs @@ -6,7 +6,7 @@ import { dictionaryTest } from './lib/dictionaries/_dictionaries.test.mjs'; import { locationTest } from './lib/location/_location.test.mjs'; import { mapviewTest } from './lib/mapview/_mapview.test.mjs'; import { pluginsTest } from './plugins/_plugins.test.mjs'; -import { workspaceTest } from './mod/workspace/_workspace.test.mjs'; +import { workspaceSuite } from './mod/workspace/_workspace.test.mjs'; import { queryTest } from './mod/query.test.mjs'; import { userTest } from './mod/user/_user.test.js'; import { ui_elementsTest } from './lib/ui/elements/_elements.test.mjs'; @@ -26,7 +26,7 @@ self._mappTest = { locationTest, mapviewTest, pluginsTest, - workspaceTest, + workspaceSuite, queryTest, userTest, ui_elementsTest, diff --git a/tests/assets/infoj/template_infoj.json b/tests/assets/infoj/template_infoj.json index 57f3d99ac6..a24b1dbb0f 100644 --- a/tests/assets/infoj/template_infoj.json +++ b/tests/assets/infoj/template_infoj.json @@ -25,9 +25,9 @@ "display": true, "type": "dataview", "label": "foo", - "query": "data_array", + "query": "layer_data_aray", "template": { - "key": "data_array", + "key": "layer_data_array", "src": "file:/tests/assets/queries/data_array.sql", "value_only": true }, diff --git a/tests/assets/layers/template_test.json b/tests/assets/layers/template_test/layer.json similarity index 100% rename from tests/assets/layers/template_test.json rename to tests/assets/layers/template_test/layer.json diff --git a/tests/assets/layers/template_test/query_template.json b/tests/assets/layers/template_test/query_template.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/tests/assets/layers/template_test/query_template.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/tests/browser/local.test.mjs b/tests/browser/local.test.mjs index 7864f89c94..87f29a98cc 100644 --- a/tests/browser/local.test.mjs +++ b/tests/browser/local.test.mjs @@ -1,6 +1,6 @@ export async function coreTest() { //API Tests - await _mappTest.workspaceTest(); + await runAllTests(_mappTest.workspaceSuite); await _mappTest.queryTest(); const mapview = await _mappTest.base(); await runAllTests(_mappTest.userTest); diff --git a/tests/mod/query.test.mjs b/tests/mod/query.test.mjs index 81bd604612..1856a2a0f5 100644 --- a/tests/mod/query.test.mjs +++ b/tests/mod/query.test.mjs @@ -11,7 +11,6 @@ */ export async function queryTest() { - await codi.describe('Query: Testing Query API', async () => { /** * @description Query: Testing Query defined on infoj entry diff --git a/tests/mod/workspace/_workspace.test.mjs b/tests/mod/workspace/_workspace.test.mjs index 89da2f90a7..6c01b8bf00 100644 --- a/tests/mod/workspace/_workspace.test.mjs +++ b/tests/mod/workspace/_workspace.test.mjs @@ -3,7 +3,10 @@ * @module mod/workspace */ -import { hasRoles } from '../../utils/roles.js' + +import { getLayerTest } from './getLayer.test.mjs'; +import { getLocaleTest } from './getLocale.test.mjs'; +import { getTemplateTest } from './getTemplate.test.mjs'; /** * This function is used as an entry point for the changeEndTest @@ -11,51 +14,16 @@ import { hasRoles } from '../../utils/roles.js' * @function workspaceTest * @param {Object} mapview */ -export async function workspaceTest(mapview) { - - await codi.describe('Workspace: Testing Workspace API', async () => { - - await codi.it('Workspace: Getting Locales', async () => { - const locales = await mapp.utils.xhr(`/test/api/workspace/locales`); - codi.assertEqual(locales[0].key, 'locale', 'Ensure that we are getting a locale back from the API') - }); - - await codi.it('Workspace: Getting a Locale', async () => { - const locale = await mapp.utils.xhr(`/test/api/workspace/locale?locale=locale`); - codi.assertTrue(!!locale.key, 'The locale should have a key property'); - codi.assertTrue(!!locale.layers, 'The locale should have layers'); - codi.assertTrue(!!locale.name, 'The locale should have a name'); - codi.assertTrue(!!locale.plugins, 'The locale should have plugins'); - codi.assertTrue(!!locale.syncPlugins, 'The locale should have syncPlugins'); - }); - - await codi.it('Workspace: Checking locale for roles', async () => { - const locale = await mapp.utils.xhr(`/test/api/workspace/locale?locale=locale&layers=true`); - codi.assertFalse(hasRoles(locale), 'The locale object should have no roles object returned') - }); - await codi.it('Workspace: Getting template_test Layer', async () => { - let layer = await mapp.utils.xhr(`/test/api/workspace/layer?layer=template_test`); - codi.assertEqual(layer.key, 'template_test', 'Ensure that we get the template_test layer from the API') - codi.assertTrue(!!layer.table, 'Ensure that the layer has a table'); - codi.assertTrue(!!layer.geom, 'Ensure that the layer has a geom'); - codi.assertTrue(!!layer.group, 'Ensure that the layer has a group'); - codi.assertEqual(layer.infoj.length, 7, 'The infoj should always have 7 infoj entries') - codi.assertTrue(!!layer.style, 'The layer needs to have a style object from another template') - - layer = await mapp.utils.xhr(`/test/api/workspace/layer?layer=template_test`); - codi.assertEqual(layer.infoj.length, 7, 'The infoj should always have 7 infoj entries') - codi.assertTrue(!!layer.style, 'The layer needs to have a style object from another template') - codi.assertTrue(!!layer.err, 'The layer should have a error array') - codi.assertEqual(layer.err.length, 1, 'There should be on failure on the layer'); - }); +export const workspaceSuite = { + workspaceTest, + getLayerTest, + getLocaleTest, + getTemplateTest +} - await codi.it('Workspace: Getting template_test_vanilla Layer', async () => { - const layer = await mapp.utils.xhr(`/test/api/workspace/layer?layer=template_test_vanilla`); - codi.assertEqual(layer.key, 'template_test_vanilla', 'Ensure that we get the template_test_vanilla layer from the API') - codi.assertEqual(layer.infoj.length, 6, 'The infoj should always have 6 infoj entries') - codi.assertTrue(!!layer.style, 'The layer needs to have a style object from another template') - }); +async function workspaceTest(mapview) { + await codi.describe('Workspace: Testing Workspace API', async () => { await codi.it('Workspace: Getting Roles', async () => { const roles = await mapp.utils.xhr(`/test/api/workspace/roles`); @@ -145,7 +113,6 @@ export async function workspaceTest(mapview) { } codi.assertTrue(workspace_test.errors.length > 0, 'The errors array needs to have more than 1 entry') - codi.assertTrue(workspace_test.overwritten_templates.length > 0, 'The overwritten templates array needs to have more than 1 entry') codi.assertTrue(workspace_test.unused_templates.length > 0, 'The unsused templates array needs to have more than 1 entry') codi.assertTrue(Object.keys(workspace_test.usage).length > 0, 'The usage object needs to have keys') diff --git a/tests/mod/workspace/getLayer.test.mjs b/tests/mod/workspace/getLayer.test.mjs new file mode 100644 index 0000000000..6285e58660 --- /dev/null +++ b/tests/mod/workspace/getLayer.test.mjs @@ -0,0 +1,29 @@ +export function getLayerTest() { + codi.describe('Workspace tests: Get Layer Test', async () => { + + await codi.it('Workspace: Getting template_test Layer', async () => { + let layer = await mapp.utils.xhr(`/test/api/workspace/layer?layer=template_test`); + codi.assertEqual(layer.key, 'template_test', 'Ensure that we get the template_test layer from the API') + codi.assertTrue(!!layer.table, 'Ensure that the layer has a table'); + codi.assertTrue(!!layer.geom, 'Ensure that the layer has a geom'); + codi.assertTrue(!!layer.group, 'Ensure that the layer has a group'); + codi.assertEqual(layer.infoj.length, 7, 'The infoj should always have 7 infoj entries') + codi.assertTrue(!!layer.style, 'The layer needs to have a style object from another template') + + layer = await mapp.utils.xhr(`/test/api/workspace/layer?layer=template_test`); + codi.assertEqual(layer.infoj.length, 7, 'The infoj should always have 7 infoj entries') + codi.assertTrue(!!layer.style, 'The layer needs to have a style object from another template') + codi.assertTrue(!!layer.err, 'The layer should have a error array') + codi.assertEqual(layer.err.length, 1, 'There should be on failure on the layer'); + }); + + await codi.it('Workspace: Getting template_test_vanilla Layer', async () => { + const layer = await mapp.utils.xhr(`/test/api/workspace/layer?layer=template_test_vanilla`); + codi.assertEqual(layer.key, 'template_test_vanilla', 'Ensure that we get the template_test_vanilla layer from the API') + codi.assertEqual(layer.infoj.length, 6, 'The infoj should always have 6 infoj entries') + codi.assertTrue(!!layer.style, 'The layer needs to have a style object from another template') + }); + }); +} + + diff --git a/tests/mod/workspace/getLocale.test.mjs b/tests/mod/workspace/getLocale.test.mjs new file mode 100644 index 0000000000..39e4c03236 --- /dev/null +++ b/tests/mod/workspace/getLocale.test.mjs @@ -0,0 +1,26 @@ + +import { hasRoles } from '../../utils/roles.js' + +export function getLocaleTest() { + codi.describe('Workspace: Get Locale Test', async () => { + + await codi.it('Workspace: Getting Locales', async () => { + const locales = await mapp.utils.xhr(`/test/api/workspace/locales`); + codi.assertEqual(locales[0].key, 'locale', 'Ensure that we are getting a locale back from the API') + }); + + await codi.it('Workspace: Getting a Locale', async () => { + const locale = await mapp.utils.xhr(`/test/api/workspace/locale?locale=locale`); + codi.assertTrue(!!locale.key, 'The locale should have a key property'); + codi.assertTrue(!!locale.layers, 'The locale should have layers'); + codi.assertTrue(!!locale.name, 'The locale should have a name'); + codi.assertTrue(!!locale.plugins, 'The locale should have plugins'); + codi.assertTrue(!!locale.syncPlugins, 'The locale should have syncPlugins'); + }); + + await codi.it('Workspace: Checking locale for roles', async () => { + const locale = await mapp.utils.xhr(`/test/api/workspace/locale?locale=locale&layers=true`); + codi.assertFalse(hasRoles(locale), 'The locale object should have no roles object returned') + }); + }) +} \ No newline at end of file diff --git a/tests/mod/workspace/getTemplate.test.mjs b/tests/mod/workspace/getTemplate.test.mjs new file mode 100644 index 0000000000..421ee822ac --- /dev/null +++ b/tests/mod/workspace/getTemplate.test.mjs @@ -0,0 +1,11 @@ +export function getTemplateTest() { + codi.describe('Workspace: Get Template Test', async () => { + codi.it('Layer template test', async () => { + await mapp.utils.xhr(`/test/api/workspace/test`); + + const res = await mapp.utils.xhr('/test/api/query?layer=template_test&template=layer_data_array') + + codi.assertEqual(res, [1, 2, 5, 3, 4], 'We expect the query to be able to return from the workspace before the layer has been merged') + }) + }); +} \ No newline at end of file diff --git a/tests/workspace.json b/tests/workspace.json index 58834d8131..df44217e68 100644 --- a/tests/workspace.json +++ b/tests/workspace.json @@ -7,7 +7,7 @@ }, "templates": { "template_test_temp": { - "src": "file:/tests/assets/layers/template_test.json" + "src": "file:/tests/assets/layers/template_test/layer.json" }, "mvt_test_temp": { "src": "file:/tests/assets/layers/mvt/layer.json" @@ -32,7 +32,8 @@ "src": "file:/tests/assets/queries/minmax_mock.sql" }, "data_array": { - "src": "file:/tests/assets/queries/data_array.sql" + "src": "file:/tests/assets/queries/data_array.sql", + "value_only": true }, "bogus_data_array": { "src": "file:/tests/assets/queries/data_array.sql",