├── .editorconfig ├── .ember-cli ├── .eslintignore ├── .eslintrc.js ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .npmignore ├── .prettierignore ├── .prettierrc.js ├── .template-lintrc.js ├── .watchmanconfig ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── addon └── helpers │ └── array-contains.js ├── app └── helpers │ └── array-contains.js ├── config ├── ember-try.js ├── environment.js └── targets.js ├── ember-cli-build.js ├── index.js ├── package.json ├── testem.js ├── tests ├── dummy │ ├── app │ │ ├── app.js │ │ ├── components │ │ │ └── .gitkeep │ │ ├── helpers │ │ │ └── .gitkeep │ │ ├── index.html │ │ ├── router.js │ │ └── styles │ │ │ └── app.css │ ├── config │ │ ├── ember-cli-update.json │ │ ├── environment.js │ │ ├── optional-features.json │ │ └── targets.js │ └── public │ │ └── robots.txt ├── helpers │ └── .gitkeep ├── index.html ├── integration │ └── helpers │ │ └── array-contains-test.js ├── test-helper.js └── unit │ └── .gitkeep ├── vendor └── .gitkeep └── yarn.lock /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | [*] 8 | end_of_line = lf 9 | charset = utf-8 10 | trim_trailing_whitespace = true 11 | insert_final_newline = true 12 | indent_style = space 13 | indent_size = 2 14 | 15 | [*.hbs] 16 | insert_final_newline = false 17 | 18 | [*.{diff,md}] 19 | trim_trailing_whitespace = false 20 | -------------------------------------------------------------------------------- /.ember-cli: -------------------------------------------------------------------------------- 1 | { 2 | /** 3 | Ember CLI sends analytics information by default. The data is completely 4 | anonymous, but there are times when you might want to disable this behavior. 5 | 6 | Setting `disableAnalytics` to true will prevent any data from being sent. 7 | */ 8 | "disableAnalytics": false 9 | } 10 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | # unconventional js 2 | /blueprints/*/files/ 3 | /vendor/ 4 | 5 | # compiled output 6 | /dist/ 7 | /tmp/ 8 | 9 | # dependencies 10 | /bower_components/ 11 | /node_modules/ 12 | 13 | # misc 14 | /coverage/ 15 | !.* 16 | .*/ 17 | .eslintcache 18 | 19 | # ember-try 20 | /.node_modules.ember-try/ 21 | /bower.json.ember-try 22 | /package.json.ember-try 23 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | root: true, 5 | parser: 'babel-eslint', 6 | parserOptions: { 7 | ecmaVersion: 2018, 8 | sourceType: 'module', 9 | ecmaFeatures: { 10 | legacyDecorators: true, 11 | }, 12 | }, 13 | plugins: ['ember'], 14 | extends: [ 15 | 'eslint:recommended', 16 | 'plugin:ember/recommended', 17 | 'plugin:prettier/recommended', 18 | ], 19 | env: { 20 | browser: true, 21 | }, 22 | rules: {}, 23 | overrides: [ 24 | // node files 25 | { 26 | files: [ 27 | './.eslintrc.js', 28 | './.prettierrc.js', 29 | './.template-lintrc.js', 30 | './ember-cli-build.js', 31 | './index.js', 32 | './testem.js', 33 | './blueprints/*/index.js', 34 | './config/**/*.js', 35 | './tests/dummy/config/**/*.js', 36 | ], 37 | parserOptions: { 38 | sourceType: 'script', 39 | }, 40 | env: { 41 | browser: false, 42 | node: true, 43 | }, 44 | plugins: ['node'], 45 | extends: ['plugin:node/recommended'], 46 | }, 47 | { 48 | // Test files: 49 | files: ['tests/**/*-test.{js,ts}'], 50 | extends: ['plugin:qunit/recommended'], 51 | }, 52 | ], 53 | }; 54 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | - master 8 | pull_request: {} 9 | 10 | concurrency: 11 | group: ci-${{ github.head_ref || github.ref }} 12 | cancel-in-progress: true 13 | 14 | jobs: 15 | test: 16 | name: 'Tests' 17 | runs-on: ubuntu-latest 18 | timeout-minutes: 10 19 | 20 | steps: 21 | - uses: actions/checkout@v3 22 | - name: Install Node 23 | uses: actions/setup-node@v3 24 | with: 25 | node-version: 18 26 | cache: yarn 27 | - name: Install Dependencies 28 | run: yarn install --frozen-lockfile 29 | - name: Lint 30 | run: yarn lint 31 | - name: Run Tests 32 | run: yarn test:ember 33 | 34 | floating: 35 | name: 'Floating Dependencies' 36 | runs-on: ubuntu-latest 37 | timeout-minutes: 10 38 | 39 | steps: 40 | - uses: actions/checkout@v3 41 | - uses: actions/setup-node@v3 42 | with: 43 | node-version: 18 44 | cache: yarn 45 | - name: Install Dependencies 46 | run: yarn install --no-lockfile 47 | - name: Run Tests 48 | run: yarn test:ember 49 | 50 | try-scenarios: 51 | name: ${{ matrix.try-scenario }} 52 | runs-on: ubuntu-latest 53 | needs: 'test' 54 | timeout-minutes: 10 55 | 56 | strategy: 57 | fail-fast: false 58 | matrix: 59 | try-scenario: 60 | - ember-lts-3.24 61 | - ember-lts-3.28 62 | - ember-release 63 | - ember-beta 64 | - ember-canary 65 | - embroider-safe 66 | - embroider-optimized 67 | 68 | steps: 69 | - uses: actions/checkout@v3 70 | - name: Install Node 71 | uses: actions/setup-node@v3 72 | with: 73 | node-version: 18 74 | cache: yarn 75 | - name: Install Dependencies 76 | run: yarn install --frozen-lockfile 77 | - name: Run Tests 78 | run: ./node_modules/.bin/ember try:one ${{ matrix.try-scenario }} 79 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist/ 5 | /tmp/ 6 | 7 | # dependencies 8 | /bower_components/ 9 | /node_modules/ 10 | 11 | # misc 12 | /.env* 13 | /.pnp* 14 | /.sass-cache 15 | /.eslintcache 16 | /connect.lock 17 | /coverage/ 18 | /libpeerconnection.log 19 | /npm-debug.log* 20 | /testem.log 21 | /yarn-error.log 22 | 23 | # ember-try 24 | /.node_modules.ember-try/ 25 | /bower.json.ember-try 26 | /package.json.ember-try 27 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # compiled output 2 | /dist/ 3 | /tmp/ 4 | 5 | # dependencies 6 | /bower_components/ 7 | 8 | # misc 9 | /.bowerrc 10 | /.editorconfig 11 | /.ember-cli 12 | /.env* 13 | /.eslintcache 14 | /.eslintignore 15 | /.eslintrc.js 16 | /.git/ 17 | /.gitignore 18 | /.prettierignore 19 | /.prettierrc.js 20 | /.template-lintrc.js 21 | /.travis.yml 22 | /.watchmanconfig 23 | /bower.json 24 | /config/ember-try.js 25 | /CONTRIBUTING.md 26 | /ember-cli-build.js 27 | /testem.js 28 | /tests/ 29 | /yarn-error.log 30 | /yarn.lock 31 | .gitkeep 32 | 33 | # ember-try 34 | /.node_modules.ember-try/ 35 | /bower.json.ember-try 36 | /package.json.ember-try 37 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | # unconventional js 2 | /blueprints/*/files/ 3 | /vendor/ 4 | 5 | # compiled output 6 | /dist/ 7 | /tmp/ 8 | 9 | # dependencies 10 | /bower_components/ 11 | /node_modules/ 12 | 13 | # misc 14 | /coverage/ 15 | !.* 16 | .eslintcache 17 | 18 | # ember-try 19 | /.node_modules.ember-try/ 20 | /bower.json.ember-try 21 | /package.json.ember-try 22 | -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | singleQuote: true, 5 | }; 6 | -------------------------------------------------------------------------------- /.template-lintrc.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | extends: 'recommended', 5 | }; 6 | -------------------------------------------------------------------------------- /.watchmanconfig: -------------------------------------------------------------------------------- 1 | { 2 | "ignore_dirs": ["tmp", "dist"] 3 | } 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | 4 | ## v2.0.0 (February 15th, 2018) 5 | 6 | #### Commits 7 | 8 | - [be6c9d96](https://github.com/bmeurant/ember-array-contains-helper/commit/be6c9d967a62990e296cbf4d55be01de2c8ab8c6) **refactor(includes)**: remove includes polyfill by default *by [Baptiste Meurant](https://github.com/bmeurant)* 9 | 10 | **Breaking changes**: 11 | 12 | Starting from this version, the `ember-runtime-enumerable-includes-polyfill` is not included by default anymore. 13 | If you need to support environments that does not handle the EcmaScript `includes` method, you will have now to explicitely add it as a dependency: `yarn add ember-runtime-enumerable-includes-polyfill`. 14 | 15 | - [7144bac6](https://github.com/bmeurant/ember-array-contains-helper/commit/7144bac620e78c9ce3481fe89501d19c825667ff) **refactor(modules)**: new Modules API, end of support for old versions *by [Baptiste Meurant](https://github.com/bmeurant)* 16 | 17 | **Breaking changes**: 18 | 19 | This versions fully embraces the [new Modules API](https://github.com/emberjs/rfcs/blob/master/text/0176-javascript-module-api.md). 20 | As a direct consequence, it will break compatibility with versions of ember that does not support this new API. 21 | If you have to support older versions, you must prefer the 1.3.x version. 22 | This version and all future versions will test and support only the lasts ember LTS versions and, obviously, the last ember release. 23 | Please see [ember-try config](./config/ember-try.js) for details. 24 | 25 | ## v1.3.2 (May 24th, 2017) 26 | 27 | #### Commits 28 | 29 | - [66cf3ad5](https://github.com/bmeurant/ember-array-contains-helper/commit/66cf3ad51faefdf09f9450a700c9e6b984204930) **refactor(array-contains)**: use ES6 destructuring and default value *by [Baptiste Meurant](https://github.com/bmeurant)* 30 | - [6a6fa30](https://github.com/bmeurant/ember-array-contains-helper/commit/6a6fa3003fa22d3fe001a53b11d541ef6a76613d) **chore(package)**: chore(package): update version for ember-cli-babel *by [Baptiste Meurant](https://github.com/bmeurant)* 31 | 32 | ## v1.3.1 (December 1st, 2016) 33 | 34 | #### Commits 35 | 36 | - [8f7da7fc](https://github.com/bmeurant/ember-array-contains-helper/commit/8f7da7fcfb957f34ad7ca808fbd02e0a621d1077) **fix(includes)**: backward compatibility for Array#includes *by [Baptiste Meurant](https://github.com/bmeurant)* 37 | 38 | ## v1.3.0 (September 12th, 2016) 39 | 40 | #### Commits 41 | 42 | - [1fa7f914](https://github.com/bmeurant/ember-array-contains-helper/commit/1fa7f914eb80b0166a731e9c97504b2129fc3bad) **docs(dummy)**: fix typo *by [Baptiste Meurant](https://github.com/bmeurant)* 43 | - [c2716988](https://github.com/bmeurant/ember-array-contains-helper/commit/c2716988333017bc4dea33e5234cf8b2fc029d5e) **refactor(array-contains)**: use includes polyfill for older ember versions *by [Baptiste Meurant](https://github.com/bmeurant)* 44 | - [3b791647](https://github.com/bmeurant/ember-array-contains-helper/commit/3b7916472c0a301643c78eb6417fc2bdf8908cb2) **fix(array-contains)**: add missing cleanup on destroy *by [Baptiste Meurant](https://github.com/bmeurant)* 45 | - [01842004](https://github.com/bmeurant/ember-array-contains-helper/commit/01842004cf4f5f5f4d9e3f3233313d6e28b00615) **refactor(array-contains)**: remove unnecessary recompute override *by [Baptiste Meurant](https://github.com/bmeurant)* 46 | 47 | ## v1.2.0 (August 3rd, 2016) 48 | 49 | ### Pull Requests 50 | 51 | - [#18](https://github.com/bmeurant/ember-array-contains-helper/pull/18) Prefer includes to contains *by [Baptiste Meurant](https://github.com/bmeurant)* 52 | 53 | #### Commits 54 | 55 | - [27ff101a](https://github.com/bmeurant/ember-array-contains-helper/commit/27ff101aeead2c56d08aba426c6cae24b32c29fe) **docs(yuidocs)**: setup yuidoc & theme, make documentation compliant (#5) *by [Baptiste Meurant](https://github.com/bmeurant)* 56 | - [3be72a20](https://github.com/bmeurant/ember-array-contains-helper/commit/3be72a208d47032c500a4902fcb0818cae07b58a) **feat(includes)**: prefer includes to contains (#18) *by [Baptiste Meurant](https://github.com/bmeurant)* 57 | - [220c0d9e](https://github.com/bmeurant/ember-array-contains-helper/commit/220c0d9eb0886fa3f8074c12b3117011ae92e1e9) **docs(readme)**: update readme *by [Baptiste Meurant](https://github.com/bmeurant)* 58 | - [f4b71e05](https://github.com/bmeurant/ember-array-contains-helper/commit/f4b71e057de302f9979066bcb3bdba41cc18f896) **style(array-contains)**: add some comments *by [Baptiste Meurant](https://github.com/bmeurant)* 59 | - [c4900805](https://github.com/bmeurant/ember-array-contains-helper/commit/c490080573303b77b2ec0ea4535f9111ab503447) **docs(readme)**: update badges *by [Baptiste Meurant](https://github.com/bmeurant)* 60 | - [201f17b4](https://github.com/bmeurant/ember-array-contains-helper/commit/201f17b43224195c25a1e35efff13ab8ab2b0cfa) **refactor(array-contains)**: use unitary imports instead of globals *by [Baptiste Meurant](https://github.com/bmeurant)* 61 | 62 | ## v1.1.0 (July 3rd, 2016) 63 | 64 | - [7e91d68](https://github.com/bmeurant/ember-array-contains-helper/commit/7e91d68dc4615e698f69598ed08a2ad9c8877aeb) Update bower dependencies 65 | - [dc26c18](https://github.com/bmeurant/ember-array-contains-helper/commit/dc26c181b5d97bedcb00279e44e6be86fcb80670) [TOOLING] Switch to ember-cli-mirage 0.2.1 66 | - [924c511](https://github.com/bmeurant/ember-array-contains-helper/commit/924c511eec55d1ca58a34e1f24aff53ad9f65e81) [TOOLING] Switch to ember-cli-code-coverage 67 | - [3a35c0a](https://github.com/bmeurant/ember-array-contains-helper/commit/3a35c0aaaa5e026ddb513c02b78d7a71a8c017f1) Update to ember-cli 2.6.2 & ember 2.6 68 | - [9dc51a3](https://github.com/bmeurant/ember-array-contains-helper/commit/9dc51a345bd24b50fd0876d0e76b4f3c5961bbdb) [DOC] Format to JSDoc 69 | 70 | ## v1.0.2 (December 16, 2015) 71 | 72 | - [#1](https://github.com/bmeurant/ember-array-contains-helper/issues/1) [BUGFIX] Do not throw error anymore when array is null or undefined but return false. 73 | - [DOC] Add changelog 74 | 75 | ## v1.0.1 (December 14, 2015) 76 | 77 | - Improve tests 78 | - Switch from ES6 destructuring assignement to standard ES5 assigment because of coverage fails 79 | - Update Documenttation in README - add tooling badges 80 | - Add coverage with ember-cli-blanket 81 | 82 | ## v1.0.0 (December 13, 2015) 83 | 84 | - Initial addon version 85 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How To Contribute 2 | 3 | ## Installation 4 | 5 | * `git clone ` 6 | * `cd ember-array-contains-helper` 7 | * `npm install` 8 | 9 | ## Linting 10 | 11 | * `npm run lint` 12 | * `npm run lint:fix` 13 | 14 | ## Running tests 15 | 16 | * `ember test` – Runs the test suite on the current Ember version 17 | * `ember test --server` – Runs the test suite in "watch mode" 18 | * `ember try:each` – Runs the test suite against multiple Ember versions 19 | 20 | ## Running the dummy application 21 | 22 | * `ember serve` 23 | * Visit the dummy application at [http://localhost:4200](http://localhost:4200). 24 | 25 | For more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/). 26 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ember-array-contains-helper 2 | 3 | ## Important notice !! 4 | 5 | **This addon is not maintained** 6 | 7 | In recent Ember versions, you problem don't need an addon for this case. 8 | With the introduction of [helper functions](https://guides.emberjs.com/release/components/helper-functions/), you can just easily create a local helper 9 | that checks if an element is contained in an array. 10 | 11 | If you want the helper to react to add/removals, you should be using some version of a "reactive" array. Either [`EmberArray`](https://api.emberjs.com/ember/5.5/classes/EmberArray) or `TrackedArray` from [tracked-built-ins](https://github.com/tracked-tools/tracked-built-ins). See demo [here](https://limber.glimdown.com/edit?c=AYjmCsGcAIBsEsBuBTaAHATsx9kHcAoeAWzQHsMAXaAYTNLIDtlHqAzDe6AcgAFQExYsgwB6AMb1yzVtwDcRBlWgBvaJQwBDcQGtkAE2gBfaBy58BJYWI3ad8RqHmLyytU2OnOxHr2TEAIxFRYjJ9eDZcDGcSV2o1AEFPMx8%2BfyCxTQwtAE9nAmQADzjofWQ2TQBXWGpxWE1IGAAJZFhYMgB1ClhDIsoWfRg6Bhl4gmhoXltdA2gs3OgAXmhmPGgEgAoAbQAGABpoAEYDgCYDgGYAXQBKBXG57M0culZNBxhljfmD%2BH7ia6WAD4HhgAHQOOqVMqQDa-fy3e73ShkUACZAAST%2BS2gGwBi2BKnuE1gyGoDjKhWxlAAFvBIKD5k9wYwKQB5NgbAAsCImEwiOPJRSWi2WAFpDgDCbzeTS6QzHjkGfp9KyAuBkOJKFyebyTK1IKgpdL1LT6YzFVhQihVerNdqicZ7kYFBN7gAeP5oer9QEOt1oQEJBXQCGwKHIGBw4gAfmgbsgGiYoEBKhUsrNCpelDejBg6flC05RiMbtECc4jkBpYDDr9AUqlGRjFUKg8ACI6vBdG2TXLkaiSZj-MXAQAVFFokN-Uv1xtMX0TUue73IX1GAggYAEIA&format=glimdown). 12 | 13 | In any case, this addon should be compatible with basically every ember version from 3.28 to 5.x. 14 | 15 | [![npm version](https://img.shields.io/npm/v/ember-array-contains-helper.svg)](https://www.npmjs.com/package/ember-array-contains-helper) 16 | [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE.md) 17 | 18 | [![Ember Observer Score](http://emberobserver.com/badges/ember-array-contains-helper.svg)](http://emberobserver.com/addons/ember-array-contains-helper) 19 | 20 | Ember template helper allowing to test if an array contains a particular element. 21 | 22 | ```hbs 23 | {{array-contains this.model 'value' property='title'}} 24 | ``` 25 | 26 | This helper allows to test the presence of a literal, a full object or a specific property/value of 27 | an object inside a given array. Objects can be native or Ember objects. 28 | 29 | ## Compatibility 30 | 31 | - This helper is tested against Ember 3.28+ 32 | 33 | ## Troubleshooting 34 | 35 | Before its version 2.x, this addon came with a polyfill (`ember-runtime-enumerable-includes-polyfill`) emulating the native EcmaScript method `includes` in case you wanted to run it within an environment that did not support this method. 36 | 37 | Since its version 2.x, the polyfill is not included by default and this addon relies on the fact that it is run in an environment supporting the `includes` method. 38 | Errors will occur if it is not the case. 39 | 40 | If you want to use this addon in an older browser or environment that does not support `includes`, you must then now explicitely add the polyfill as a regular dependency: `yarn add ember-runtime-enumerable-includes-polyfill`. 41 | 42 | ## Installation 43 | 44 | - `ember install ember-array-contains-helper` 45 | 46 | ## Usage 47 | 48 | ```hbs 49 | {{array-contains [property='']}} 50 | ``` 51 | 52 | Where: 53 | 54 | - `` is the array to search into. Should be a valid not null array. 55 | - `` is the value which is supposed to be contained in the arrray. Could be an object or a literal, null or undefined. 56 | - `` is an option: if set, the search is done on the presence of an object containing a 57 | property `` with the value ``. If not, the search is done of the presence of the full 58 | `` (object or literal) 59 | 60 | This helper could be: 61 | 62 | - used standalone: 63 | ```hbs 64 | {{array-contains this.model 'value' property='title'}} 65 | ``` 66 | - or, more often, combined with the `if` helper: 67 | ```hbs 68 | {{if 69 | (array-contains this.model 'value' property='title') 70 | 'something' 71 | 'something else' 72 | }} 73 | ``` 74 | 75 | Depending on the given parameters, the test is made on 76 | 77 | - the presence of a literal: 78 | 79 | ```javascript 80 | // routes/application.js 81 | 82 | import Route from '@ember/routing/route'; 83 | 84 | export default class ApplicationRoute extends Route { 85 | model() { 86 | return ['Akira', 'Blacksad', 'CalvinAndHobbes']; 87 | } 88 | } 89 | ``` 90 | 91 | ```hbs 92 | {{! templates/application.hbs }} 93 | 94 | {{array-contains this.model 'Akira'}} 95 | ``` 96 | 97 | - the presence of the object itself: 98 | 99 | ```javascript 100 | // routes/application.js 101 | 102 | import Route from '@ember/routing/route'; 103 | import Comic from '../models/comic'; 104 | 105 | let blackSad = Comic.create({ 106 | title: 'Blacksad', 107 | }); 108 | 109 | let calvinAndHobbes = Comic.create({ 110 | title: 'Calvin and Hobbes', 111 | }); 112 | 113 | let akira = Comic.create({ 114 | title: 'Akira', 115 | }); 116 | 117 | export default class ApplicationRoute extends Route { 118 | model() { 119 | return [akira, blacksad, calvinAndHobbes]; 120 | } 121 | 122 | setupController(controller) { 123 | super.setupController(...arguments); 124 | controller.calvinAndHobbes = calvinAndHobbes; 125 | } 126 | } 127 | ``` 128 | 129 | ```hbs 130 | {{! templates/application.hbs }} 131 | 132 | {{array-contains this.model this.calvinAndHobbes}} 133 | ``` 134 | 135 | - the presence of an object containing a specific property with a specific value using the option `property`: 136 | 137 | ```javascript 138 | // routes/application.js 139 | 140 | import Route from '@ember/routing/route'; 141 | import { inject as service } from '@ember/service'; 142 | 143 | export default class ApplicationRoute extends Route { 144 | @service store; 145 | 146 | model() { 147 | return this.store.findAll('comic'); 148 | } 149 | } 150 | ``` 151 | 152 | ```hbs 153 | {{! templates/application.hbs }} 154 | 155 | {{array-contains this.model 'Blacksad' property='title'}} 156 | ``` 157 | 158 | ### `null` and `undefined` 159 | 160 | `null` and `undefined` are considered acceptable values for 'value' parameter. 161 | 162 | - **until ember 2.9**, `null` and `undefined` are both coerced to `null` by the templating engine. The following 163 | expressions are therefore both leading to check for the presence of a `null` value inside the array: 164 | 165 | ```hbs 166 | {{array-contains collection null}} 167 | {{array-contains collection undefined}} 168 | ``` 169 | 170 | - **ember 2.10 (glimmer)** changed this behaviour. `undefined` are then preserved and not coerced to `null` anymore. 171 | 172 | It could eventually break some apps relying on the initial behaviour but it has been considered as a fix since the first behaviour 173 | was accidental. See [this issue](https://github.com/emberjs/ember.js/issues/14016) for details. 174 | 175 | ## Development 176 | 177 | ### Installation 178 | 179 | - `git clone https://github.com/bmeurant/ember-array-contains-helper` 180 | - `cd ember-array-contains-helper` 181 | - `npm install` 182 | 183 | ### Running dummy demo app 184 | 185 | - `npm install` 186 | - `ember server` 187 | - Visit your app at [http://localhost:4200](http://localhost:4200). 188 | 189 | ### Linting 190 | 191 | - `npm run lint:js` 192 | - `npm run lint:js -- --fix` 193 | 194 | ### Running Tests 195 | 196 | - `ember test` – Runs the test suite on the current Ember version 197 | - `ember test --server` – Runs the test suite in "watch mode" 198 | - `npm test` – Runs `ember try:each` to test your addon against multiple Ember versions 199 | 200 | ### Building 201 | 202 | - `ember build` 203 | 204 | ### Generating documentation 205 | 206 | This addon uses [YUIDoc](http://yui.github.io/yuidoc/) via [ember-cli-yuidoc](https://github.com/cibernox/ember-cli-yuidoc). [yuidoc-ember-cli-theme](https://github.com/Turbo87/yuidoc-ember-cli-theme) makes it pretty. 207 | Docs generation is enabled in development mode via `ember build` or `ember serve` with or without --docs auto refresh option. It can also be explicitely generated with `ember ember-cli-yuidoc` 208 | command. 209 | 210 | For more information on using ember-cli, visit [https://www.ember-cli.com/](https://www.ember-cli.com/). 211 | -------------------------------------------------------------------------------- /addon/helpers/array-contains.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @module ember-array-contains-helper 3 | */ 4 | 5 | import { isNone } from '@ember/utils'; 6 | import { A as emberArray, isArray } from '@ember/array'; 7 | import { helper } from '@ember/component/helper'; 8 | 9 | /** 10 | * Helper providing a way to test the presence of an item in an array. 11 | * 12 | * Depending on the given parameters, the test is made on 13 | * - the presence of a **literal**: 14 | * ``{{array-contains array 'foo'}}`` 15 | * - the presence of **the object itself**: 16 | * ``{{array-contains array object}}`` 17 | * - the presence of **an object containing a specific property with a specific value**: 18 | * ``{{array-contains array 'value' property='title'}}`` 19 | * 20 | * Note that null or undefined are considered acceptable and equivalent values for 'value' parameter (resolve both to null) 21 | * 22 | * This helper could be used standalone or, more often, combined with the ``if`` helper: 23 | * 24 | * ```html 25 | * {{if (array-contains array 'value' property='title') 'something' 'something else'}} 26 | * ``` 27 | * 28 | * 29 | * 30 | * @public 31 | * @function arrayContains 32 | * @param {Array} params array and value to test. Array can be null, undefined or valid Array. 33 | * value could be a literal or an object 34 | * @param {Object} hash named arguments accepted by this helper (``property``) 35 | * @return {Boolean} 36 | * - true if: 37 | * - the array in ``params[0]`` contains the object value in ``params[1]`` 38 | * - the array in ``params[0]`` contains an object holding a property named ``hash.property`` with value equals to ``params[1]`` 39 | * - false otherwise and if the array in ``params[0]`` is null or undefined 40 | * 41 | * @throws {Ember.Error} if the given array (from ``params[0]``) is not null and not an array. 42 | */ 43 | export function arrayContains([array, value], { property }) { 44 | // if array undefined or null, we test against an empty array. This is particularily useful 45 | // if the test occurs before a promise is resolved, for example 46 | if (isNone(array)) { 47 | array = emberArray([]); 48 | } 49 | 50 | if (!isArray(array)) { 51 | throw new Error('First parameter should be a valid array'); 52 | } 53 | 54 | // Wrap into an Ember.Array to use advanced methods while supporting disabling prototype extensions 55 | // Note: This operation does not modify the original array 56 | let wrappedArray = emberArray(array); 57 | 58 | if (property) { 59 | // Property provided, test the property 60 | return wrappedArray.isAny(property, value); 61 | } else { 62 | // No property provided, test the full object 63 | return wrappedArray.includes(value); 64 | } 65 | } 66 | 67 | export default helper(arrayContains); 68 | -------------------------------------------------------------------------------- /app/helpers/array-contains.js: -------------------------------------------------------------------------------- 1 | export { 2 | default, 3 | arrayContains, 4 | } from 'ember-array-contains-helper/helpers/array-contains'; 5 | -------------------------------------------------------------------------------- /config/ember-try.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const getChannelURL = require('ember-source-channel-url'); 4 | const { embroiderSafe, embroiderOptimized } = require('@embroider/test-setup'); 5 | 6 | module.exports = async function () { 7 | return { 8 | useYarn: true, 9 | scenarios: [ 10 | { 11 | name: 'ember-lts-3.24', 12 | npm: { 13 | devDependencies: { 14 | 'ember-source': '~3.24.3', 15 | }, 16 | }, 17 | }, 18 | { 19 | name: 'ember-lts-3.28', 20 | npm: { 21 | devDependencies: { 22 | 'ember-source': '~3.28.0', 23 | }, 24 | }, 25 | }, 26 | { 27 | name: 'ember-release', 28 | npm: { 29 | devDependencies: { 30 | 'ember-source': await getChannelURL('release'), 31 | }, 32 | }, 33 | }, 34 | { 35 | name: 'ember-beta', 36 | npm: { 37 | devDependencies: { 38 | 'ember-source': await getChannelURL('beta'), 39 | }, 40 | }, 41 | }, 42 | { 43 | name: 'ember-canary', 44 | npm: { 45 | devDependencies: { 46 | 'ember-source': await getChannelURL('canary'), 47 | }, 48 | }, 49 | }, 50 | { 51 | name: 'ember-default-with-jquery', 52 | env: { 53 | EMBER_OPTIONAL_FEATURES: JSON.stringify({ 54 | 'jquery-integration': true, 55 | }), 56 | }, 57 | npm: { 58 | devDependencies: { 59 | '@ember/jquery': '^1.1.0', 60 | }, 61 | }, 62 | }, 63 | { 64 | name: 'ember-classic', 65 | env: { 66 | EMBER_OPTIONAL_FEATURES: JSON.stringify({ 67 | 'application-template-wrapper': true, 68 | 'default-async-observers': false, 69 | 'template-only-glimmer-components': false, 70 | }), 71 | }, 72 | npm: { 73 | devDependencies: { 74 | 'ember-source': '~3.28.0', 75 | }, 76 | ember: { 77 | edition: 'classic', 78 | }, 79 | }, 80 | }, 81 | embroiderSafe(), 82 | embroiderOptimized(), 83 | ], 84 | }; 85 | }; 86 | -------------------------------------------------------------------------------- /config/environment.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function (/* environment, appConfig */) { 4 | return {}; 5 | }; 6 | -------------------------------------------------------------------------------- /config/targets.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const browsers = [ 4 | 'last 1 Chrome versions', 5 | 'last 1 Firefox versions', 6 | 'last 1 Safari versions', 7 | ]; 8 | 9 | module.exports = { 10 | browsers, 11 | }; 12 | -------------------------------------------------------------------------------- /ember-cli-build.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const EmberAddon = require('ember-cli/lib/broccoli/ember-addon'); 4 | 5 | module.exports = function (defaults) { 6 | let app = new EmberAddon(defaults, { 7 | snippetSearchPaths: ['app', 'tests'], 8 | }); 9 | 10 | /* 11 | This build file specifies the options for the dummy test app of this 12 | addon, located in `/tests/dummy` 13 | This build file does *not* influence how the addon or the app using it 14 | behave. You most likely want to be modifying `./index.js` or app's build file 15 | */ 16 | 17 | const { maybeEmbroider } = require('@embroider/test-setup'); 18 | return maybeEmbroider(app, { 19 | skipBabel: [ 20 | { 21 | package: 'qunit', 22 | }, 23 | ], 24 | }); 25 | }; 26 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | name: require('./package').name, 5 | }; 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ember-array-contains-helper", 3 | "version": "3.0.0", 4 | "description": "Ember helper to test the presence of an item in an array", 5 | "keywords": [ 6 | "ember-addon" 7 | ], 8 | "license": "MIT", 9 | "author": "Baptiste Meurant ", 10 | "directories": { 11 | "doc": "doc", 12 | "test": "tests" 13 | }, 14 | "repository": "https://github.com/bmeurant/ember-array-contains-helper", 15 | "scripts": { 16 | "build": "ember build --environment=production", 17 | "lint": "npm-run-all --aggregate-output --continue-on-error --parallel \"lint:!(fix)\"", 18 | "lint:fix": "npm-run-all --aggregate-output --continue-on-error --parallel lint:*:fix", 19 | "lint:hbs": "ember-template-lint .", 20 | "lint:hbs:fix": "ember-template-lint . --fix", 21 | "lint:js": "eslint . --cache", 22 | "lint:js:fix": "eslint . --fix", 23 | "start": "ember serve", 24 | "test": "npm-run-all lint test:*", 25 | "test:ember": "ember test", 26 | "test:ember-compatibility": "ember try:each", 27 | "deploy": "ember github-pages:commit --message \"Deploy gh-pages from commit $(git rev-parse HEAD)\" --environment production; git push; git checkout -" 28 | }, 29 | "dependencies": { 30 | "ember-cli-babel": "^7.26.10" 31 | }, 32 | "devDependencies": { 33 | "@ember/optional-features": "^2.0.0", 34 | "@ember/string": "^3.1.1", 35 | "@ember/test-helpers": "^2.6.0", 36 | "@embroider/test-setup": "^3.0.3", 37 | "@glimmer/component": "^1.0.4", 38 | "@glimmer/tracking": "^1.0.4", 39 | "babel-eslint": "^10.1.0", 40 | "broccoli-asset-rev": "^3.0.0", 41 | "ember-auto-import": "^2.7.2", 42 | "ember-cli": "^3.28.6", 43 | "ember-cli-app-version": "^6.0.0", 44 | "ember-cli-dependency-checker": "^3.2.0", 45 | "ember-cli-htmlbars": "^5.7.2", 46 | "ember-cli-inject-live-reload": "^2.1.0", 47 | "ember-cli-sri": "^2.1.1", 48 | "ember-cli-terser": "^4.0.2", 49 | "ember-disable-prototype-extensions": "^1.1.3", 50 | "ember-load-initializers": "^2.1.2", 51 | "ember-qunit": "^5.1.5", 52 | "ember-resolver": "^10.1.0", 53 | "ember-source": "~3.28.8", 54 | "ember-source-channel-url": "^3.0.0", 55 | "ember-template-lint": "^3.15.0", 56 | "ember-try": "^1.4.0", 57 | "eslint": "^7.32.0", 58 | "eslint-config-prettier": "^8.3.0", 59 | "eslint-plugin-ember": "^10.5.8", 60 | "eslint-plugin-node": "^11.1.0", 61 | "eslint-plugin-prettier": "^3.4.1", 62 | "eslint-plugin-qunit": "^6.2.0", 63 | "loader.js": "^4.7.0", 64 | "npm-run-all": "^4.1.5", 65 | "prettier": "^2.5.1", 66 | "qunit": "^2.17.2", 67 | "qunit-dom": "^1.6.0", 68 | "webpack": "^5.89.0" 69 | }, 70 | "engines": { 71 | "node": "12.* || 14.* || >= 16" 72 | }, 73 | "ember": { 74 | "edition": "octane" 75 | }, 76 | "ember-addon": { 77 | "configPath": "tests/dummy/config", 78 | "demoURL": "http://baptiste.meurant.io/ember-array-contains-helper/" 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /testem.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | test_page: 'tests/index.html?hidepassed', 5 | disable_watching: true, 6 | launch_in_ci: ['Chrome'], 7 | launch_in_dev: ['Chrome'], 8 | browser_start_timeout: 120, 9 | browser_args: { 10 | Chrome: { 11 | ci: [ 12 | // --no-sandbox is needed when running Chrome inside a container 13 | process.env.CI ? '--no-sandbox' : null, 14 | '--headless', 15 | '--disable-dev-shm-usage', 16 | '--disable-software-rasterizer', 17 | '--mute-audio', 18 | '--remote-debugging-port=0', 19 | '--window-size=1440,900', 20 | ].filter(Boolean), 21 | }, 22 | }, 23 | }; 24 | -------------------------------------------------------------------------------- /tests/dummy/app/app.js: -------------------------------------------------------------------------------- 1 | import Application from '@ember/application'; 2 | import Resolver from 'ember-resolver'; 3 | import loadInitializers from 'ember-load-initializers'; 4 | import config from 'dummy/config/environment'; 5 | 6 | export default class App extends Application { 7 | modulePrefix = config.modulePrefix; 8 | podModulePrefix = config.podModulePrefix; 9 | Resolver = Resolver; 10 | } 11 | 12 | loadInitializers(App, config.modulePrefix); 13 | -------------------------------------------------------------------------------- /tests/dummy/app/components/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmeurant/ember-array-contains-helper/a32bad10351604c8ea170ce6e83f9b8442b5e1a9/tests/dummy/app/components/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/helpers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmeurant/ember-array-contains-helper/a32bad10351604c8ea170ce6e83f9b8442b5e1a9/tests/dummy/app/helpers/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Ember Array Contains Helper Demo 7 | 8 | 9 | 10 | {{content-for "head"}} 11 | 12 | 13 | 14 | 15 | {{content-for "head-footer"}} 16 | 17 | 18 | {{content-for "body"}} 19 | 20 | 21 | 22 | 23 | {{content-for "body-footer"}} 24 | 25 | 26 | -------------------------------------------------------------------------------- /tests/dummy/app/router.js: -------------------------------------------------------------------------------- 1 | import EmberRouter from '@ember/routing/router'; 2 | import config from 'dummy/config/environment'; 3 | 4 | export default class Router extends EmberRouter { 5 | location = config.locationType; 6 | rootURL = config.rootURL; 7 | } 8 | 9 | Router.map(function () {}); 10 | -------------------------------------------------------------------------------- /tests/dummy/app/styles/app.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmeurant/ember-array-contains-helper/a32bad10351604c8ea170ce6e83f9b8442b5e1a9/tests/dummy/app/styles/app.css -------------------------------------------------------------------------------- /tests/dummy/config/ember-cli-update.json: -------------------------------------------------------------------------------- 1 | { 2 | "schemaVersion": "1.0.0", 3 | "packages": [ 4 | { 5 | "name": "ember-cli", 6 | "version": "3.28.6", 7 | "blueprints": [ 8 | { 9 | "name": "addon", 10 | "outputRepo": "https://github.com/ember-cli/ember-addon-output", 11 | "codemodsSource": "ember-addon-codemods-manifest@1", 12 | "isBaseBlueprint": true, 13 | "options": [ 14 | "--no-welcome" 15 | ] 16 | } 17 | ] 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /tests/dummy/config/environment.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function (environment) { 4 | let ENV = { 5 | modulePrefix: 'dummy', 6 | environment, 7 | rootURL: '/', 8 | locationType: 'auto', 9 | EmberENV: { 10 | FEATURES: { 11 | // Here you can enable experimental features on an ember canary build 12 | // e.g. EMBER_NATIVE_DECORATOR_SUPPORT: true 13 | }, 14 | EXTEND_PROTOTYPES: { 15 | // Prevent Ember Data from overriding Date.parse. 16 | Date: false, 17 | }, 18 | }, 19 | 20 | APP: { 21 | // Here you can pass flags/options to your application instance 22 | // when it is created 23 | }, 24 | }; 25 | 26 | if (environment === 'development') { 27 | // ENV.APP.LOG_RESOLVER = true; 28 | // ENV.APP.LOG_ACTIVE_GENERATION = true; 29 | // ENV.APP.LOG_TRANSITIONS = true; 30 | // ENV.APP.LOG_TRANSITIONS_INTERNAL = true; 31 | // ENV.APP.LOG_VIEW_LOOKUPS = true; 32 | } 33 | 34 | if (environment === 'test') { 35 | // Testem prefers this... 36 | ENV.locationType = 'none'; 37 | 38 | // keep test console output quieter 39 | ENV.APP.LOG_ACTIVE_GENERATION = false; 40 | ENV.APP.LOG_VIEW_LOOKUPS = false; 41 | 42 | ENV.APP.rootElement = '#ember-testing'; 43 | ENV.APP.autoboot = false; 44 | } 45 | 46 | if (environment === 'production') { 47 | // prod options 48 | } 49 | 50 | return ENV; 51 | }; 52 | -------------------------------------------------------------------------------- /tests/dummy/config/optional-features.json: -------------------------------------------------------------------------------- 1 | { 2 | "application-template-wrapper": false, 3 | "default-async-observers": true, 4 | "jquery-integration": false, 5 | "template-only-glimmer-components": true 6 | } 7 | -------------------------------------------------------------------------------- /tests/dummy/config/targets.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const browsers = [ 4 | 'last 1 Chrome versions', 5 | 'last 1 Firefox versions', 6 | 'last 1 Safari versions', 7 | ]; 8 | 9 | // Ember's browser support policy is changing, and IE11 support will end in 10 | // v4.0 onwards. 11 | // 12 | // See https://deprecations.emberjs.com/v3.x#toc_3-0-browser-support-policy 13 | // 14 | // If you need IE11 support on a version of Ember that still offers support 15 | // for it, uncomment the code block below. 16 | // 17 | // const isCI = Boolean(process.env.CI); 18 | // const isProduction = process.env.EMBER_ENV === 'production'; 19 | // 20 | // if (isCI || isProduction) { 21 | // browsers.push('ie 11'); 22 | // } 23 | 24 | module.exports = { 25 | browsers, 26 | }; 27 | -------------------------------------------------------------------------------- /tests/dummy/public/robots.txt: -------------------------------------------------------------------------------- 1 | # http://www.robotstxt.org 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /tests/helpers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmeurant/ember-array-contains-helper/a32bad10351604c8ea170ce6e83f9b8442b5e1a9/tests/helpers/.gitkeep -------------------------------------------------------------------------------- /tests/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Dummy Tests 7 | 8 | 9 | 10 | {{content-for "head"}} 11 | {{content-for "test-head"}} 12 | 13 | 14 | 15 | 16 | 17 | {{content-for "head-footer"}} 18 | {{content-for "test-head-footer"}} 19 | 20 | 21 | {{content-for "body"}} 22 | {{content-for "test-body"}} 23 | 24 |
25 |
26 |
27 |
28 |
29 |
30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | {{content-for "body-footer"}} 38 | {{content-for "test-body-footer"}} 39 | 40 | 41 | -------------------------------------------------------------------------------- /tests/integration/helpers/array-contains-test.js: -------------------------------------------------------------------------------- 1 | import { run } from '@ember/runloop'; 2 | import EmberObject, { set } from '@ember/object'; 3 | import { hbs } from 'ember-cli-htmlbars'; 4 | import { render, setupOnerror } from '@ember/test-helpers'; 5 | 6 | import { module, test } from 'qunit'; 7 | import { setupRenderingTest } from 'ember-qunit'; 8 | 9 | module('helper:array-contains', function (hooks) { 10 | setupRenderingTest(hooks); 11 | 12 | test('should not throw error if array undefined or null', async function (assert) { 13 | this.set('array', undefined); 14 | 15 | await render(hbs` 16 | {{array-contains this.array 'any'}} 17 | `); 18 | 19 | assert.dom().hasText('false', 'array should not contain anything'); 20 | 21 | this.set('array', null); 22 | 23 | assert.dom().hasText('false', 'array should not contain anything'); 24 | }); 25 | 26 | // Asserting error thrown no longer works as of ember 2.11 27 | // TODO: unskip once https://github.com/emberjs/ember.js/issues/15013 is resolved (2.17). 28 | test('should throw error if array is invalid', async function (assert) { 29 | assert.expect(1); 30 | 31 | this.set('array', 'any'); 32 | 33 | setupOnerror(function (error) { 34 | const { message } = error; 35 | assert.strictEqual(message, 'First parameter should be a valid array'); 36 | }); 37 | 38 | await render(hbs` 39 | {{array-contains this.array 'any'}} 40 | `); 41 | }); 42 | 43 | test('should return true if literal contained', async function (assert) { 44 | this.set('array', ['c', 'string', 0, true, null]); 45 | 46 | this.array.push(undefined); 47 | 48 | await render(hbs`{{array-contains this.array 'c'}}`); 49 | 50 | assert.dom().hasText('true', "array should contain 'c'"); 51 | 52 | await render(hbs`{{array-contains this.array 'string'}}`); 53 | assert.dom().hasText('true', "array should contain 'string'"); 54 | 55 | await render(hbs`{{array-contains this.array 0}}`); 56 | assert.dom().hasText('true', "array should contain '0'"); 57 | 58 | await render(hbs`{{array-contains this.array true}}`); 59 | assert.dom().hasText('true', "array should contain 'true'"); 60 | 61 | await render(hbs`{{array-contains this.array null}}`); 62 | assert.dom().hasText('true', "array should contain 'null'"); 63 | 64 | await render(hbs`{{array-contains this.array undefined}}`); 65 | assert.dom().hasText('true', "array should contain 'undefined'"); 66 | }); 67 | 68 | test('should return false if literal not contained', async function (assert) { 69 | this.set('array', ['c', 'string', 0, true, null]); 70 | 71 | await render(hbs`{{array-contains this.array 'a'}}`); 72 | assert.dom().hasText('false', "array should not contain 'a'"); 73 | 74 | await render(hbs`{{array-contains this.array 'foo'}}`); 75 | assert.dom().hasText('false', "array should not contain 'foo'"); 76 | 77 | await render(hbs`{{array-contains this.array 2}}`); 78 | assert.dom().hasText('false', "array should not contain '2'"); 79 | 80 | await render(hbs`{{array-contains this.array false}}`); 81 | assert.dom().hasText('false', "array should not contain 'false'"); 82 | 83 | await render(hbs`{{array-contains this.array undefined}}`); 84 | assert.dom().hasText('false', "array should not contain 'undefined'"); 85 | }); 86 | 87 | test('should return true if native object contained', async function (assert) { 88 | let elem = { id: 1, title: 'any' }; 89 | this.set('array', [elem]); 90 | this.set('elem', elem); 91 | 92 | await render(hbs`{{array-contains this.array this.elem}}`); 93 | assert.dom().hasText('true', 'array should contain elem'); 94 | }); 95 | 96 | test('should return false if native object not contained', async function (assert) { 97 | this.set('array', [{ id: 2, title: 'other' }]); 98 | this.set('elem', { id: 1, title: 'any' }); 99 | 100 | await render(hbs`{{array-contains this.array this.elem}}`); 101 | assert.dom().hasText('false', 'array should not contain elem'); 102 | }); 103 | 104 | test('should recompute when native object change', async function (assert) { 105 | let elem = { id: 1, title: 'any' }; 106 | this.set('array', [elem]); 107 | this.set('elem', elem); 108 | 109 | await render(hbs`{{array-contains this.array this.elem}}`); 110 | assert.dom().hasText('true', 'array should contain elem'); 111 | 112 | this.set('elem', {}); 113 | 114 | assert.dom().hasText('false', 'array should not contain elem'); 115 | 116 | this.set('elem', elem); 117 | 118 | assert.dom().hasText('true', 'array should contain elem'); 119 | 120 | this.set('elem', { id: 1, title: 'any' }); 121 | 122 | assert.dom().hasText('false', 'array should not contain elem'); 123 | }); 124 | 125 | test('should return true if Ember object contained', async function (assert) { 126 | let elem = EmberObject.create({ id: 1, title: 'any' }); 127 | this.set('array', [elem]); 128 | this.set('elem', elem); 129 | 130 | await render(hbs`{{array-contains this.array this.elem}}`); 131 | assert.dom().hasText('true', 'array should contain elem'); 132 | }); 133 | 134 | test('should return false if Ember object not contained', async function (assert) { 135 | this.set('array', [EmberObject.create({ id: 2, title: 'other' })]); 136 | this.set('elem', EmberObject.create({ id: 1, title: 'any' })); 137 | 138 | await render(hbs`{{array-contains this.array this.elem}}`); 139 | assert.dom().hasText('false', 'array should not contain elem'); 140 | }); 141 | 142 | test('should recompute when Ember object change', async function (assert) { 143 | let elem = EmberObject.create({ id: 1, title: 'any' }); 144 | this.set('array', [elem]); 145 | this.set('elem', elem); 146 | 147 | await render(hbs`{{array-contains this.array this.elem}}`); 148 | assert.dom().hasText('true', 'array should contain elem'); 149 | 150 | this.set('elem', {}); 151 | 152 | assert.dom().hasText('false', 'array should not contain elem'); 153 | 154 | this.set('elem', elem); 155 | 156 | assert.dom().hasText('true', 'array should contain elem'); 157 | 158 | this.set('elem', EmberObject.create({ id: 1, title: 'any' })); 159 | 160 | assert.dom().hasText('false', 'array should not contain elem'); 161 | }); 162 | 163 | test('should return true if native object property contained', async function (assert) { 164 | this.set('array', [{ id: 1, title: 'any' }]); 165 | 166 | await render(hbs`{{array-contains this.array 'any' property='title'}}`); 167 | assert.dom().hasText('true', "array should contain 'any' title"); 168 | }); 169 | 170 | test('should return false if native object property not contained', async function (assert) { 171 | this.set('array', [{ id: 2, title: 'other' }]); 172 | 173 | await render(hbs`{{array-contains this.array 'any' property='title'}}`); 174 | assert.dom().hasText('false', "array should not contain 'any' title"); 175 | }); 176 | 177 | test('should return true if Ember object contained 1', async function (assert) { 178 | let elem = EmberObject.create({ id: 1, title: 'any' }); 179 | this.set('array', [elem]); 180 | this.set('elem', elem); 181 | 182 | await render(hbs`{{array-contains this.array this.elem}}`); 183 | assert.dom().hasText('true', 'array should contain elem'); 184 | }); 185 | 186 | test('should return false if Ember object not contained 2', async function (assert) { 187 | let elem = EmberObject.create({ id: 1, title: 'any' }); 188 | this.set('array', [EmberObject.create({ id: 2, title: 'other' })]); 189 | this.set('elem', elem); 190 | 191 | await render(hbs`{{array-contains this.array this.elem}}`); 192 | assert.dom().hasText('false', 'array should not contain elem'); 193 | }); 194 | 195 | test('should recompute when Ember object change 3', async function (assert) { 196 | let elem = EmberObject.create({ id: 1, title: 'any' }); 197 | this.set('array', [elem]); 198 | this.set('elem', elem); 199 | 200 | await render(hbs`{{array-contains this.array this.elem}}`); 201 | assert.dom().hasText('true', 'array should contain elem'); 202 | 203 | this.set('elem', {}); 204 | 205 | assert.dom().hasText('false', 'array should not contain elem'); 206 | 207 | this.set('elem', elem); 208 | 209 | assert.dom().hasText('true', 'array should contain elem'); 210 | 211 | this.set('elem', EmberObject.create({ id: 1, title: 'any' })); 212 | 213 | assert.dom().hasText('false', 'array should not contain elem'); 214 | }); 215 | 216 | test('should return true if Ember object property contained', async function (assert) { 217 | this.set('array', [EmberObject.create({ id: 1, title: 'any' })]); 218 | 219 | await render(hbs`{{array-contains this.array 'any' property='title'}}`); 220 | assert.dom().hasText('true', "array should contain 'any' title"); 221 | }); 222 | 223 | test('should return false if Ember object property not contained', async function (assert) { 224 | this.set('array', [EmberObject.create({ id: 2, title: 'other' })]); 225 | 226 | await render(hbs`{{array-contains this.array 'any' property='title'}}`); 227 | assert.dom().hasText('false', "array should not contain 'any' title"); 228 | }); 229 | 230 | test('should rerun test when array replaced', async function (assert) { 231 | this.set('array', ['any']); 232 | 233 | await render(hbs`{{array-contains this.array 'any'}}`); 234 | assert.dom().hasText('true', "array should contain 'any'"); 235 | 236 | this.set('array', ['not']); 237 | 238 | assert.dom().hasText('false', "array should not contain 'any'"); 239 | }); 240 | 241 | test('should rerun test when array changed', async function (assert) { 242 | let array = ['any']; 243 | this.set('array', array); 244 | 245 | await render(hbs`{{array-contains this.array 'any'}}`); 246 | assert.dom().hasText('true', "array should contain 'any'"); 247 | 248 | run(() => { 249 | array.popObject(); 250 | }); 251 | 252 | assert.dom().hasText('false', "array should not contain 'any'"); 253 | 254 | run(() => { 255 | array.pushObject('any'); 256 | }); 257 | 258 | assert.dom().hasText('true', "array should contain 'any'"); 259 | }); 260 | 261 | test('should rerun test when property in array changed', async function (assert) { 262 | let object = { id: 1, title: 'any' }; 263 | let array = [object]; 264 | this.set('array', array); 265 | 266 | await render(hbs`{{array-contains this.array 'any' property='title'}}`); 267 | assert.dom().hasText('true', "array should contain object with prop 'any'"); 268 | 269 | run(() => { 270 | set(object, 'title', 'not'); 271 | }); 272 | 273 | assert 274 | .dom() 275 | .hasText('false', "array should not contain object with prop 'any'"); 276 | 277 | run(() => { 278 | set(object, 'title', 'any'); 279 | }); 280 | 281 | assert.dom().hasText('true', "array should contain object with prop 'any'"); 282 | }); 283 | 284 | test('should return true in nested if if Ember object property contained', async function (assert) { 285 | this.set('array', [EmberObject.create({ id: 1, title: 'any' })]); 286 | 287 | await render( 288 | hbs`{{if (array-contains this.array 'any' property='title') 'ifTrue' 'ifFalse'}}` 289 | ); 290 | assert.dom().hasText('ifTrue', "array should contain 'any' title"); 291 | }); 292 | 293 | test('should return false in nested if if Ember object property not contained', async function (assert) { 294 | this.set('array', [EmberObject.create({ id: 2, title: 'other' })]); 295 | 296 | await render( 297 | hbs`{{if (array-contains this.array 'any' property='title') 'ifTrue' 'ifFalse'}}` 298 | ); 299 | assert.dom().hasText('ifFalse', "array should not contain 'any' title"); 300 | }); 301 | }); 302 | -------------------------------------------------------------------------------- /tests/test-helper.js: -------------------------------------------------------------------------------- 1 | import Application from 'dummy/app'; 2 | import config from 'dummy/config/environment'; 3 | import * as QUnit from 'qunit'; 4 | import { setApplication } from '@ember/test-helpers'; 5 | import { setup } from 'qunit-dom'; 6 | import { start } from 'ember-qunit'; 7 | 8 | setApplication(Application.create(config.APP)); 9 | 10 | setup(QUnit.assert); 11 | 12 | start(); 13 | -------------------------------------------------------------------------------- /tests/unit/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmeurant/ember-array-contains-helper/a32bad10351604c8ea170ce6e83f9b8442b5e1a9/tests/unit/.gitkeep -------------------------------------------------------------------------------- /vendor/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmeurant/ember-array-contains-helper/a32bad10351604c8ea170ce6e83f9b8442b5e1a9/vendor/.gitkeep --------------------------------------------------------------------------------