Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Revert native contains property #547

Merged
merged 3 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions addon-test-support/properties/contains.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assign } from '../-private/helpers';
import { assign, every } from '../-private/helpers';
import { findMany, findOne } from '../extend';
import { A } from '@ember/array';
import $ from 'jquery';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh... I must be blind.

At the moment in order to use "adaptive" jquery, we had to import it by a synthetic -jquery path, like in other properties

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to create a PR to fix this or want me to whip one up?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do it, though not sure if I manage to handle it today

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so yes, this error pops up in the GH Actions PR #552. and it's fixed there as well. I'd fix it altogether this weekend.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!


/**
* Returns a boolean representing whether an element or a set of elements contains the specified text.
Expand Down Expand Up @@ -69,7 +69,6 @@ import { A } from '@ember/array';
*
* const page = create({
* scope: '.scope',

* spanContains: contains('span')
* });
*
Expand Down Expand Up @@ -102,7 +101,9 @@ export function contains(selector, userOptions = {}) {

let elements = options.multiple ? findMany(this, selector, options) : [findOne(this, selector, options)];

return A(elements).every((element) => element.innerText.indexOf(textToSearch) >= 0);
return every($(elements), function(element) {
return element.text().indexOf(textToSearch) >= 0;
});
};
}
};
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/-private/properties/contains-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <span style="visibility: hidden;">ipsum</span>');

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 <span style="display: none;">ipsum</span>');

assert.ok(!page.foo('Not here'));
assert.ok(page.foo('ipsum'));
});
});