From 9b52843e3f2658684dd40c16b3a7a96a9a410092 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 21 Nov 2014 11:22:28 -0800 Subject: [PATCH] [Core] Update spec for TypeProvider Update spec for TypeProvider to handle changes to API for transition of platform/core; WTD-573. --- platform/core/src/types/TypeProvider.js | 2 +- platform/core/test/types/TypeProviderSpec.js | 169 +++++-------------- 2 files changed, 46 insertions(+), 125 deletions(-) diff --git a/platform/core/src/types/TypeProvider.js b/platform/core/src/types/TypeProvider.js index 34718d72ed..6a9c5964e9 100644 --- a/platform/core/src/types/TypeProvider.js +++ b/platform/core/src/types/TypeProvider.js @@ -150,7 +150,7 @@ define( /** * Get a specific type by name. * - * @param {string} key the key (machine-readable identifier) + * @param {string} [key] the key (machine-readable identifier) * for the type of interest * @returns {Promise} a * promise for a type object identified by this key. diff --git a/platform/core/test/types/TypeProviderSpec.js b/platform/core/test/types/TypeProviderSpec.js index 500f611a9c..9b36e70d8d 100644 --- a/platform/core/test/types/TypeProviderSpec.js +++ b/platform/core/test/types/TypeProviderSpec.js @@ -2,7 +2,7 @@ define( ['../../src/types/TypeProvider'], - function (typeProviderModule) { + function (TypeProvider) { "use strict"; describe("Type provider", function () { @@ -50,162 +50,83 @@ define( beforeEach(function () { captured = {}; - provider = typeProviderModule.instantiate({ - definitions: testTypeDefinitions - }); - }); - - it("can be instantiated from a factory method", function () { - expect(provider).toBeTruthy(); + provider = new TypeProvider(testTypeDefinitions); }); it("looks up non-inherited types by name", function () { - provider.getType('basic').then(capture('type')); + captured.type = provider.getType('basic'); - waitsFor( - function () { - return captured.type !== undefined; - }, - "promise resolution", - 250 - ); - runs(function () { - expect(captured.type.getGlyph()).toEqual("X"); - expect(captured.type.getName()).toEqual("Basic Type"); - expect(captured.type.getDescription()).toBeUndefined(); - }); + expect(captured.type.getGlyph()).toEqual("X"); + expect(captured.type.getName()).toEqual("Basic Type"); + expect(captured.type.getDescription()).toBeUndefined(); }); it("supports single inheritance", function () { - provider.getType('single-subtype').then(capture('type')); + captured.type = provider.getType('single-subtype'); - waitsFor( - function () { - return captured.type !== undefined; - }, - "promise resolution", - 250 - ); - runs(function () { - expect(captured.type.getGlyph()).toEqual("X"); - expect(captured.type.getName()).toEqual("Basic Subtype"); - expect(captured.type.getDescription()).toEqual("A test subtype"); - }); + expect(captured.type.getGlyph()).toEqual("X"); + expect(captured.type.getName()).toEqual("Basic Subtype"); + expect(captured.type.getDescription()).toEqual("A test subtype"); }); it("supports multiple inheritance", function () { - provider.getType('multi-subtype').then(capture('type')); - waitsFor( - function () { - return captured.type !== undefined; - }, - "promise resolution", - 250 - ); - runs(function () { - expect(captured.type.getGlyph()).toEqual("Y"); - expect(captured.type.getName()).toEqual("Multi-parent Subtype"); - expect(captured.type.getDescription()).toEqual("Multi1 Description"); - }); + captured.type = provider.getType('multi-subtype'); + + expect(captured.type.getGlyph()).toEqual("Y"); + expect(captured.type.getName()).toEqual("Multi-parent Subtype"); + expect(captured.type.getDescription()).toEqual("Multi1 Description"); }); it("concatenates capabilities in order", function () { - provider.getType('multi-subtype').then(capture('type')); - waitsFor( - function () { - return captured.type !== undefined; - }, - "promise resolution", - 250 + captured.type = provider.getType('multi-subtype'); + + expect(captured.type.getDefinition().capabilities).toEqual( + ['a1', 'b1', 'a2', 'b2', 'c2', 'a3'] ); - runs(function () { - expect(captured.type.getDefinition().capabilities).toEqual( - ['a1', 'b1', 'a2', 'b2', 'c2', 'a3'] - ); - }); }); it("allows lookup of the undefined type", function () { - provider.getType(undefined).then(capture('type')); - waitsFor( - function () { - return captured.type !== undefined; - }, - "promise resolution", - 250 - ); - runs(function () { - expect(captured.type.getName()).toEqual("Default"); - }); + captured.type = provider.getType(undefined); + + expect(captured.type.getName()).toEqual("Default"); }); it("concatenates capabilities of all undefined types", function () { - typeProviderModule.instantiate({ - definitions: testTypeDefinitions.concat([ - { - capabilities: ['a', 'b', 'c'] - }, - { - capabilities: ['x', 'y', 'z'] - } + captured.type = new TypeProvider( + testTypeDefinitions.concat([ + { capabilities: ['a', 'b', 'c'] }, + { capabilities: ['x', 'y', 'z'] } ]) - }).getType(undefined).then(capture('type')); + ).getType(undefined); - waitsFor( - function () { - return captured.type !== undefined; - }, - "promise resolution", - 250 + + expect(captured.type.getDefinition().capabilities).toEqual( + ['a', 'b', 'c', 'x', 'y', 'z'] ); - runs(function () { - expect(captured.type.getDefinition().capabilities).toEqual( - ['a', 'b', 'c', 'x', 'y', 'z'] - ); - }); + }); it("includes capabilities from undefined type in all types", function () { - typeProviderModule.instantiate({ - definitions: testTypeDefinitions.concat([ - { - capabilities: ['a', 'b', 'c'] - }, - { - capabilities: ['x', 'y', 'z'] - } + captured.type = TypeProvider.instantiate( + testTypeDefinitions.concat([ + { capabilities: ['a', 'b', 'c'] }, + { capabilities: ['x', 'y', 'z'] } ]) - }).getType('multi-subtype').then(capture('type')); - waitsFor( - function () { - return captured.type !== undefined; - }, - "promise resolution", - 250 + ).getType('multi-subtype'); + + expect(captured.type.getDefinition().capabilities).toEqual( + ['a', 'b', 'c', 'x', 'y', 'z', 'a1', 'b1', 'a2', 'b2', 'c2', 'a3'] ); - runs(function () { - expect(captured.type.getDefinition().capabilities).toEqual( - ['a', 'b', 'c', 'x', 'y', 'z', 'a1', 'b1', 'a2', 'b2', 'c2', 'a3'] - ); - }); }); it("allows types to be listed", function () { - provider.listTypes().then(capture('types')); - waitsFor( - function () { - return captured.types !== undefined; - }, - "promise resolution", - 250 + captured.types = provider.listTypes(); + + expect(captured.types.length).toEqual( + testTypeDefinitions.filter(function (t) { + return t.key; + }).length ); - runs(function () { - expect(captured.types.length).toEqual( - testTypeDefinitions.filter(function (t) { - return t.key; - }).length - ); - }); });