From a2c17e3d35541626e5b4b03ace566d5771354df6 Mon Sep 17 00:00:00 2001 From: Raido Kuli Date: Fri, 31 Mar 2017 18:04:20 +0300 Subject: [PATCH 1/4] Components with positional params failure if not full attribute definition --- tests/dummy/app/components/print-test-attributes.js | 11 +++++++++++ .../templates/components/print-test-attributes.hbs | 1 + ...strip-data-test-attributes-from-components-test.js | 6 ++++++ 3 files changed, 18 insertions(+) create mode 100644 tests/dummy/app/components/print-test-attributes.js diff --git a/tests/dummy/app/components/print-test-attributes.js b/tests/dummy/app/components/print-test-attributes.js new file mode 100644 index 00000000..0e5bb2f1 --- /dev/null +++ b/tests/dummy/app/components/print-test-attributes.js @@ -0,0 +1,11 @@ +import Ember from 'ember'; + +const { Component } = Ember; + +const component = Component.extend(); + +component.reopenClass({ + positionalParams: 'params' +}); + +export default component; diff --git a/tests/dummy/app/templates/components/print-test-attributes.hbs b/tests/dummy/app/templates/components/print-test-attributes.hbs index 990e1941..60bf5127 100644 --- a/tests/dummy/app/templates/components/print-test-attributes.hbs +++ b/tests/dummy/app/templates/components/print-test-attributes.hbs @@ -2,3 +2,4 @@
{{data-test-second}}
{{data-non-test}}
{{data-test}}
+
{{params.length}}
\ No newline at end of file diff --git a/tests/integration/strip-data-test-attributes-from-components-test.js b/tests/integration/strip-data-test-attributes-from-components-test.js index 43e59e90..24ef2b21 100644 --- a/tests/integration/strip-data-test-attributes-from-components-test.js +++ b/tests/integration/strip-data-test-attributes-from-components-test.js @@ -9,6 +9,12 @@ moduleForComponent('print-test-attributes', 'StripTestSelectorsTransform plugin' if (config.stripTestSelectors) { + test('it strips data-test-* attributes from components with positional params', function(assert) { + this.render(hbs`{{print-test-attributes "param1" data-test-first}}`); + + assert.equal(this.$('.data-test-positional-params').text(), 1, 'there should be only one param'); + }); + test('it strips data-test-* attributes from components', function(assert) { this.render(hbs`{{print-test-attributes data-test-first="foobar"}}`); From cd70fed566d34762f0f388451dbcafeaf7180bef Mon Sep 17 00:00:00 2001 From: Raido Kuli Date: Fri, 31 Mar 2017 22:43:50 +0300 Subject: [PATCH 2/4] Filter MustacheStatement and BlockStatement params for data-test-* with no value --- strip-test-selectors.js | 12 ++++++++-- ...ta-test-attributes-from-components-test.js | 22 +++++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/strip-test-selectors.js b/strip-test-selectors.js index cb00248d..aeacc961 100644 --- a/strip-test-selectors.js +++ b/strip-test-selectors.js @@ -4,6 +4,10 @@ let TEST_SELECTOR_PREFIX = /data-test-.*/; +function isNotTestSelector(attribute) { + return !TEST_SELECTOR_PREFIX.test(attribute); +} + function StripTestSelectorsTransform() { this.syntax = null; } @@ -14,11 +18,15 @@ StripTestSelectorsTransform.prototype.transform = function(ast) { walker.visit(ast, function(node) { if (node.type === 'ElementNode') { node.attributes = node.attributes.filter(function(attribute) { - return !TEST_SELECTOR_PREFIX.test(attribute.name); + return isNotTestSelector(attribute.name); }); } else if (node.type === 'MustacheStatement' || node.type === 'BlockStatement') { + node.params = node.params.filter(function(param) { + return isNotTestSelector(param.original); + }); + node.hash.pairs = node.hash.pairs.filter(function(pair) { - return !TEST_SELECTOR_PREFIX.test(pair.key); + return isNotTestSelector(pair.key); }); } }); diff --git a/tests/integration/strip-data-test-attributes-from-components-test.js b/tests/integration/strip-data-test-attributes-from-components-test.js index 24ef2b21..85ff1cc6 100644 --- a/tests/integration/strip-data-test-attributes-from-components-test.js +++ b/tests/integration/strip-data-test-attributes-from-components-test.js @@ -9,8 +9,26 @@ moduleForComponent('print-test-attributes', 'StripTestSelectorsTransform plugin' if (config.stripTestSelectors) { - test('it strips data-test-* attributes from components with positional params', function(assert) { - this.render(hbs`{{print-test-attributes "param1" data-test-first}}`); + test('it strips data-test-* attributes from components with single positional params', function(assert) { + this.render(hbs`{{print-test-attributes data-test-should-not-be}}`); + + assert.equal(this.$('.data-test-positional-params').text(), 0, 'there should be no params'); + }); + + test('it strips data-test-* attributes from components with positional params data-test-* as first param', function(assert) { + this.render(hbs`{{print-test-attributes data-test-should-not-be "param1"}}`); + + assert.equal(this.$('.data-test-positional-params').text(), 1, 'there should be no params'); + }); + + test('it strips data-test-* attributes from components with multiple positional params', function(assert) { + this.render(hbs`{{print-test-attributes "param1" data-test-should-not-be}}`); + + assert.equal(this.$('.data-test-positional-params').text(), 1, 'there should be only one param'); + }); + + test('it strips data-test-* attributes from components with block and multiple positional params', function(assert) { + this.render(hbs`{{#print-test-attributes "param1" data-test-should-not-be}}{{/print-test-attributes}}`); assert.equal(this.$('.data-test-positional-params').text(), 1, 'there should be only one param'); }); From 91a72228761be720171510c94880bcedac2e3962 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Fri, 7 Apr 2017 13:23:47 +0200 Subject: [PATCH 3/4] tests: Fix assertion message --- .../strip-data-test-attributes-from-components-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/strip-data-test-attributes-from-components-test.js b/tests/integration/strip-data-test-attributes-from-components-test.js index 85ff1cc6..aed650b3 100644 --- a/tests/integration/strip-data-test-attributes-from-components-test.js +++ b/tests/integration/strip-data-test-attributes-from-components-test.js @@ -18,7 +18,7 @@ if (config.stripTestSelectors) { test('it strips data-test-* attributes from components with positional params data-test-* as first param', function(assert) { this.render(hbs`{{print-test-attributes data-test-should-not-be "param1"}}`); - assert.equal(this.$('.data-test-positional-params').text(), 1, 'there should be no params'); + assert.equal(this.$('.data-test-positional-params').text(), 1, 'there should be only one param'); }); test('it strips data-test-* attributes from components with multiple positional params', function(assert) { From 260d156a54c5a6fddd7e7a1ba31975e7d397f563 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Fri, 7 Apr 2017 13:25:14 +0200 Subject: [PATCH 4/4] strip-test-selectors: Replace isNotTestSelector() with isTestSelector() --- strip-test-selectors.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/strip-test-selectors.js b/strip-test-selectors.js index aeacc961..28e94ec4 100644 --- a/strip-test-selectors.js +++ b/strip-test-selectors.js @@ -4,8 +4,8 @@ let TEST_SELECTOR_PREFIX = /data-test-.*/; -function isNotTestSelector(attribute) { - return !TEST_SELECTOR_PREFIX.test(attribute); +function isTestSelector(attribute) { + return TEST_SELECTOR_PREFIX.test(attribute); } function StripTestSelectorsTransform() { @@ -18,15 +18,15 @@ StripTestSelectorsTransform.prototype.transform = function(ast) { walker.visit(ast, function(node) { if (node.type === 'ElementNode') { node.attributes = node.attributes.filter(function(attribute) { - return isNotTestSelector(attribute.name); + return !isTestSelector(attribute.name); }); } else if (node.type === 'MustacheStatement' || node.type === 'BlockStatement') { node.params = node.params.filter(function(param) { - return isNotTestSelector(param.original); + return !isTestSelector(param.original); }); node.hash.pairs = node.hash.pairs.filter(function(pair) { - return isNotTestSelector(pair.key); + return !isTestSelector(pair.key); }); } });