diff --git a/karma-test-shim.js b/karma-test-shim.js index 6cca7c7f829f..536922f266fb 100644 --- a/karma-test-shim.js +++ b/karma-test-shim.js @@ -8,10 +8,11 @@ __karma__.loaded = function() {}; /** * Gets map of module alias to location or package. * @param dir Directory name under `src/` for create a map for. + * @param core Is that a map of the core files */ -function getPathsMap(dir) { +function getPathsMap(dir, core) { return Object.keys(window.__karma__.files) - .filter(isComponentsFile) + .filter(!!core ? isCoreFile : isComponentsFile) .reduce(function(pathsMapping, appPath) { var pathToReplace = new RegExp('^/base/dist/' + dir + '/'); var moduleName = appPath.replace(pathToReplace, './').replace(/\.js$/, ''); @@ -26,6 +27,11 @@ System.config({ defaultExtension: false, format: 'register', map: getPathsMap('components') + }, + 'base/dist/core': { + defaultExtension: false, + format: 'register', + map: getPathsMap('core', true) } } }); @@ -46,6 +52,10 @@ System.import('angular2/platform/browser').then(function(browser_adapter) { __karma__.error(error.stack || error); }); +function isCoreFile(filePath) { + return /^\/base\/dist\/core\/(?!spec)([a-z0-9-_\/]+)\.js$/.test(filePath); +} + function isComponentsFile(filePath) { return /^\/base\/dist\/components\/(?!spec)([a-z0-9-_\/]+)\.js$/.test(filePath); } diff --git a/karma.conf.js b/karma.conf.js index 2858b845050a..063e9d90d04a 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -31,7 +31,7 @@ module.exports = function(config) { proxies: { // required for component assests fetched by Angular's compiler "/demo-app/": "/base/dist/demo-app/", - "/components/": "/base/dist/components/", + "/components/": "/base/dist/components/" }, exclude: [], preprocessors: {}, diff --git a/src/components/switch/switch.spec.ts b/src/components/switch/switch.spec.ts new file mode 100644 index 000000000000..be87b80d9664 --- /dev/null +++ b/src/components/switch/switch.spec.ts @@ -0,0 +1,59 @@ +import { + it, + iit, + describe, + ddescribe, + expect, + inject, + injectAsync, + TestComponentBuilder, + beforeEachProviders, + beforeEach, +} from 'angular2/testing'; +import {provide, Component} from 'angular2/core'; +import {DebugElement} from "angular2/core"; +import {MdSwitch} from './switch'; +import {AsyncTestFn} from "angular2/testing"; +import {FORM_DIRECTIVES} from "angular2/common"; +import {Input} from "angular2/core"; + + +describe('MdSwitch', () => { + let builder: TestComponentBuilder; + + beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { builder = tcb; })); + + describe('md-switch', () => { + it('should change the model value', (done: () => void) => { + return builder.createAsync(TestApp).then((fixture) => { + let testComponent = fixture.debugElement.componentInstance; + let switchElement = getChildDebugElement(fixture.debugElement, 'md-switch'); + + expect(switchElement.nativeElement.classList.contains('md-checked')).toBe(false); + + testComponent.testSwitch = true; + + fixture.detectChanges(); + + expect(switchElement.nativeElement.classList.contains('md-checked')).toBe(true); + done(); + }); + }); + }); +}); + +/** Gets a child DebugElement by tag name. */ +function getChildDebugElement(parent: DebugElement, tagName: string): DebugElement { + return parent.query(debugEl => debugEl.nativeElement.tagName.toLowerCase() == tagName); +} + +/** Test component that contains an MdSwitch. */ +@Component({ + selector: 'test-app', + directives: [MdSwitch, FORM_DIRECTIVES], + template: + 'Test Switch', +}) +class TestApp { + testSwitch = false; +} diff --git a/src/core/services/drag/drag.ts b/src/core/services/drag/drag.ts index 967b24872898..e5a26f1a472c 100644 --- a/src/core/services/drag/drag.ts +++ b/src/core/services/drag/drag.ts @@ -1,5 +1,4 @@ import {DOM} from "angular2/src/platform/dom/dom_adapter"; -import {Json} from "angular2/src/facade/lang"; export class MdDrag {