From 7a4979d0cfd4c4dbe91b53b69c62aa28c295af5c Mon Sep 17 00:00:00 2001 From: Saivan Date: Wed, 18 Apr 2018 20:55:06 +1000 Subject: Initial planning for the Timeline Module This commit just includes a few plans and a massive derrangement of the fx module before it is to be refactored into the Timeline module. The basic methods are included, but everything is broken --- spec/spec/circle.js | 2 +- spec/spec/queue.js | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 spec/spec/queue.js (limited to 'spec') diff --git a/spec/spec/circle.js b/spec/spec/circle.js index c0f0936..0f2c8f4 100644 --- a/spec/spec/circle.js +++ b/spec/spec/circle.js @@ -1,3 +1,4 @@ + describe('Circle', function() { var circle @@ -173,5 +174,4 @@ describe('Circle', function() { expect(window.matrixStringToArray(circle.node.getAttribute('transform'))).toEqual([1,0,0,1,12,12]) }) }) - }) diff --git a/spec/spec/queue.js b/spec/spec/queue.js new file mode 100644 index 0000000..738831c --- /dev/null +++ b/spec/spec/queue.js @@ -0,0 +1,111 @@ + +describe ('SVG.Queue()', function () { + + describe('first ()', function () { + + it('returns null if no item in the queue', function () { + var queue = new SVG.Queue() + expect(queue.first()).toEqual(null) + }) + + it ('returns the first value in the queue', function () { + var queue = new SVG.Queue() + queue.push(1) + expect(queue.first()).toBe(1) + queue.push(2) + expect(queue.first()).toBe(1) + }) + }) + + describe('last ()', function () { + + it ('returns null if no item in the queue', function () { + var queue = new SVG.Queue() + expect(queue.last()).toEqual(null) + }) + + it ('returns the last value added', function () { + var queue = new SVG.Queue() + queue.push(1) + expect(queue.last()).toBe(1) + queue.push(2) + expect(queue.last()).toBe(2) + }) + }) + + describe('push ()', function () { + + it ('adds an element to the end of the queue', function () { + var queue = new SVG.Queue() + queue.push(1) + queue.push(2) + queue.push(3) + + expect(queue.first()).toBe(1) + expect(queue.last()).toBe(3) + }) + + it ('changes the length when you add things', function () { + var queue = new SVG.Queue() + queue.push(1) + expect(queue.length).toBe(1) + queue.push(2) + expect(queue.length).toBe(2) + }) + }) + + describe('remove ()', function () { + it('removes an item from the queue which matches the matcher', function () { + var queue = new SVG.Queue() + queue.push(1) + queue.push(2) + queue.push(3) + + queue.remove(function(item) { + return item.value == 3 + }) + + expect(queue.length).toBe(2) + expect(queue.last()).toBe(2) + expect(queue.first()).toBe(1) + }) + + it('removes no item from the queue if nothing is matched', function () { + var queue = new SVG.Queue() + queue.push(1) + queue.push(2) + queue.push(3) + + queue.remove(function(item) { + return item.value == 4 + }) + + expect(queue.length).toBe(3) + expect(queue.last()).toBe(3) + expect(queue.first()).toBe(1) + }) + }) + + describe('shift ()', function () { + it('returns nothing if queue is empty', function () { + var queue = new SVG.Queue() + var val = queue.shift() + expect(val).toBeFalsy() + }) + + it('returns the first item of the queue and removes it', function () { + var queue = new SVG.Queue() + queue.push(1) + queue.push(2) + queue.push(3) + + var val = queue.shift() + + expect(queue.length).toBe(2) + expect(queue.last()).toBe(3) + expect(queue.first()).toBe(2) + + expect(val).toBe(1) + }) + }) +}) -- cgit v1.2.3