-
Notifications
You must be signed in to change notification settings - Fork 75
Add tests, switch tests to page objects #1 #1069
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,12 @@ | ||
| import BeforeOptionsComponent from 'ember-power-select/components/power-select/before-options'; | ||
| import Ember from 'ember'; | ||
|
|
||
| const { get } = Ember; | ||
|
|
||
| export default BeforeOptionsComponent.extend({ | ||
| actions: { | ||
| close() { | ||
| this.get('selectRemoteController').actions.close(); | ||
| get(this, 'selectRemoteController').actions.close(); | ||
| } | ||
| } | ||
| }); |
51 changes: 45 additions & 6 deletions
51
tests/integration/components/select-inline-dropdown/list-item-test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,51 @@ | ||
| import { moduleForComponent, test } from 'ember-qunit'; | ||
| import hbs from 'htmlbars-inline-precompile'; | ||
| import pageComponent from 'code-corps-ember/tests/pages/components/select-inline-dropdown/list-item'; | ||
| import PageObject from 'ember-cli-page-object'; | ||
| import Ember from 'ember'; | ||
|
|
||
| moduleForComponent('select-inline-dropdown/list-item', 'Integration | Component | select inline dropdown/list item', { | ||
| integration: true | ||
| }); | ||
| const { setProperties } = Ember; | ||
|
|
||
| let page = PageObject.create(pageComponent); | ||
|
|
||
| moduleForComponent( | ||
| 'select-inline-dropdown/list-item', | ||
| 'Integration | Component | select inline dropdown/list item', { | ||
| integration: true, | ||
| beforeEach() { | ||
| page.setContext(this); | ||
| }, | ||
| afterEach() { | ||
| page.removeContext(); | ||
| } | ||
| } | ||
| ); | ||
|
|
||
| function renderPage() { | ||
| page.render(hbs` | ||
| {{select-inline-dropdown/list-item | ||
| iconUrl=iconUrl | ||
| primaryText=primaryText | ||
| secondaryText=secondaryText | ||
| lastSearchedText=lastSearchedText | ||
| }}`); | ||
| } | ||
|
|
||
| test('it renders correctly', function(assert) { | ||
| assert.expect(5); | ||
|
|
||
| let iconUrl = 'testurl'; | ||
| let primaryText = 'Test'; | ||
| let secondaryText = 'testuser'; | ||
| let lastSearchedText = 'est'; | ||
|
|
||
| setProperties(this, { iconUrl, primaryText, secondaryText, lastSearchedText }); | ||
|
|
||
| test('it renders', function(assert) { | ||
| this.render(hbs`{{select-inline-dropdown/list-item}}`); | ||
| renderPage(); | ||
|
|
||
| assert.equal(this.$().text().trim(), ''); | ||
| assert.equal(page.icon.url, iconUrl, 'Icon is rendered.'); | ||
| assert.equal(page.primary.text, primaryText, 'Primary text is rendered.'); | ||
| assert.equal(page.primary.highlighted.text, lastSearchedText, 'Filtered text is rendered on primary.'); | ||
| assert.equal(page.secondary.text, secondaryText, 'Secondary text is rendered.'); | ||
| assert.equal(page.secondary.highlighted.text, lastSearchedText, 'Filtered text is rendered on secondary.'); | ||
| }); |
22 changes: 22 additions & 0 deletions
22
tests/pages/components/select-inline-dropdown/list-item.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { attribute } from 'ember-cli-page-object'; | ||
|
|
||
| export default { | ||
| icon: { | ||
| scope: '.select-inline-dropdown__list-item__icon', | ||
| url: attribute('src', 'img') | ||
| }, | ||
|
|
||
| primary: { | ||
| scope: '.select-inline-dropdown__list-item__content__primary', | ||
| highlighted: { | ||
| scope: 'strong' | ||
| } | ||
| }, | ||
|
|
||
| secondary: { | ||
| scope: '.select-inline-dropdown__list-item__content__secondary', | ||
| highlighted: { | ||
| scope: 'strong' | ||
| } | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| import { moduleFor, test } from 'ember-qunit'; | ||
| import Ember from 'ember'; | ||
|
|
||
| const { set } = Ember; | ||
|
|
||
| moduleFor('adapter:task', 'Unit | Adapter | task'); | ||
|
|
||
| test('"sortQueryParams" passes through (and underscores) any keys that arent special', function(assert) { | ||
| assert.expect(2); | ||
|
|
||
| let adapter = this.subject(); | ||
|
|
||
| assert.deepEqual( | ||
| adapter.sortQueryParams({ foo: 'bar' }), | ||
| { foo: 'bar' }, | ||
| 'Leaves single-word keys untouched.' | ||
| ); | ||
|
|
||
| assert.deepEqual( | ||
| adapter.sortQueryParams({ camelFoo: 'bar' }), | ||
| { camel_foo: 'bar' }, | ||
| 'Underscores camelCase keys.' | ||
| ); | ||
| }); | ||
|
|
||
| test('"sortQueryParams" moves page param into query sub-object if present', function(assert) { | ||
| assert.expect(5); | ||
|
|
||
| let adapter = this.subject(); | ||
|
|
||
| assert.deepEqual( | ||
| adapter.sortQueryParams({ page: 'foo' }), | ||
| { page: { page: 'foo' } }, | ||
| 'When there is a page key, it needs to be nested.' | ||
| ); | ||
|
|
||
| assert.deepEqual( | ||
| adapter.sortQueryParams({ page: undefined }), | ||
| { }, | ||
| 'An undefined value is discarded.' | ||
| ); | ||
|
|
||
| assert.deepEqual( | ||
| adapter.sortQueryParams({ page: null }), | ||
| { }, | ||
| 'A null value is discarded.' | ||
| ); | ||
|
|
||
| assert.deepEqual( | ||
| adapter.sortQueryParams({ page: null }), | ||
| { }, | ||
| 'An empty string value is discarded.' | ||
| ); | ||
|
|
||
| assert.deepEqual( | ||
| adapter.sortQueryParams({ page: '' }), | ||
| { }, | ||
| 'An empty string value is discarded.' | ||
| ); | ||
| }); | ||
|
|
||
| test('"sortQueryParams" discards "projectId"', function(assert) { | ||
| assert.expect(6); | ||
|
|
||
| let adapter = this.subject(); | ||
|
|
||
| assert.deepEqual( | ||
| adapter.sortQueryParams({ projectId: 'bar' }), | ||
| { }, | ||
| 'Discards "projectId" when it has a value.' | ||
| ); | ||
|
|
||
| assert.deepEqual( | ||
| adapter.sortQueryParams({ projectId: '' }), | ||
| { }, | ||
| 'Discards "projectId" when empty string.' | ||
| ); | ||
|
|
||
| assert.deepEqual( | ||
| adapter.sortQueryParams({ projectId: null }), | ||
| { }, | ||
| 'Discards "projectId" when null.' | ||
| ); | ||
|
|
||
| assert.deepEqual( | ||
| adapter.sortQueryParams({ projectId: undefined }), | ||
| { }, | ||
| 'Discards "projectId" undefined.' | ||
| ); | ||
|
|
||
| assert.deepEqual( | ||
| adapter.sortQueryParams({ projectId: [] }), | ||
| { }, | ||
| 'Discards "projectId" when blank array.' | ||
| ); | ||
|
|
||
| assert.deepEqual( | ||
| adapter.sortQueryParams({ }), | ||
| { }, | ||
| 'Works on blank object.' | ||
| ); | ||
| }); | ||
|
|
||
| test('"urlForQuery" makes "projectId" part of the path', function(assert) { | ||
| assert.expect(1); | ||
|
|
||
| let adapter = this.subject(); | ||
| set(adapter, 'host', 'test'); | ||
|
|
||
| assert.equal( | ||
| adapter.urlForQuery({ projectId: 2 }), | ||
| 'test/projects/2/tasks', | ||
| '"projectId" is correctly made part of the path.' | ||
| ); | ||
| }); | ||
|
|
||
| test('"urlForQueryRecord" makes "projectId" and "number" part of the path', function(assert) { | ||
| assert.expect(1); | ||
|
|
||
| let adapter = this.subject(); | ||
| set(adapter, 'host', 'test'); | ||
|
|
||
| assert.equal( | ||
| adapter.urlForQueryRecord({ projectId: 2, number: 5 }), | ||
| 'test/projects/2/tasks/5', | ||
| '"projectId" and "number" are correctly made part of the path.' | ||
| ); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { moduleForComponent, test } from 'ember-qunit'; | ||
| import Ember from 'ember'; | ||
|
|
||
| const { Controller, set } = Ember; | ||
|
|
||
| moduleForComponent( | ||
| 'power-select/before-options', | ||
| 'Unit | Component | power select before options', | ||
| { | ||
| unit: true | ||
| } | ||
| ); | ||
|
|
||
| test('close action calls "close" action on assigned "selectRemoteController"', function(assert) { | ||
| assert.expect(1); | ||
|
|
||
| let stubController = Controller.extend({ | ||
| actions: { | ||
| close() { | ||
| assert.ok(true, 'Action was called'); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| let component = this.subject(); | ||
| set(component, 'selectRemoteController', stubController.create()); | ||
| component.send('close'); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is a unit component test vs an integration? Not sure I've seen this distinction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An integration test will partially boot the app (albeit not fully, like an acceptance test). It is also expected to render the component, which will have access to (and render) all subcomponents/services/etc.
The intention of an integration test it so check how the component is working with connected parts (while not fully starting the app) and how it interacts with the user/other layers.
The purpose of a component unit test would be to simply execute the component code to test, for example, some complex function within the component.