Skip to content

Commit

Permalink
deprecate and
Browse files Browse the repository at this point in the history
  • Loading branch information
ro0gr committed Oct 1, 2023
1 parent 8895ea4 commit 83f9b16
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 6 deletions.
15 changes: 15 additions & 0 deletions addon/src/-private/finders.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import deprecate from './deprecate';
import { $, buildSelector, findClosestValue, guardMultiple } from './helpers';
import { getAdapter } from '../adapters/index';
import { throwBetterError, ELEMENT_NOT_FOUND } from './better-errors';
Expand Down Expand Up @@ -53,6 +54,13 @@ export function findElementWithAssert(
targetSelector,
options = {}
) {
deprecate(
'find-element',
'`findElementWithAssert(` is deprecated. Please, consider using the `findOne(` instead.',
'2.2.0',
'3.0.0'
);

const selector = buildSelector(pageObjectNode, targetSelector, options);
const container = getContainer(pageObjectNode, options);

Expand All @@ -74,6 +82,13 @@ export function findElementWithAssert(
* @deprecated
*/
export function findElement(pageObjectNode, targetSelector, options = {}) {
deprecate(
'find-element',
'`findElement(` is deprecated. Please, consider using the `findOne(` or `findMany(` instead.',
'2.2.0',
'3.0.0'
);

const selector = buildSelector(pageObjectNode, targetSelector, options);
const container = getContainer(pageObjectNode, options);

Expand Down
72 changes: 72 additions & 0 deletions docs/guides/deprecations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
layout: page
title: Deprecations
---

This is a list of deprecations introduced in 2.x cycle:

## Find element

**ID**: ember-cli-page-object.find-element

**Until**: 3.0.0

Both `findElement(` and `findElementWithAssert()` have jQuery collection as their return value. Since we are going away from jQuery usage, these two finders are deprecated now.

Please consider using `findOne(` or `findMany(` instead.

Bad:

```js
import { getter } from 'ember-cli-page-object/macros';
import { findElementWithAssert } from 'ember-cli-page-object/extend';

export default function isDisabled(selector, options = {}) {
return getter(function() {
return findElementWithAssert(this, selector, options).is(':disabled');
});
}
```

Good:

```js
import { getter } from 'ember-cli-page-object/macros';
import { findOne } from 'ember-cli-page-object/extend';

export default function isDisabled(selector, options = {}) {
return getter(function() {
return findOne(this, selector, options).disabled;
});
}

```

Bad:

```js
import { getter } from 'ember-cli-page-object/macros';
import { findElement } from 'ember-cli-page-object/extend';

export default function count(selector, options = {}) {
return getter(function() {
return findElement(this, selector, {
...options,
multiple: true
}).length;
});
}
```

Good:

```js
import { getter } from 'ember-cli-page-object/macros';
import { findMany } from 'ember-cli-page-object/extend';

export default function count(selector, options = {}) {
return getter(function() {
return findMany(this, selector, options).length;
});
}
```
8 changes: 2 additions & 6 deletions docs/guides/extend.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,12 @@ export default function count(selector, options = {}) {
}
```

## findElementWithAssert
## findElementWithAssert (deprecated)

[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")

Note: in the v2 series we are going to deprecate `findElementWithAssert`. It's recommended to migrate to use `findOne` instead.

In order to ease the migration, you may find useful the [`find-one`](https://github.com/ro0gr/ember-page-object-codemod/tree/master/transforms/find-one) codemod to perform the migration.

**Parameters**

- `pageObjectNode` **Ceibo** Node of the tree
Expand Down Expand Up @@ -106,12 +104,10 @@ export default function count(selector, options = {}) {
}
```

## findElement
## findElement (deprecated)

[addon/-private/extend/find-element.js:36-42](https://github.com/san650/ember-cli-page-object/blob/c521335ffba9955a6acaf1006ed503cbb61ba72d/addon/-private/extend/find-element.js#L36-L42 "Source code on GitHub")

Note: in the v2 series we are going to deprecate `findElement`. It's recommended to migrate to use `findMany` instead.

**Parameters**

- `pageObjectNode` **Ceibo** Node of the tree
Expand Down
49 changes: 49 additions & 0 deletions test-app/tests/integration/deprecations/find-element-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { module, test } from 'qunit';
import { create } from 'ember-cli-page-object';
import deprecate from 'ember-cli-page-object/-private/deprecate';
import hbs from 'htmlbars-inline-precompile';
import { render } from '@ember/test-helpers';
import { findElement, findElementWithAssert } from 'ember-cli-page-object/extend';
import { setupRenderingTest } from '../../helpers';

module('Deprecation | find-element', function (hooks) {
setupRenderingTest(hooks);

hooks.beforeEach(function () {
deprecate.__calls = [];
});

hooks.afterEach(function () {
delete deprecate.__calls;
});

test('findElement', async function (assert) {
await render(hbs`<span></span>`);

findElement(create(), 'span');

assert.deepEqual(deprecate.__calls, [
[
"find-element",
"`findElement(` is deprecated. Please, consider using the `findOne(` or `findMany(` instead.",
"2.2.0",
"3.0.0"
],
]);
});

test('findElementWithAssert', async function (assert) {
await render(hbs`<span></span>`);

findElementWithAssert(create(), 'span');

assert.deepEqual(deprecate.__calls, [
[
"find-element",
"`findElementWithAssert(` is deprecated. Please, consider using the `findOne(` instead.",
"2.2.0",
"3.0.0"
],
]);
});
});
26 changes: 26 additions & 0 deletions test-app/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,29 @@ declare module 'ember-cli-page-object/templates/*' {
const tmpl: TemplateFactory;
export default tmpl;
}

declare module "ember-cli-page-object/-private/deprecate" {
const deprecate: {
(id: string, message: string, since: string, until: string): void;

/**
Stores list of argments for each `deprecate(` invocation.
It's `undefined` by default, which means "invocations tracking is disabled".
If you want to enable tracking, just initialize the `__calls` with an empty array, e.g:
```js
deprecate.__calls = [];
```
or disable it with
```js
delete deprecate.__calls;
```
*/
__calls?: string[][]
};

export default deprecate
}

0 comments on commit 83f9b16

Please sign in to comment.