Skip to content

Commit 1d79d53

Browse files
committed
test(selector): add tests with multiple attributes
Fixes angular#1025 Closes angular#1117
1 parent 60e4197 commit 1d79d53

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

modules/angular2/test/core/compiler/pipeline/directive_parser_spec.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export function main() {
2525
SomeViewport2,
2626
SomeComponent,
2727
SomeComponent2,
28+
SomeComponent3,
2829
SomeDynamicComponent,
2930
SomeDynamicComponent2
3031
];
@@ -105,6 +106,13 @@ export function main() {
105106
);
106107
}).toThrowError('Only template directives are allowed on template elements - check <template some-comp>');
107108
});
109+
110+
it('should detect them with multiple attributes', () => {
111+
var results = createPipeline().process(el('<input type=text control=one></input>'));
112+
var dirs = results[0].getAllDirectives();
113+
expect(dirs.length).toEqual(1);
114+
expect(dirs[0]).toEqual(reader.read(SomeComponent3));
115+
});
108116
});
109117

110118
describe("dynamic component directives", () => {
@@ -261,6 +269,9 @@ class SomeComponent {}
261269
@Component({selector: '[some-comp2]'})
262270
class SomeComponent2 {}
263271

272+
@Component({selector: 'input[type=text][control]'})
273+
class SomeComponent3 {}
274+
264275
@DynamicComponent({selector: '[some-dynamic-comp]'})
265276
class SomeDynamicComponent {}
266277

@@ -270,7 +281,7 @@ class SomeDynamicComponent2 {}
270281
@Component()
271282
@Template({
272283
directives: [SomeDecorator, SomeViewport, SomeViewport2,
273-
SomeComponent, SomeComponent2,
284+
SomeComponent, SomeComponent2, SomeComponent3,
274285
SomeDynamicComponent, SomeDynamicComponent2
275286
]
276287
})

modules/angular2/test/core/compiler/selector_spec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ export function main() {
106106
expect(matched).toEqual([s1[0],1]);
107107
});
108108

109+
it('should select by many attributes and independent of the value', () => {
110+
matcher.addSelectables(s1 = CssSelector.parse('input[type=text][control]'), 1);
111+
112+
var cssSelector = new CssSelector();
113+
cssSelector.setElement('input');
114+
cssSelector.addAttribute('type', 'text');
115+
cssSelector.addAttribute('control', 'one');
116+
117+
expect(matcher.match(cssSelector, selectableCollector)).toEqual(true);
118+
expect(matched).toEqual([s1[0], 1]);
119+
});
120+
109121
it('should select independent of the order in the css selector', () => {
110122
matcher.addSelectables(s1 = CssSelector.parse('[someAttr].someClass'), 1);
111123
matcher.addSelectables(s2 = CssSelector.parse('.someClass[someAttr]'), 2);
@@ -205,6 +217,14 @@ export function main() {
205217
expect(cssSelector.toString()).toEqual('sometag.someclass[attrname=attrvalue]');
206218
});
207219

220+
it('should detect multiple attributes', () => {
221+
var cssSelector = CssSelector.parse('input[type=text][control]')[0];
222+
expect(cssSelector.element).toEqual('input');
223+
expect(cssSelector.attrs).toEqual(['type', 'text', 'control', '']);
224+
225+
expect(cssSelector.toString()).toEqual('input[type=text][control]');
226+
});
227+
208228
it('should detect :not', () => {
209229
var cssSelector = CssSelector.parse('sometag:not([attrname=attrvalue].someclass)')[0];
210230
expect(cssSelector.element).toEqual('sometag');

modules/angular2/test/render/dom/compiler/directive_parser_spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export function main() {
1717
annotatedDirectives = [
1818
someComponent,
1919
someComponent2,
20+
someComponent3,
2021
someViewport,
2122
someViewport2,
2223
someDecorator,
@@ -57,6 +58,13 @@ export function main() {
5758
);
5859
});
5960

61+
it('should detect directives with multiple attributes', () => {
62+
var results = process(el('<input type=text control=one></input>'));
63+
expect(results[0].directives[0].directiveIndex).toBe(
64+
annotatedDirectives.indexOf(someComponent3)
65+
);
66+
});
67+
6068
it('should compile children by default', () => {
6169
var results = createPipeline().process(el('<div some-decor></div>'));
6270
expect(results[0].compileChildren).toEqual(true);
@@ -190,6 +198,12 @@ var someComponent2 = new DirectiveMetadata({
190198
type: DirectiveMetadata.COMPONENT_TYPE
191199
});
192200

201+
var someComponent3 = new DirectiveMetadata({
202+
selector: 'input[type=text][control]',
203+
id: 'someComponent3',
204+
type: DirectiveMetadata.COMPONENT_TYPE
205+
});
206+
193207
var someViewport = new DirectiveMetadata({
194208
selector: '[some-vp]',
195209
id: 'someViewport',

modules/angular2/test/render/dom/compiler/selector_spec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ export function main() {
106106
expect(matched).toEqual([s1[0],1]);
107107
});
108108

109+
it('should select by many attributes and independent of the value', () => {
110+
matcher.addSelectables(s1 = CssSelector.parse('input[type=text][control]'), 1);
111+
112+
var cssSelector = new CssSelector();
113+
cssSelector.setElement('input');
114+
cssSelector.addAttribute('type', 'text');
115+
cssSelector.addAttribute('control', 'one');
116+
117+
expect(matcher.match(cssSelector, selectableCollector)).toEqual(true);
118+
expect(matched).toEqual([s1[0], 1]);
119+
});
120+
109121
it('should select independent of the order in the css selector', () => {
110122
matcher.addSelectables(s1 = CssSelector.parse('[someAttr].someClass'), 1);
111123
matcher.addSelectables(s2 = CssSelector.parse('.someClass[someAttr]'), 2);
@@ -205,6 +217,14 @@ export function main() {
205217
expect(cssSelector.toString()).toEqual('sometag.someclass[attrname=attrvalue]');
206218
});
207219

220+
it('should detect multiple attributes', () => {
221+
var cssSelector = CssSelector.parse('input[type=text][control]')[0];
222+
expect(cssSelector.element).toEqual('input');
223+
expect(cssSelector.attrs).toEqual(['type', 'text', 'control', '']);
224+
225+
expect(cssSelector.toString()).toEqual('input[type=text][control]');
226+
});
227+
208228
it('should detect :not', () => {
209229
var cssSelector = CssSelector.parse('sometag:not([attrname=attrvalue].someclass)')[0];
210230
expect(cssSelector.element).toEqual('sometag');

0 commit comments

Comments
 (0)