From 21d9c87b344598c457ae01b872b85c033a5e043f Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Sun, 12 Jan 2020 23:05:32 +0200 Subject: fix tests --- .../services/style_setter/style_setter.spec.js | 79 ---------------------- .../specs/services/theme_data/theme_data.spec.js | 79 ++++++++++++++++++++++ 2 files changed, 79 insertions(+), 79 deletions(-) delete mode 100644 test/unit/specs/services/style_setter/style_setter.spec.js create mode 100644 test/unit/specs/services/theme_data/theme_data.spec.js (limited to 'test') diff --git a/test/unit/specs/services/style_setter/style_setter.spec.js b/test/unit/specs/services/style_setter/style_setter.spec.js deleted file mode 100644 index 7f789124..00000000 --- a/test/unit/specs/services/style_setter/style_setter.spec.js +++ /dev/null @@ -1,79 +0,0 @@ -import { getLayersArray, topoSort } from 'src/services/style_setter/style_setter' - -describe('getLayersArray', () => { - const fixture = { - layer1: null, - layer2: 'layer1', - layer3a: 'layer2', - layer3b: 'layer2' - } - - it('should expand layers properly (3b)', () => { - const out = getLayersArray('layer3b', fixture) - expect(out).to.eql(['layer1', 'layer2', 'layer3b']) - }) - - it('should expand layers properly (3a)', () => { - const out = getLayersArray('layer3a', fixture) - expect(out).to.eql(['layer1', 'layer2', 'layer3a']) - }) - - it('should expand layers properly (2)', () => { - const out = getLayersArray('layer2', fixture) - expect(out).to.eql(['layer1', 'layer2']) - }) - - it('should expand layers properly (1)', () => { - const out = getLayersArray('layer1', fixture) - expect(out).to.eql(['layer1']) - }) -}) - -describe('topoSort', () => { - const fixture1 = { - layerA: [], - layer1A: ['layerA'], - layer2A: ['layer1A'], - layerB: [], - layer1B: ['layerB'], - layer2B: ['layer1B'], - layer3AB: ['layer2B', 'layer2A'] - } - - // Same thing but messed up order - const fixture2 = { - layer1A: ['layerA'], - layer1B: ['layerB'], - layer2A: ['layer1A'], - layerB: [], - layer3AB: ['layer2B', 'layer2A'], - layer2B: ['layer1B'], - layerA: [] - } - - it('should make a topologically sorted array', () => { - const out = topoSort(fixture1, (node, inheritance) => inheritance[node]) - // This basically checks all ordering that matters - expect(out.indexOf('layerA')).to.be.below(out.indexOf('layer1A')) - expect(out.indexOf('layer1A')).to.be.below(out.indexOf('layer2A')) - expect(out.indexOf('layerB')).to.be.below(out.indexOf('layer1B')) - expect(out.indexOf('layer1B')).to.be.below(out.indexOf('layer2B')) - expect(out.indexOf('layer2A')).to.be.below(out.indexOf('layer3AB')) - expect(out.indexOf('layer2B')).to.be.below(out.indexOf('layer3AB')) - }) - - it('order in object shouldn\'t matter', () => { - const out = topoSort(fixture2, (node, inheritance) => inheritance[node]) - // This basically checks all ordering that matters - expect(out.indexOf('layerA')).to.be.below(out.indexOf('layer1A')) - expect(out.indexOf('layer1A')).to.be.below(out.indexOf('layer2A')) - expect(out.indexOf('layerB')).to.be.below(out.indexOf('layer1B')) - expect(out.indexOf('layer1B')).to.be.below(out.indexOf('layer2B')) - expect(out.indexOf('layer2A')).to.be.below(out.indexOf('layer3AB')) - expect(out.indexOf('layer2B')).to.be.below(out.indexOf('layer3AB')) - }) - it('ignores cyclic dependencies', () => { - const out = topoSort({ a: 'b', b: 'a', c: 'a' }, (node, inheritance) => inheritance[node]) - expect(out.indexOf('a')).to.be.below(out.indexOf('c')) - }) -}) diff --git a/test/unit/specs/services/theme_data/theme_data.spec.js b/test/unit/specs/services/theme_data/theme_data.spec.js new file mode 100644 index 00000000..507905eb --- /dev/null +++ b/test/unit/specs/services/theme_data/theme_data.spec.js @@ -0,0 +1,79 @@ +import { getLayersArray, topoSort } from 'src/services/theme_data/theme_data.service.js' + +describe('getLayersArray', () => { + const fixture = { + layer1: null, + layer2: 'layer1', + layer3a: 'layer2', + layer3b: 'layer2' + } + + it('should expand layers properly (3b)', () => { + const out = getLayersArray('layer3b', fixture) + expect(out).to.eql(['layer1', 'layer2', 'layer3b']) + }) + + it('should expand layers properly (3a)', () => { + const out = getLayersArray('layer3a', fixture) + expect(out).to.eql(['layer1', 'layer2', 'layer3a']) + }) + + it('should expand layers properly (2)', () => { + const out = getLayersArray('layer2', fixture) + expect(out).to.eql(['layer1', 'layer2']) + }) + + it('should expand layers properly (1)', () => { + const out = getLayersArray('layer1', fixture) + expect(out).to.eql(['layer1']) + }) +}) + +describe('topoSort', () => { + const fixture1 = { + layerA: [], + layer1A: ['layerA'], + layer2A: ['layer1A'], + layerB: [], + layer1B: ['layerB'], + layer2B: ['layer1B'], + layer3AB: ['layer2B', 'layer2A'] + } + + // Same thing but messed up order + const fixture2 = { + layer1A: ['layerA'], + layer1B: ['layerB'], + layer2A: ['layer1A'], + layerB: [], + layer3AB: ['layer2B', 'layer2A'], + layer2B: ['layer1B'], + layerA: [] + } + + it('should make a topologically sorted array', () => { + const out = topoSort(fixture1, (node, inheritance) => inheritance[node]) + // This basically checks all ordering that matters + expect(out.indexOf('layerA')).to.be.below(out.indexOf('layer1A')) + expect(out.indexOf('layer1A')).to.be.below(out.indexOf('layer2A')) + expect(out.indexOf('layerB')).to.be.below(out.indexOf('layer1B')) + expect(out.indexOf('layer1B')).to.be.below(out.indexOf('layer2B')) + expect(out.indexOf('layer2A')).to.be.below(out.indexOf('layer3AB')) + expect(out.indexOf('layer2B')).to.be.below(out.indexOf('layer3AB')) + }) + + it('order in object shouldn\'t matter', () => { + const out = topoSort(fixture2, (node, inheritance) => inheritance[node]) + // This basically checks all ordering that matters + expect(out.indexOf('layerA')).to.be.below(out.indexOf('layer1A')) + expect(out.indexOf('layer1A')).to.be.below(out.indexOf('layer2A')) + expect(out.indexOf('layerB')).to.be.below(out.indexOf('layer1B')) + expect(out.indexOf('layer1B')).to.be.below(out.indexOf('layer2B')) + expect(out.indexOf('layer2A')).to.be.below(out.indexOf('layer3AB')) + expect(out.indexOf('layer2B')).to.be.below(out.indexOf('layer3AB')) + }) + it('ignores cyclic dependencies', () => { + const out = topoSort({ a: 'b', b: 'a', c: 'a' }, (node, inheritance) => inheritance[node]) + expect(out.indexOf('a')).to.be.below(out.indexOf('c')) + }) +}) -- cgit v1.2.3-70-g09d2