Skip to content
This repository was archived by the owner on Jan 22, 2018. It is now read-only.

Commit 07bfb56

Browse files
author
Kamil Kisiela
committed
test(ngModelAttrsManipulator): full coverage
1 parent bf66028 commit 07bfb56

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

tests/helpers/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './ng-model-attrs-manipulator-spec';
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import {
2+
ngModelAttrsManipulator
3+
}
4+
from './../../src/helpers';
5+
6+
describe("formlyMaterial - ngModelAttrsManipulator", () => {
7+
it("should skip on skipNgModelAttrsManipulator", () => {
8+
const tpl = 'test';
9+
const result = ngModelAttrsManipulator(tpl, {
10+
extras: {
11+
skipNgModelAttrsManipulator: true
12+
}
13+
});
14+
15+
expect(result).toBe(tpl);
16+
});
17+
18+
it("should not modify on missing ngModel", () => {
19+
const tpl = 'test';
20+
const result = ngModelAttrsManipulator(tpl, {});
21+
22+
expect(result).toBe(tpl);
23+
});
24+
25+
it("should add attribute with value to ngModel", () => {
26+
const tpl = '<div><input ng-model="baz"/></div>';
27+
const attr = {
28+
name: 'foo',
29+
value: 'bar'
30+
};
31+
const result = ngModelAttrsManipulator(tpl, {}, attr.name, attr.value);
32+
const element = angular.element(result);
33+
34+
expect(result).not.toBe(tpl);
35+
expect(element.find('[ng-model]').attr(attr.name)).toBe(attr.value);
36+
});
37+
38+
it("should add attribute with value to few elements with ngModel", () => {
39+
const tpl = '<div><input ng-model="baz1"/><input ng-model="baz2"/></div>';
40+
const attr = {
41+
name: 'foo',
42+
value: 'bar'
43+
};
44+
const result = ngModelAttrsManipulator(tpl, {}, attr.name, attr.value);
45+
const element = angular.element(result);
46+
47+
expect(result).not.toBe(tpl);
48+
expect(element.find('[ng-model]').length).toBe(2);
49+
expect(element.find('[ng-model]:eq(0)').attr(attr.name)).toBe(attr.value);
50+
expect(element.find('[ng-model]:eq(1)').attr(attr.name)).toBe(attr.value);
51+
});
52+
53+
it("should not overwrite attribute on ngModel", () => {
54+
const name = 'baz';
55+
const tpl = `<div><input ng-model="${name}" foo="${name}"/></div>`;
56+
const attr = {
57+
name: 'foo',
58+
value: 'bar'
59+
};
60+
const result = ngModelAttrsManipulator(tpl, {}, attr.name, attr.value);
61+
const element = angular.element(result);
62+
63+
expect(result).not.toBe(tpl);
64+
expect(element.find('[ng-model]').attr(attr.name)).toBe(name);
65+
});
66+
});

tests/index-spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import './../src';
22

3+
import './helpers';
34
import './runs';
45
import './types'
5-
import './wrappers';
6+
import './wrappers';

0 commit comments

Comments
 (0)