From 9a6c9e77c1a1c81a9008580d179111aa939d8ace Mon Sep 17 00:00:00 2001 From: dodget Date: Fri, 18 Oct 2019 13:11:20 -0400 Subject: [PATCH 1/2] Testing TimeExplorer class. --- SpecRunner.html | 10 ++++++++++ js/TimeExplorerSpec.js | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/SpecRunner.html b/SpecRunner.html index eeb9098..913c327 100644 --- a/SpecRunner.html +++ b/SpecRunner.html @@ -2,10 +2,20 @@ Testing with Jasmine + + + + + + + + + + diff --git a/js/TimeExplorerSpec.js b/js/TimeExplorerSpec.js index e448c5e..fc7b6c4 100644 --- a/js/TimeExplorerSpec.js +++ b/js/TimeExplorerSpec.js @@ -64,3 +64,39 @@ describe('Testing the functions of the TimeExplorer file', ()=>{ }) }) + +describe('Testing the TimeExplorer class', () => { + let div; + + beforeEach( ()=> { + div = document.createElement('div'); + div.setAttribute("id", "timeline"); + document.body.appendChild(div); + }); + + afterEach( ()=> { + div.remove(); + div = null; + }); + + it('TimeExplorer should have options after initialization', ()=> { + const api_key = "AIzaSyCA8GIsjw-QL-CC1v6fgDWmDyyhRM_ZESE" + let explorer = new TimeExplorer(api_key); + expect(explorer.options.timelineOptions.height).toEqual(window.innerHeight); + }) + + it('TimeExplorer.get_tag_col() should return "Tags"', ()=> { + const api_key = "AIzaSyCA8GIsjw-QL-CC1v6fgDWmDyyhRM_ZESE" + let explorer = new TimeExplorer(api_key); + expect(explorer.get_tag_col()).toEqual('Tags'); + }) + + it('TimeExplorer.set_options() should extend options', ()=> { + const api_key = "AIzaSyCA8GIsjw-QL-CC1v6fgDWmDyyhRM_ZESE" + let explorer = new TimeExplorer(api_key, options=["Joe"]); + let r = explorer.set_options(["Joe"]) + expect(r.timelineOptions['0']).toEqual("Joe"); + }) + + +}) From 975dff930fcb48221fb8ad5942b85b4bf0096100 Mon Sep 17 00:00:00 2001 From: dodget Date: Fri, 18 Oct 2019 14:15:21 -0400 Subject: [PATCH 2/2] Refactor tests. --- js/TimeExplorerSpec.js | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/js/TimeExplorerSpec.js b/js/TimeExplorerSpec.js index fc7b6c4..d57caa0 100644 --- a/js/TimeExplorerSpec.js +++ b/js/TimeExplorerSpec.js @@ -1,12 +1,12 @@ -describe('Testing the functions of the TimeExplorer file', ()=>{ +describe('Testing the functions of the TimeExplorer file', ()=> { - it('zip_arrays should zip two arrays of equal length', ()=>{ + it('zip_arrays should zip two arrays of equal length', ()=> { const arr1 = ["Joan", "Bill", "Bob"]; const arr2 = [1,2,3]; expect(zip_arrays(arr1,arr2)).toEqual({"Joan": 1, "Bill": 2, "Bob": 3}); }) - it('timeParse should parse AM time', ()=>{ + it('timeParse should parse AM time', ()=> { const times = [ "10:20", "10:20am", @@ -16,7 +16,7 @@ describe('Testing the functions of the TimeExplorer file', ()=>{ times.forEach( time => expect(timeParse(time)).toEqual([10,20])); }) - it('timeParse should parse PM time', ()=>{ + it('timeParse should parse PM time', ()=> { const times = [ "10:20pm", "10:20PM", @@ -67,6 +67,10 @@ describe('Testing the functions of the TimeExplorer file', ()=>{ describe('Testing the TimeExplorer class', () => { let div; + const api_key = "AIzaSyCA8GIsjw-QL-CC1v6fgDWmDyyhRM_ZESE"; + const new_explorer = () => { + return new TimeExplorer(api_key); + } beforeEach( ()=> { div = document.createElement('div'); @@ -80,23 +84,27 @@ describe('Testing the TimeExplorer class', () => { }); it('TimeExplorer should have options after initialization', ()=> { - const api_key = "AIzaSyCA8GIsjw-QL-CC1v6fgDWmDyyhRM_ZESE" - let explorer = new TimeExplorer(api_key); + explorer = new_explorer() expect(explorer.options.timelineOptions.height).toEqual(window.innerHeight); }) it('TimeExplorer.get_tag_col() should return "Tags"', ()=> { - const api_key = "AIzaSyCA8GIsjw-QL-CC1v6fgDWmDyyhRM_ZESE" - let explorer = new TimeExplorer(api_key); - expect(explorer.get_tag_col()).toEqual('Tags'); + explorer = new_explorer() + const tags = explorer.get_tag_col(); + expect(tags).toEqual('Tags'); }) it('TimeExplorer.set_options() should extend options', ()=> { - const api_key = "AIzaSyCA8GIsjw-QL-CC1v6fgDWmDyyhRM_ZESE" - let explorer = new TimeExplorer(api_key, options=["Joe"]); - let r = explorer.set_options(["Joe"]) + explorer = new_explorer() + const r = explorer.set_options(["Joe"]) expect(r.timelineOptions['0']).toEqual("Joe"); }) + it('TimeExplorer.slugify() should return a valid slug', ()=> { + explorer = new_explorer() + const slug = explorer.slugify("Let's make a slug"); + expect(slug).toEqual("Let_s_make_a_slug"); + }) + })