Skip to content

Commit 08f0ca4

Browse files
committed
test(switch): add basic test
1 parent 86c6bf8 commit 08f0ca4

File tree

4 files changed

+72
-4
lines changed

4 files changed

+72
-4
lines changed

karma-test-shim.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ __karma__.loaded = function() {};
88
/**
99
* Gets map of module alias to location or package.
1010
* @param dir Directory name under `src/` for create a map for.
11+
* @param core Is that a map of the core files
1112
*/
12-
function getPathsMap(dir) {
13+
function getPathsMap(dir, core) {
1314
return Object.keys(window.__karma__.files)
14-
.filter(isComponentsFile)
15+
.filter(!!core ? isCoreFile : isComponentsFile)
1516
.reduce(function(pathsMapping, appPath) {
1617
var pathToReplace = new RegExp('^/base/dist/' + dir + '/');
1718
var moduleName = appPath.replace(pathToReplace, './').replace(/\.js$/, '');
@@ -26,6 +27,11 @@ System.config({
2627
defaultExtension: false,
2728
format: 'register',
2829
map: getPathsMap('components')
30+
},
31+
'base/dist/core': {
32+
defaultExtension: false,
33+
format: 'register',
34+
map: getPathsMap('core', true)
2935
}
3036
}
3137
});
@@ -46,6 +52,10 @@ System.import('angular2/platform/browser').then(function(browser_adapter) {
4652
__karma__.error(error.stack || error);
4753
});
4854

55+
function isCoreFile(filePath) {
56+
return /^\/base\/dist\/core\/(?!spec)([a-z0-9-_\/]+)\.js$/.test(filePath);
57+
}
58+
4959
function isComponentsFile(filePath) {
5060
return /^\/base\/dist\/components\/(?!spec)([a-z0-9-_\/]+)\.js$/.test(filePath);
5161
}

karma.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = function(config) {
3131
proxies: {
3232
// required for component assests fetched by Angular's compiler
3333
"/demo-app/": "/base/dist/demo-app/",
34-
"/components/": "/base/dist/components/",
34+
"/components/": "/base/dist/components/"
3535
},
3636
exclude: [],
3737
preprocessors: {},

src/components/switch/switch.spec.ts

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import {
2+
it,
3+
iit,
4+
describe,
5+
ddescribe,
6+
expect,
7+
inject,
8+
injectAsync,
9+
TestComponentBuilder,
10+
beforeEachProviders,
11+
beforeEach,
12+
} from 'angular2/testing';
13+
import {provide, Component} from 'angular2/core';
14+
import {DebugElement} from "angular2/core";
15+
import {MdSwitch} from './switch';
16+
import {AsyncTestFn} from "angular2/testing";
17+
import {FORM_DIRECTIVES} from "angular2/common";
18+
import {Input} from "angular2/core";
19+
20+
21+
describe('MdSwitch', () => {
22+
let builder: TestComponentBuilder;
23+
24+
beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { builder = tcb; }));
25+
26+
describe('md-switch', () => {
27+
it('should change the model value', (done: () => void) => {
28+
return builder.createAsync(TestApp).then((fixture) => {
29+
let testComponent = fixture.debugElement.componentInstance;
30+
let switchElement = getChildDebugElement(fixture.debugElement, 'md-switch');
31+
32+
expect(switchElement.nativeElement.classList.contains('md-checked')).toBe(false);
33+
34+
testComponent.testSwitch = true;
35+
36+
fixture.detectChanges();
37+
38+
expect(switchElement.nativeElement.classList.contains('md-checked')).toBe(true);
39+
done();
40+
});
41+
});
42+
});
43+
});
44+
45+
/** Gets a child DebugElement by tag name. */
46+
function getChildDebugElement(parent: DebugElement, tagName: string): DebugElement {
47+
return parent.query(debugEl => debugEl.nativeElement.tagName.toLowerCase() == tagName);
48+
}
49+
50+
/** Test component that contains an MdSwitch. */
51+
@Component({
52+
selector: 'test-app',
53+
directives: [MdSwitch, FORM_DIRECTIVES],
54+
template:
55+
'<md-switch [(ngModel)]="testSwitch">Test Switch</md-switch>',
56+
})
57+
class TestApp {
58+
testSwitch = false;
59+
}

src/core/services/drag/drag.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {DOM} from "angular2/src/platform/dom/dom_adapter";
2-
import {Json} from "angular2/src/facade/lang";
32

43
export class MdDrag {
54

0 commit comments

Comments
 (0)