From f7adb8c5f0377151ae3e75786e9debbe9fd4a469 Mon Sep 17 00:00:00 2001 From: Tanya <62726866+TanyaStere42@users.noreply.github.com> Date: Mon, 25 Nov 2024 11:37:27 -0800 Subject: [PATCH] Removal of unmaintained tests tests haen't been maintained for years, none of them work. unit tests will be done on work as completed going forward --- .../tests/coOccurrenceGraph_test.js | 139 ------- .../tests/forceLayoutAbstract_test.js | 341 ------------------ .../javascript/tests/graphAbstract_test.js | 296 --------------- .../javascript/tests/jsonParser_test.js | 147 -------- src/main/webapp/javascript/tests/test.html | 33 -- 5 files changed, 956 deletions(-) delete mode 100644 src/main/webapp/javascript/tests/coOccurrenceGraph_test.js delete mode 100644 src/main/webapp/javascript/tests/forceLayoutAbstract_test.js delete mode 100644 src/main/webapp/javascript/tests/graphAbstract_test.js delete mode 100644 src/main/webapp/javascript/tests/jsonParser_test.js delete mode 100644 src/main/webapp/javascript/tests/test.html diff --git a/src/main/webapp/javascript/tests/coOccurrenceGraph_test.js b/src/main/webapp/javascript/tests/coOccurrenceGraph_test.js deleted file mode 100644 index 3dc3dbc091..0000000000 --- a/src/main/webapp/javascript/tests/coOccurrenceGraph_test.js +++ /dev/null @@ -1,139 +0,0 @@ -QUnit.module('Co-Occurrence Graph Interface'); - -let cg, cgCopy; -QUnit.begin(() => { - let individualId = "mock" - cg = new OccurrenceGraph(individualId); -}); - -cloneCG = () => Object.assign(Object.create(Object.getPrototypeOf(cg)), cg); - -let nodeMinTypeHook = { - "beforeEach": () => { - cgCopy = cloneCG(); - cgCopy.getNodeMin = (node1, node2) => [0, 1]; - } -} -QUnit.module('getNodeMinType()', nodeMinTypeHook, () => { - QUnit.test('Spatial', t => { - let dist = cgCopy.getNodeMinType({}, {}, "spatial"); - t.equal(dist, 0); - }); - QUnit.test('Temporal', t => { - let time = cgCopy.getNodeMinType({}, {}, "temporal"); - t.equal(time, 1); - }); - QUnit.test('Invalid type', t => { - let val = cgCopy.getNodeMinType({}, {}, null); - t.notOk(val); - }); -}); - -QUnit.module('getSightingsData()', () => { - QUnit.test('Empty data', t => { - let data = cg.getSightingsData([]); - t.equal(data.length, 0); - }); - - QUnit.test('Valid data', t => { - let sightings = [{"location": {"lat": 0, "lon": 1}, "time": {"datetime": 2}}]; - let data = cg.getSightingsData(sightings); - t.equal(data.length, 1); - t.equal(data[0].lat, 0); - }); -}); - -QUnit.module('getNodeMinBruteForce()', () => { - QUnit.test('Valid data', t => { - let arr1 = [{"a": 1, "b": 2}, {"a": 3, "b": 4}]; - let arr2 = [{"a": 5, "b": 8}, {"a": 4, "b": 7}]; - let diffFunc = (x, y) => Math.abs(x.a - y.a) + Math.abs(x.b - y.b); - let min = cg.getNodeMinBruteForce(arr1, arr2, diffFunc); - t.equal(min, 4); - }); -}); - -QUnit.module('getNodeMinKDTree()', () => { - QUnit.test('Valid data', t => { - let arr1 = [{"a": 1, "b": 2}, {"a": 3, "b": 4}]; - let arr2 = [{"a": 5, "b": 8}, {"a": 4, "b": 7}]; - let diffFunc = (x, y) => Math.abs(x.a - y.a) + Math.abs(x.b - y.b); - let [min, coordPair] = cg.getNodeMinKDTree(arr1, arr2, ["a", "b"], diffFunc); - t.equal(min, 4); - }); -}); - -QUnit.module('calculateDist()', () => { - QUnit.test('Valid distances', t => { - let node1Loc = { - "lon": 10, - "lat": 0 - } - let node2Loc = { - "lon": 0, - "lat": 0 - } - t.equal(cg.calculateDist(node1Loc, node2Loc), 10) - }); - - QUnit.test('Invalid distances', t => { - t.equal(cg.calculateDist(null, 10), -1) - }); -}); - -QUnit.module('calculateTime()', () => { - QUnit.test('Valid times', t => { - t.equal(cg.calculateTime(10, 0), 10) - }); - - QUnit.test('Invalid times', t => { - t.equal(cg.calculateTime(10, null), -1) - }); -}); - -let linearInterpEventHooks = { - 'before': () => cg.id = "a", - 'after': () => cg.id = null -} -QUnit.module('linearInterp()', linearInterpEventHooks, () => { - QUnit.test('Valid x-axis interpolation', t => { - let link = { - 'source': { - 'data': { - 'individualID': "a" - }, - 'x': 10 - }, - 'target': { - 'x': 0 - } - }; - t.equal(cg.linearInterp(link, "x"), 4); - }); - - QUnit.test('Valid y-axis interpolation', t => { - let link = { - 'source': { - 'data': { - 'individualID': "a" - }, - 'y': 0 - }, - 'target': { - 'y': 10 - } - }; - t.equal(cg.linearInterp(link, "y"), 6); - }); - - QUnit.test('Invalid link data', t => { - t.equal(cg.linearInterp(null, "z"), -1) - }); -}); - -QUnit.module('focusedNode()', () => { - QUnit.test('Verify no-op', t => { - let val = cg.focusNode(); - t.notOk(val); - }); -}); diff --git a/src/main/webapp/javascript/tests/forceLayoutAbstract_test.js b/src/main/webapp/javascript/tests/forceLayoutAbstract_test.js deleted file mode 100644 index 5e3980cecf..0000000000 --- a/src/main/webapp/javascript/tests/forceLayoutAbstract_test.js +++ /dev/null @@ -1,341 +0,0 @@ -QUnit.module('Abstract Force Layout Interface'); - -//Useful for converting DOM supplied RGBs back to object hex values -function rgbToHex(rgb) { - rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); - function hex(x) { - return ("0" + parseInt(x).toString(16)).slice(-2); - } - return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]); -} - -let fa, faCopy; -QUnit.begin(() => { - let individualID = 'mock'; - fa = new ForceLayoutAbstract(individualID); -}); - -//setupGraph() - Wrapper function, not tested - -QUnit.module('setForces()', () => { - QUnit.test('Default forces', t => { - fa.setForces(); - t.ok(fa.forces.force('link')); - t.ok(fa.forces.force('charge')); - t.ok(fa.forces.force('collision')); - t.ok(fa.forces.force('center')); - }); -}); - -let copyFaObj = {'beforeEach': () => - faCopy = Object.assign(Object.create(Object.getPrototypeOf(fa)), fa) }; -let defineArrowsEventHooks = Object.assign(copyFaObj, {'afterEach': () => $('#test').empty()}); -QUnit.module('defineArrows()', defineArrowsEventHooks, () => { - QUnit.test('Familial Link', t => { - let svg = d3.select('#test'); - let linkData = [{'linkId': 0, 'type': 'familial'}]; - let mockRadius = 1; - faCopy.getLinkTarget = () => { - let data = {'data': {'r': mockRadius }}; - return data; - } - let mockColor = '#ff0000' - faCopy.getLinkColor = () => mockColor; - faCopy.defineArrows(svg, linkData); - t.equal($('#test defs marker').attr('id'), - 'arrow' + linkData[0].linkId + ':' + faCopy.graphId); - t.equal($('#test defs marker').attr('refX'), mockRadius); - t.equal($('#test defs marker').attr('refY'), 0); - t.equal($('#test defs marker').attr('markerWidth'), faCopy.markerWidth); - t.equal($('#test defs marker').attr('markerHeight'), faCopy.markerHeight); - t.equal($('#test defs marker').attr('orient'), 'auto'); - t.equal($('#test defs marker path').attr('fill'), mockColor); - }); - - QUnit.test('Member Link', t => { - let svg = d3.select('#test'); - let linkData = [{'type': 'member'}]; - faCopy.defineArrows(svg, linkData); - t.equal($('#test defs').children().length, 0); - }); -}); - -//updateGraph() - Wrapper function, not tested - -QUnit.module('applyForces()', () => { - QUnit.test('Default forces', t => { - let linkData = []; - let nodeData = []; - fa.forces = d3.forceSimulation().force('link', d3.forceLink()); - fa.applyForces(linkData, nodeData); - t.ok(fa.forces.on('tick')); - t.ok(fa.forces.alpha()); - t.ok(fa.alpha < 1); - }); -}); - -QUnit.module('ticked()', () => { - QUnit.test('Valid tick', t => { - let source = {'x': 0, 'y': 0}; - let target = {'x': 1, 'y': 1}; - let links = {'x1': 0, 'y1': 0, 'x2': 0, 'y2': 0, - 'source': source, 'target': target }; - let nodes = {'x': 0, 'y': 0 }; - fa.links = links; - fa.links.attr = (field, valueFunc) => { - fa.links[field] = valueFunc(fa.links); - return fa.links; - } - fa.nodes = nodes; - fa.nodes.attr = (field, valueFunc) => { - fa.nodes[field] = valueFunc(fa.nodes); - return fa.nodes; - } - fa.ticked(fa); - t.equal(fa.links.x1, source.x); - t.equal(fa.links.y1, source.y); - t.equal(fa.links.x2, target.x); - t.equal(fa.links.y2, target.y); - }); -}); - -//enableNodeInteraction() - Wrapper function, not tested - -QUnit.module('dragStarted()', {'beforeEach': () => d3.event = {} }, () => { - //Note - Heat refers to the energy (movement) of the graph - QUnit.test('Viable low-heat drag', t => { - d3.event = {'x': 1, 'y': 1}; - let d = {'filtered': false}; - fa.forces = d3.forceSimulation().alphaTarget(0); - fa.dragStarted(d); - t.ok(fa.forces.alphaTarget() > 0); - t.ok(d.fx, d3.event.x); - t.ok(d.fy, d3.event.y); - }); - - QUnit.test('Viable high-heat drag', t => { - d3.event = {'x': 1, 'y': 1, 'active': true}; - let d = {'filtered': false}; - fa.forces = d3.forceSimulation().alphaTarget(0); - fa.dragStarted(d); - t.equal(fa.forces.alphaTarget(), 0); - t.ok(d.fx, d3.event.x); - t.ok(d.fy, d3.event.y); - }); - - QUnit.test('Key binding detected', t => { - d3.event = {'x': 1, 'y': 1, 'ctrlKey': true}; - let d = {'filtered': false}; - fa.forces = d3.forceSimulation().alphaTarget(0); - fa.dragStarted(d); - t.equal(fa.forces.alphaTarget(), 0); - t.notOk(d.fx); - t.notOk(d.fy); - }); - - QUnit.test('Filtered node', t => { - d3.event = {'x': 1, 'y': 1}; - let d = {'filtered': true}; - fa.forces = d3.forceSimulation().alphaTarget(0); - fa.dragStarted(d); - t.equal(fa.forces.alphaTarget(), 0); - t.notOk(d.fx); - t.notOk(d.fy); - }); -}); - -QUnit.module('dragged()', {'beforeEach': () => d3.event = {} }, () => { - //Note - Heat refers to the energy (movement) of the graph - QUnit.test('Viable low-heat drag', t => { - d3.event = {'x': 1, 'y': 1}; - let d = {'filtered': false}; - fa.dragged(d); - t.ok(d.fx, d3.event.x); - t.ok(d.fy, d3.event.y); - }); - - QUnit.test('Viable high-heat drag', t => { - d3.event = {'x': 1, 'y': 1, 'active': true}; - let d = {'filtered': false}; - fa.dragged(d); - t.ok(d.fx, d3.event.x); - t.ok(d.fy, d3.event.y); - }); - - QUnit.test('Key binding detected', t => { - d3.event = {'x': 1, 'y': 1, 'ctrlKey': true}; - let d = {'filtered': false}; - fa.dragged(d); - t.notOk(d.fx); - t.notOk(d.fy); - }); - - QUnit.test('Filtered node', t => { - d3.event = {'x': 1, 'y': 1}; - let d = {'filtered': true}; - fa.dragged(d); - t.notOk(d.fx); - t.notOk(d.fy); - }); -}); - -let releaseNodeEventHooks = { - 'beforeEach': () => $('#test').empty(), - 'after': () => $('#test').empty(), -}; -QUnit.module('dragEnded()', releaseNodeEventHooks, () => { - //Note - Heat refers to the energy (movement) of the graph - QUnit.test('Viable low-heat drag', t => { - d3.event = {}; - let d = {'filtered': false}; - let node = d3.select('#test').append('circle') - .style('fill', 'red'); - fa.forces = d3.forceSimulation().alphaTarget(0.5); - fa.dragEnded(d, '#test'); - t.equal(rgbToHex($('#test circle').css('fill')), fa.fixedNodeColor); - t.equal(fa.forces.alphaTarget(), 0); - }); - - QUnit.test('Viable high-heat drag', t => { - d3.event = {'active': true}; - let d = {'filtered': false}; - let node = d3.select('#test').append('circle') - .style('fill', 'red'); - fa.forces = d3.forceSimulation().alphaTarget(0.5); - fa.dragEnded(d, '#test'); - t.equal(rgbToHex($('#test circle').css('fill')), fa.fixedNodeColor); - t.equal(fa.forces.alphaTarget(), 0.5); - }); - - QUnit.test('Key binding detected', t => { - d3.event = {'ctrlKey': true}; - let d = {'filtered': false}; - let node = d3.select('#test').append('circle') - .style('fill', '#ff0000'); - fa.forces = d3.forceSimulation().alphaTarget(0.5); - fa.dragEnded(d, '#test'); - t.equal(rgbToHex($('#test circle').css('fill')), '#ff0000') - t.equal(fa.forces.alphaTarget(), 0.5); - }); - - QUnit.test('Filtered node', t => { - d3.event = {}; - let d = {'filtered': true}; - let node = d3.select('#test').append('circle') - .style('fill', '#ff0000'); - fa.forces = d3.forceSimulation().alphaTarget(0.5); - fa.dragEnded(d, '#test'); - t.equal(rgbToHex($('#test circle').css('fill')), '#ff0000') - t.equal(fa.forces.alphaTarget(), 0.5); - }); -}); - -QUnit.module('releaseNode()', releaseNodeEventHooks, () => { - QUnit.test('Fixed node', t => { - let d = {'fx': 1, 'fy': 2} - let node = d3.select('#test').append('circle') - .style('fill', 'red'); - fa.releaseNode(d, '#test'); - t.equal(d.fx, null); - t.equal(d.fy, null); - t.equal(rgbToHex($('#test circle').css('fill')), fa.defNodeColor); - }); -}); - -let resetGraphEventHooks = Object.assign(copyFaObj, {'afterEach': () => $('#test').empty()}); -QUnit.module('resetGraph()', resetGraphEventHooks, () => { - QUnit.test('Full reset', t => { - faCopy.filtered = {'test': true}; - let nodes = [{'filtered': true}]; - faCopy.svg = d3.select('#test'); - faCopy.svg.data(nodes).append('g') - .attr('class', 'node'); - faCopy.updateGraph = () => faCopy.updated = true; - faCopy.nodeData = nodes - faCopy.resetGraph(); - t.equal(Object.keys(faCopy.filtered.test), 0); - t.equal($('.node').length, 0); - t.ok(faCopy.updated); - nodes.forEach(node => t.ok(!node.filtered)) - }); -}); - -QUnit.module('isAssignedKeyBinding()', {'beforeEach': () => d3.event = {} }, () => { - QUnit.test('shiftKey', t => { - d3.event.shiftKey = true; - t.ok(fa.isAssignedKeyBinding()); - }); - - QUnit.test('ctrlKey', t => { - d3.event.sourceEvent = {'ctrlKey': true }; - t.ok(fa.isAssignedKeyBinding()); - }); - - QUnit.test('No key', t => { - t.notOk(fa.isAssignedKeyBinding()); - }); -}); - -QUnit.module('shiftKey()', {'beforeEach': () => d3.event = {} }, () => { - QUnit.test('Event shiftKey', t => { - d3.event.shiftKey = true; - t.ok(fa.shiftKey()); - }); - - QUnit.test('Source event shiftKey', t => { - d3.event.sourceEvent = {'shiftKey': true }; - t.ok(fa.shiftKey()); - }); - - QUnit.test('No shiftKey', t => { - t.notOk(fa.shiftKey()); - }); -}); - -QUnit.module('ctrlKey()', {'beforeEach': () => d3.event = {} }, () => { - QUnit.test('Event ctrlKey', t => { - d3.event.ctrlKey = true; - t.ok(fa.ctrlKey()); - }); - - QUnit.test('Source event ctrlKey', t => { - d3.event.sourceEvent = {'ctrlKey': true }; - t.ok(fa.ctrlKey()); - }); - - QUnit.test('No ctrlKey', t => { - t.notOk(fa.ctrlKey()); - }); -}); - -QUnit.module('getLinkTarget()', () => { - QUnit.test('Valid target', t => { - let link = {'target': 'c'}; - fa.nodeData = [{'id': 'a'}, {'id': 'b'}, {'id': 'c'}]; - let targetNode = fa.getLinkTarget(link); - t.equal(targetNode, fa.nodeData[2]); - }); - - QUnit.test('Invalid target', t => { - let link = {'target': 'b'}; - fa.nodeData = [{'id': '1'}, {'id': '2'}, {'id': '3'}]; - let targetNode = fa.getLinkTarget(link); - t.equal(targetNode, undefined); - }); -}); - -QUnit.module('getLinkSource()', () => { - QUnit.test('Valid source', t => { - let link = {'source': 'b'}; - fa.nodeData = [{'id': 'a'}, {'id': 'b'}, {'id': 'c'}]; - let srcNode = fa.getLinkSource(link); - t.equal(srcNode, fa.nodeData[1]); - }); - - QUnit.test('Invalid source', t => { - let link = {'source': 'a'}; - fa.nodeData = [{'id': '1'}, {'id': '2'}, {'id': '3'}]; - let srcNode = fa.getLinkSource(link); - t.equal(srcNode, undefined); - }); -}); diff --git a/src/main/webapp/javascript/tests/graphAbstract_test.js b/src/main/webapp/javascript/tests/graphAbstract_test.js deleted file mode 100644 index e089aac6d3..0000000000 --- a/src/main/webapp/javascript/tests/graphAbstract_test.js +++ /dev/null @@ -1,296 +0,0 @@ -QUnit.module('Abstract Graph Interface'); - -let ga, gaCopy; -QUnit.begin(() => { - let individualID = 'mock'; - ga = new GraphAbstract(individualID); -}); - -let terracedTestEventHooks = { - 'before': () => { - $('#test').append('
' + - ''); - }, - 'after': () => $('#test').empty() -}; -QUnit.module('showTable()', terracedTestEventHooks, () => { - QUnit.test('Display table', t => { - ga.showTable('#testA', '#testB'); - t.ok($('#testA').is(':hidden')); - t.ok(!$('#testA').hasClass('active')); - t.ok($('#testB').is(':visible')); - t.ok($('#testB').hasClass('active')); - }); -}); - -//setupGraph() - Wrapper function, not tested - -QUnit.module('addSvg()', {'after': () => $('#test').empty() }, () => { - QUnit.test('Append SVG', t => { - ga.addSvg('#test'); - t.equal($('.container').attr('width'), ga.width); - t.equal($('.container').attr('height'), ga.height); - t.ok($('.container').has('g')) - }); -}); - -QUnit.module('addTooltip()', {'after': () => $('#test').empty() }, () => { - QUnit.test('Append tooltip', t => { - ga.addTooltip('#test'); - t.ok(ga.tooltip); - t.equal($('.tooltip').css('opacity'), 0); - }); -}); - - -QUnit.module('updateNodeOutlines()', {'after': () => $('#test').empty() }, () => { - QUnit.test('Create Node', t => { - let data = [{'data': {'name': 'a'}}]; - let mockedNodes = d3.select('#test').append('g').data(data); - ga.updateNodeOutlines(mockedNodes, mockedNodes); - t.equal($('#test circle').attr('r'), ga.startingRadius); - t.ok($('#test circle').css('fill')); - t.ok($('#test circle').css('stroke')); - t.ok($('#test circle').css('stroke-width')); - }); -}); - -QUnit.module('colorGender()', () => { - function validateColor(test, color, colorRef) { - test.strictEqual(color, colorRef); - } - - QUnit.test('Male nodes', t => { - let d = {'data': {'gender': 'male'}}; - let color = ga.colorGender(d); - validateColor(t, color, ga.maleColor); - }); - - QUnit.test('Female nodes', t => { - let d = {'data': {'gender': 'female'}}; - let color = ga.colorGender(d); - validateColor(t, color, ga.femaleColor); - }); - - QUnit.test('Default gender nodes', t => { - let d = {'data': {}}; - let color = ga.colorGender(d); - validateColor(t, color, ga.defGenderColor); - }); -}); - -QUnit.module('updateNodeSymbols()', {'after': $('#test').empty() }, () => { - QUnit.test('Add symbol', t => { - let data = [{'data': {'name': 'a'}}]; - let mockedNodes = d3.select('#test').append('g').data(data); - ga.updateNodeSymbols(mockedNodes, mockedNodes); - t.ok($('.symb').attr('d')); - t.equal($('.symb').attr('fill'), this.alphaColor); - t.equal($('.symb').css('fill-opacity'), 0); - }); -}); - -QUnit.module('updateNodeText()', {'after': $('#test').empty() }, () => { - QUnit.test('Add text', t => { - let data = [{'data': {'name': 'a'}}]; - let mockedNodes = d3.select('#test').append('g').data(data); - ga.updateNodeText(mockedNodes, mockedNodes); - t.equal($('.text').text(), data[0].data.name); - }); -}); - -QUnit.module('wheelDelta()', {'before': () => d3.event = {'deltaY': 0, 'deltaMode': 1}}, () => { - QUnit.test('Zoom unchanged', t => { - d3.event.deltaY = 0; - let delta = ga.wheelDelta(); - t.equal(delta, 0); - }); - - QUnit.test('Zooming in', t => { - d3.event.deltaY = 1; - let delta = ga.wheelDelta(); - t.ok(delta < 0); - }); - - QUnit.test('Zooming out', t => { - d3.event.deltaY = -1; - let delta = ga.wheelDelta(); - t.ok(delta > 0); - }); -}); - -QUnit.module('incompleteInfoMessage()', {'after': () => $('#test').empty() }, () => { - QUnit.test('Display message', t => { - ga.incompleteInfoMessage('#test'); - t.equal($('#incompleteInfoMsg').text(), 'There are currently no known relationships ' + - 'for this Marked Individual'); - }); -}); - -QUnit.module('setNodeRadius()', () => { - QUnit.test('Empyt node list', t => { - let nodes = []; - ga.setNodeRadius(nodes, nodes); - t.equal(nodes.length, 0); - }); - - QUnit.test('List of length 2', t => { - let nodes = [{'data': {} }, {'data': {} }]; - ga.setNodeRadius(nodes, nodes); - nodes.forEach(d => t.equal(d.data.r, ga.radius)); - }); -}); - -QUnit.module('calcNodeSize()', {'beforeEach': () => ga.radius = null}, () => { - function checkRadius(test, ga) { - test.ok(ga.radius < ga.maxRadius); - test.ok(ga.radius > 0); - } - - QUnit.test('Empty node list', t => { - let nodes = []; - let radius = ga.calcNodeSize(nodes); - checkRadius(t, ga); - }); - - QUnit.test('Reasonable node list (5)', t => { - let nodes = {'length': 5}; - let radius = ga.calcNodeSize(nodes); - checkRadius(t, ga); - }); - - QUnit.test('Large node list (1000)', t => { - let nodes = {'length': 1000}; - let radius = ga.calcNodeSize(nodes); - checkRadius(t, ga); - }); - - QUnit.test('Non-list entries', t => { - let nodes = null; - let radius = ga.calcNodeSize(nodes); - t.notOk(ga.radius) - }); -}); - -QUnit.module('getLinkColor()', () => { - QUnit.test('Familial link', t => { - let d = {'type': 'familial'}; - let color = ga.getLinkColor(d); - t.equal(color, ga.famLinkColor); - }); - - QUnit.test('Paternal link', t => { - let d = {'type': 'paternal'}; - let color = ga.getLinkColor(d); - t.equal(color, ga.paternalLinkColor); - }); - - QUnit.test('Maternal link', t => { - let d = {'type': 'maternal'}; - let color = ga.getLinkColor(d); - t.equal(color, ga.maternalLinkColor); - }); - - QUnit.test('Default link', t => { - let d = {'type': 'default'}; - let color = ga.getLinkColor(d); - t.equal(color, ga.defLinkColor); - }); - - QUnit.test('Null entry', t => { - let d = null; - let color = ga.getLinkColor(d); - t.equal(color, ga.defLinkColor); - }); -}); - -QUnit.module('getSizeScalar()', () => { - QUnit.test('Focused node', t => { - let d = {'data': {'isFocused': true }}; - let scalar = ga.getSizeScalar(d); - t.equal(scalar, ga.focusedScale); - }); - - QUnit.test('Unfocused node', t => { - let d = {'data': {'isFocused': false }}; - let scalar = ga.getSizeScalar(d); - t.equal(scalar, ga.focusedScale); - }); - - QUnit.test('Null entry', t => { - let d = null; - let scalar = ga.getSizeScalar(d); - t.equal(scalar, ga.focusedScale); - }); -}); - -let handleMouseEventHooks = { - 'beforeEach': () => { - gaCopy = Object.assign(Object.create(Object.getPrototypeOf(ga)), ga); - gaCopy.addTooltip('#test'); - gaCopy.displayNodeTooltip = (d) => gaCopy.tooltipType = "node"; - gaCopy.displayLinkTooltip = (d) => gaCopy.tooltipType = "link" - d3.event = {'layerX': 0, 'layerY': 0}; - }, - 'afterEach': () => $('#test').empty() -} -QUnit.module('handleMouseOver()', handleMouseEventHooks, () => { - QUnit.test('Entering node', t => { - gaCopy.popup = false; - gaCopy.handleMouseOver({}, "node"); - t.ok(gaCopy.popup); - }); - - QUnit.test('Inside node', t => { - gaCopy.popup = true; - gaCopy.handleMouseOver({}, "node"); - t.ok(gaCopy.popup); - t.equal($('.tooltip').css('opacity'), 0) - }); - - QUnit.test('Entering link', t => { - gaCopy.popup = false; - gaCopy.handleMouseOver({}, "link"); - t.ok(gaCopy.popup); - }); - - QUnit.test('Inside link', t => { - gaCopy.popup = true; - gaCopy.handleMouseOver({}, "link"); - t.ok(gaCopy.popup); - t.equal($('.tooltip').css('opacity'), 0) - }); -}); - - -let displayNodeEventHooks = { - 'beforeEach': () => { - gaCopy = Object.assign(Object.create(Object.getPrototypeOf(ga)), ga); - $('.tooltip').remove(); - gaCopy.addTooltip('#test'); - d3.event = {'layerX': 0, 'layerY': 0}; - } -} -QUnit.module('displayNodeTooltip()', displayNodeEventHooks, () => { - QUnit.test('Valid Text', t => { - gaCopy.generateNodeTooltipHtml = (d) => true; - gaCopy.displayNodeTooltip({}); - t.ok($('.tooltip').css('left')); - t.ok($('.tooltip').css('top')); - t.ok($('.tooltip').css('background-color')); - t.ok($('.tooltip').html()); - }); - - QUnit.test('Invalid text', t => { - gaCopy.generateNodeTooltipHtml = (d) => false; - gaCopy.displayNodeTooltip({}); - t.equal($('.tooltip').html(), ""); - }); -}); - -QUnit.module('handleMouseOut()', handleMouseEventHooks, () => { - QUnit.test('Exiting node', t => { - ga.handleMouseOut(); - t.ok(!ga.popup); - }); -}); diff --git a/src/main/webapp/javascript/tests/jsonParser_test.js b/src/main/webapp/javascript/tests/jsonParser_test.js deleted file mode 100644 index 5ba837e5cf..0000000000 --- a/src/main/webapp/javascript/tests/jsonParser_test.js +++ /dev/null @@ -1,147 +0,0 @@ -QUnit.module('JSON Link/Node Parser'); - -let jp, jpCopy; -QUnit.begin(() => { - jp = new JSONParser(null, false, -1, false, true); -}); - -cloneJP = () => Object.assign(Object.create(Object.getPrototypeOf(jp)), jp); - -//parseJSON() - Wrapper function, not tested - -querySetup = { - 'beforeEach': () => { - jpCopy = cloneJP(); - jpCopy.queryData = (name, query, isDict) => query; - jpCopy.globals = {"baseUrl": ""}; - } -}; -QUnit.module('queryNodeData()', querySetup, () => { - QUnit.test('Local files', t => { - jpCopy.localFiles = true; - query = jpCopy.queryNodeData(); - t.ok(query.includes(".json")) - }); - QUnit.test('Non-local files', t => { - jpCopy.localFiles = false; - query = jpCopy.queryNodeData(); - t.ok(query.includes("SELECT")) - }); -}); - -QUnit.module('queryRelationshipData()', querySetup, () => { - QUnit.test('Local files', t => { - jpCopy.globals = {"baseUrl": ""}; - jpCopy.localFiles = true; - query = jpCopy.queryNodeData(); - t.ok(query.includes(".json")) - }); - QUnit.test('Non-local Files', t => { - jpCopy.globals = {"baseUrl": ""}; - jpCopy.localFiles = false; - query = jpCopy.queryNodeData(); - t.ok(query.includes("SELECT")) - }); -}); - - -//queryData() - d3.js wrapper, not tested - -QUnit.module('storeQueryAsDict()', {"beforeEach": () => jpCopy = cloneJP() }, () => { - QUnit.test('Empty JSON', t => { - jpCopy.storeQueryAsDict({}, "A", () => true); - t.equal(JSONParser["A"], undefined) - }); - QUnit.test('Valid JSON', t => { - jpCopy.storeQueryAsDict([{"individualID": "b"}], "B", () => true); - t.equal(JSONParser["B"]["b"]["individualID"], "b") - }); -}); - -setupMap = { - "beforeEach": () => { - JSONParser.relationshipData = [{"markedIndividualName1": "a", "markedIndividualName2": "b"}] - jpCopy = cloneJP(); - jpCopy.getRelationType = (el) => "type"; - } -} -QUnit.module('mapRelationships()', setupMap, () => { - QUnit.test('Empty relationships', t => { - JSONParser.relationshipData = []; - let relations = jpCopy.mapRelationships(); - t.deepEqual(relations, {}); - }); - QUnit.test('Valid relationships', t => { - let nodes = {"a": {}, "b": {}}; - let relations = jpCopy.mapRelationships(nodes); - t.equal(relations["a"][0]["name"], "b"); - t.equal(relations["b"][0]["name"], "a"); - }); - QUnit.test('Multi-mapped relationships', t => { - let nodes = {"a": {}, "b": {}}; - JSONParser.relationshipData.push({"markedIndividualName1": "a", - "markedIndividualName2": "b"}); - let relations = jpCopy.mapRelationships(nodes); - t.equal(relations["a"].length, 2); - t.equal(relations["b"].length, 2); - t.equal(relations["a"][0]["name"], "b"); - t.equal(relations["b"][1]["name"], "a"); - }); - -}); - -QUnit.module('getLinkId()', () => { - QUnit.test('Unique IDs', t => { - let ids = []; - for (let i = 0; i < 5; i++) { - ids[i] = jp.getLinkId(); - } - t.ok(ids.length === (new Set(ids)).size) - }); -}); - -QUnit.module('getNodeId()', () => { - QUnit.test('Unique IDs', t => { - let ids = []; - for (let i = 0; i < 5; i++) { - ids[i] = jp.getNodeId(); - } - t.ok(ids.length === (new Set(ids)).size) - }); -}); - -QUnit.module('updateNodeData()', () => { - QUnit.test('Valid input', t => { - let node = {}; - let updatedNode = jp.updateNodeData(node, 1, 2, 3); - t.equal(updatedNode.id, 2); - t.equal(updatedNode.group, 1); - t.equal(updatedNode.depth, 3); - }); -}); - -QUnit.module('getRelationType()', () => { - QUnit.test('Maternal relation', t => { - let link = {"markedIndividualRole1": "mother", "markedIndivdiualRole2": null} - t.equal(jp.getRelationType(link)[0], "maternal") - }); - - QUnit.test('Paternal relation', t => { - let link = {"markedIndividualRole1": null, "markedIndividualRole2": "father"} - t.equal(jp.getRelationType(link)[0], "paternal") - }); - - QUnit.test('Calf relation', t => { - let link = {"markedIndividualRole1": "calf", "markedIndivdiualRole2": "calf"} - t.equal(jp.getRelationType(link)[0], "familial") - }); - - QUnit.test('Member relation', t => { - let link = {"markedIndividualRole1": null, "markedIndivdiualRole2": null} - t.equal(jp.getRelationType(link)[0], "member") - }); - - QUnit.test('Null relation', t => { - t.equal(jp.getRelationType(null)[0], "member") - }); -}); diff --git a/src/main/webapp/javascript/tests/test.html b/src/main/webapp/javascript/tests/test.html deleted file mode 100644 index d4b20d7f3a..0000000000 --- a/src/main/webapp/javascript/tests/test.html +++ /dev/null @@ -1,33 +0,0 @@ - - - - - -