From 1125547a77c50080eb01ee12e9d33eae5bed96c8 Mon Sep 17 00:00:00 2001 From: Alon Bukai Date: Sun, 3 Oct 2021 20:22:58 +0300 Subject: [PATCH 1/3] fix: Revert native contains property The change done in this PR: #466 caused a regression. $.text() can find the text in `visibility: hidden` or `display: none` elements. element.innerText does not return the text. Fixes: #514 --- addon-test-support/properties/contains.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/addon-test-support/properties/contains.js b/addon-test-support/properties/contains.js index 59452e9c..4f8e6081 100644 --- a/addon-test-support/properties/contains.js +++ b/addon-test-support/properties/contains.js @@ -1,6 +1,5 @@ -import { assign } from '../-private/helpers'; -import { findMany, findOne } from '../extend'; -import { A } from '@ember/array'; +import { assign, every } from '../-private/helpers'; +import { findElementWithAssert } from '../extend'; /** * Returns a boolean representing whether an element or a set of elements contains the specified text. @@ -69,7 +68,6 @@ import { A } from '@ember/array'; * * const page = create({ * scope: '.scope', - * spanContains: contains('span') * }); * @@ -96,13 +94,13 @@ export function contains(selector, userOptions = {}) { get(key) { return function(textToSearch) { - let options = assign({ - pageObjectKey: `${key}("${textToSearch}")` - }, userOptions); + let options = assign({ pageObjectKey: `${key}("${textToSearch}")` }, userOptions); - let elements = options.multiple ? findMany(this, selector, options) : [findOne(this, selector, options)]; + let elements = findElementWithAssert(this, selector, options); - return A(elements).every((element) => element.innerText.indexOf(textToSearch) >= 0); + return every(elements, function(element) { + return element.text().indexOf(textToSearch) >= 0; + }); }; } }; From 5f8ecc7e5ed38a2f6f69157c890c61de6839481b Mon Sep 17 00:00:00 2001 From: Alon Bukai Date: Tue, 12 Oct 2021 08:30:06 +0000 Subject: [PATCH 2/3] fix: Update contains helper to use findMany/One This keeps the helper in line with other internal helpers. This required converting the e lements into a jQuery array as this is what the `every` function receives. --- addon-test-support/properties/contains.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/addon-test-support/properties/contains.js b/addon-test-support/properties/contains.js index 4f8e6081..2d185414 100644 --- a/addon-test-support/properties/contains.js +++ b/addon-test-support/properties/contains.js @@ -1,5 +1,6 @@ import { assign, every } from '../-private/helpers'; -import { findElementWithAssert } from '../extend'; +import { findMany, findOne } from '../extend'; +import $ from 'jquery'; /** * Returns a boolean representing whether an element or a set of elements contains the specified text. @@ -94,11 +95,13 @@ export function contains(selector, userOptions = {}) { get(key) { return function(textToSearch) { - let options = assign({ pageObjectKey: `${key}("${textToSearch}")` }, userOptions); + let options = assign({ + pageObjectKey: `${key}("${textToSearch}")` + }, userOptions); - let elements = findElementWithAssert(this, selector, options); + let elements = options.multiple ? findMany(this, selector, options) : [findOne(this, selector, options)]; - return every(elements, function(element) { + return every($(elements), function(element) { return element.text().indexOf(textToSearch) >= 0; }); }; From 2a325143d9201c782f4b1649bc30d4303c021e34 Mon Sep 17 00:00:00 2001 From: Alon Bukai Date: Tue, 12 Oct 2021 08:30:28 +0000 Subject: [PATCH 3/3] test: Add tests for contains on invisible elements --- .../unit/-private/properties/contains-test.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/unit/-private/properties/contains-test.ts b/tests/unit/-private/properties/contains-test.ts index c048e849..f213f0a5 100644 --- a/tests/unit/-private/properties/contains-test.ts +++ b/tests/unit/-private/properties/contains-test.ts @@ -127,4 +127,26 @@ moduleForProperty('contains', function(test) { assert.ok(page.foo('ipsum')); }); + + test('looks for elements that are visibility hidden', async function(assert) { + let page = create({ + foo: contains('span') + }); + + await this.adapter.createTemplate(this, page, 'Lorem ipsum'); + + assert.ok(!page.foo('Not here')); + assert.ok(page.foo('ipsum')); + }); + + test('looks for elements that are display none', async function(assert) { + let page = create({ + foo: contains('span') + }); + + await this.adapter.createTemplate(this, page, 'Lorem ipsum'); + + assert.ok(!page.foo('Not here')); + assert.ok(page.foo('ipsum')); + }); });