Skip to content

Commit

Permalink
remove findElementWithAssert
Browse files Browse the repository at this point in the history
  • Loading branch information
ro0gr committed Mar 29, 2020
1 parent 693c223 commit eb1087c
Show file tree
Hide file tree
Showing 16 changed files with 28 additions and 273 deletions.
28 changes: 1 addition & 27 deletions addon-test-support/-private/execution_context/acceptance.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import $ from '-jquery';
import { run } from '../action';
import {
guardMultiple,
buildSelector,
findClosestValue
} from '../helpers';
import { findClosestValue } from '../helpers';
import {
fillElement,
assertFocusable
Expand Down Expand Up @@ -87,26 +83,4 @@ AcceptanceExecutionContext.prototype = {
);
}
},

findWithAssert(selector, options) {
let result;

selector = buildSelector(this.pageObjectNode, selector, options);

/* global find */
result = find(selector, options.testContainer || findClosestValue(this.pageObjectNode, 'testContainer'));

if (result.length === 0) {
throwBetterError(
this.pageObjectNode,
options.pageObjectKey,
ELEMENT_NOT_FOUND,
{ selector }
);
}

guardMultiple(result, selector, options.multiple);

return result;
}
};
32 changes: 1 addition & 31 deletions addon-test-support/-private/execution_context/integration.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import $ from '-jquery';
import { run } from '@ember/runloop';
import { run as runAction } from '../action';
import {
guardMultiple,
buildSelector,
findClosestValue
} from '../helpers';
import { findClosestValue } from '../helpers';
import {
fillElement,
assertFocusable
Expand Down Expand Up @@ -99,30 +95,4 @@ IntegrationExecutionContext.prototype = {
);
}
},

findWithAssert(selector, options) {
let result;
let container = options.testContainer || findClosestValue(this.pageObjectNode, 'testContainer');

selector = buildSelector(this.pageObjectNode, selector, options);

if (container) {
result = $(selector, container);
} else {
result = this.testContext.$(selector);
}

guardMultiple(result, selector, options.multiple);

if (result.length === 0) {
throwBetterError(
this.pageObjectNode,
options.pageObjectKey,
ELEMENT_NOT_FOUND,
{ selector }
);
}

return result;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ import {
} from 'ember-native-dom-helpers';

import { run } from '../action';
import {
guardMultiple,
buildSelector,
findClosestValue
} from '../helpers';
import { findClosestValue } from '../helpers';
import {
fillElement,
assertFocusable
Expand Down Expand Up @@ -100,26 +96,5 @@ ExecutionContext.prototype = {
);
}
},

findWithAssert(selector, options) {
let container = options.testContainer || findClosestValue(this.pageObjectNode, 'testContainer');

selector = buildSelector(this.pageObjectNode, selector, options);

let result = this.$(selector, container);

if (result.length === 0) {
throwBetterError(
this.pageObjectNode,
options.pageObjectKey,
ELEMENT_NOT_FOUND,
{ selector }
);
}

guardMultiple(result, selector, options.multiple);

return result;
}
};

24 changes: 1 addition & 23 deletions addon-test-support/-private/execution_context/rfc268.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import $ from '-jquery';
import { run } from '../action';
import {
guardMultiple,
buildSelector,
findClosestValue,
} from '../helpers';
import { findClosestValue } from '../helpers';
import {
getRootElement,
visit,
Expand Down Expand Up @@ -76,24 +72,6 @@ ExecutionContext.prototype = {
}
},

findWithAssert(selector, options) {
selector = buildSelector(this.pageObjectNode, selector, options);
let result = this.getElements(selector, options);

guardMultiple(result, selector, options.multiple);

if (result.length === 0) {
throwBetterError(
this.pageObjectNode,
options.pageObjectKey,
ELEMENT_NOT_FOUND,
{ selector }
);
}

return result;
},

getElements(selector, options) {
let container = options.testContainer || findClosestValue(this.pageObjectNode, 'testContainer');

Expand Down
15 changes: 0 additions & 15 deletions addon-test-support/-private/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,6 @@ export function buildSelector(node, targetSelector, options) {
return (new Selector(node, options.scope, targetSelector, options)).toString();
}

/**
* @private
*
* Check if all options are in whitelist
*
*/
export function filterWhitelistedOption(options, whitelist) {
return whitelist.reduce((whitelisted, knownKey) => {
if (knownKey in options) {
whitelisted[knownKey] = options[knownKey];
}
return whitelisted;
}, {});
}

/**
* @public
*
Expand Down
46 changes: 0 additions & 46 deletions addon-test-support/extend/find-element-with-assert.js

This file was deleted.

28 changes: 22 additions & 6 deletions addon-test-support/extend/find-one.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import $ from '-jquery';
import { getExecutionContext } from '../-private/execution_context';
import { filterWhitelistedOption } from "../-private/helpers";
import { buildSelector, findClosestValue, guardMultiple } from "../-private/helpers";
import { throwBetterError, ELEMENT_NOT_FOUND } from '../-private/better-errors';

/**
* @public
Expand Down Expand Up @@ -37,9 +39,23 @@ import { filterWhitelistedOption } from "../-private/helpers";
* @throws If more than one element found
*/
export function findOne(pageObjectNode, targetSelector, options = {}) {
const filteredOptions = filterWhitelistedOption(options, [
'resetScope', 'visible', 'testContainer', 'contains', 'at', 'last', 'scope', 'pageObjectKey'
]);
const opts = Object.assign({}, filteredOptions, { multiple: false });
return getExecutionContext(pageObjectNode).findWithAssert(targetSelector, opts).get(0);
const selector = buildSelector(pageObjectNode, targetSelector, options);
const container = options.testContainer
|| findClosestValue(pageObjectNode, 'testContainer')
|| getExecutionContext(pageObjectNode).testContainer;

const elements = $(selector, container).toArray();

guardMultiple(elements, selector);

if (elements.length === 0) {
throwBetterError(
pageObjectNode,
options.pageObjectKey,
ELEMENT_NOT_FOUND,
{ selector }
);
}

return elements[0];
}
1 change: 0 additions & 1 deletion addon-test-support/extend/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export { findElementWithAssert } from './find-element-with-assert';
export { findOne } from './find-one';
export { findMany } from './find-many';
export { buildSelector, getContext, fullScope } from '../-private/helpers';
Expand Down
1 change: 0 additions & 1 deletion addon-test-support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { triggerable } from './properties/triggerable'; export { triggerable }
import { value } from './properties/value'; export { value };
import { visitable } from './properties/visitable'; export { visitable };

export { findElementWithAssert } from './extend/find-element-with-assert';
export { buildSelector, getContext } from './-private/helpers';

export default {
Expand Down
35 changes: 0 additions & 35 deletions guides/extend.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ You can create custom helpers by creating `Ceibo` descriptors. (`Ceibo` is a sma

- [findOne](#findone)
- [findMany](#findmany)
- [findElementWithAssert](#findelementwithassert) **[Deprecated]**

## findOne

Expand Down Expand Up @@ -76,38 +75,4 @@ export default function count(selector, options = {}) {
}
```

## findElementWithAssert

[addon/-private/extend/find-element-with-assert.js:38-44](https://github.com/san650/ember-cli-page-object/blob/c521335ffba9955a6acaf1006ed503cbb61ba72d/addon/-private/extend/find-element-with-assert.js#L38-L44 "Source code on GitHub")

**Parameters**

- `pageObjectNode` **Ceibo** Node of the tree
- `targetSelector` **string** Specific CSS selector
- `options` **Object** Additional options
- `options.resetScope` **boolean** Do not use inherited scope
- `options.contains` **string** Filter by using :contains('foo') pseudo-class
- `options.last` **boolean** Filter by using :last pseudo-class
- `options.visible` **boolean** Filter by using :visible pseudo-class
- `options.multiple` **boolean** Specify if built selector can match multiple elements.
- `options.testContainer` **String** Context where to search elements in the DOM
- `options.at` **number** Filter by index using :eq(x) pseudo-class
- `options.pageObjectKey` **String** Used in the error message when the element is not found

**Examples**

```javascript
import { findElementWithAssert } from 'ember-cli-page-object/extend';

export default function isDisabled(selector, options = {}) {
return {
isDescriptor: true,

get() {
return findElementWithAssert(this, selector, options).is(':disabled');
}
};
}
```

{% endraw %}
2 changes: 1 addition & 1 deletion test-support/page-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default {
visitable
};

export { buildSelector, findElementWithAssert, getContext, fullScope } from 'ember-cli-page-object';
export { buildSelector, getContext, fullScope } from 'ember-cli-page-object';

deprecate(`Importing from "test-support" is now deprecated. Please import directly from the "ember-cli-page-object" module instead.`, false, {
id: 'ember-cli-page-object.import-from-test-support',
Expand Down
27 changes: 0 additions & 27 deletions tests/acceptance/extension-helpers-test.ts

This file was deleted.

31 changes: 0 additions & 31 deletions tests/acceptance/rfc268-extension-helpers-test.ts

This file was deleted.

Loading

0 comments on commit eb1087c

Please sign in to comment.