Skip to content

Commit

Permalink
Merge pull request GEOLYTIX#1721 from RobAndrewHurst/getTemplate
Browse files Browse the repository at this point in the history
Update test assests
  • Loading branch information
RobAndrewHurst authored Nov 18, 2024
2 parents 06d7b8a + 391d752 commit 33612bb
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 53 deletions.
4 changes: 2 additions & 2 deletions tests/_mapp.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -26,7 +26,7 @@ self._mappTest = {
locationTest,
mapviewTest,
pluginsTest,
workspaceTest,
workspaceSuite,
queryTest,
userTest,
ui_elementsTest,
Expand Down
4 changes: 2 additions & 2 deletions tests/assets/infoj/template_infoj.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions tests/assets/layers/template_test/query_template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
2 changes: 1 addition & 1 deletion tests/browser/local.test.mjs
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
1 change: 0 additions & 1 deletion tests/mod/query.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*/
export async function queryTest() {


await codi.describe('Query: Testing Query API', async () => {
/**
* @description Query: Testing Query defined on infoj entry
Expand Down
57 changes: 12 additions & 45 deletions tests/mod/workspace/_workspace.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,27 @@
* @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
* This function is also in a function as to not execute in the CLI environment and only execute in a browser.
* @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`);
Expand Down Expand Up @@ -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')

Expand Down
29 changes: 29 additions & 0 deletions tests/mod/workspace/getLayer.test.mjs
Original file line number Diff line number Diff line change
@@ -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')
});
});
}


26 changes: 26 additions & 0 deletions tests/mod/workspace/getLocale.test.mjs
Original file line number Diff line number Diff line change
@@ -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')
});
})
}
11 changes: 11 additions & 0 deletions tests/mod/workspace/getTemplate.test.mjs
Original file line number Diff line number Diff line change
@@ -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')
})
});
}
5 changes: 3 additions & 2 deletions tests/workspace.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand Down

0 comments on commit 33612bb

Please sign in to comment.