Skip to content
This repository has been archived by the owner on May 26, 2019. It is now read-only.

More gradual testing intro #1818

Merged
merged 6 commits into from
Mar 22, 2017

Conversation

toddjordan
Copy link
Contributor

@toddjordan toddjordan commented Feb 20, 2017

Addresses #1718
Fixes #1863

Still in need of some proof reading, and would like a couple of people to walk through this version of the tutorial, since its a pretty big change.

@toddjordan toddjordan force-pushed the more-gradual-testing-intro branch 2 times, most recently from 0c5c736 to 3f64a38 Compare February 20, 2017 06:29
@homu
Copy link
Contributor

homu commented Mar 9, 2017

☔ The latest upstream changes (presumably e257e8b) made this pull request unmergeable. Please resolve the merge conflicts.

@locks
Copy link
Contributor

locks commented Mar 9, 2017

Poo, it's a significant conflict :\

@toddjordan toddjordan force-pushed the more-gradual-testing-intro branch 4 times, most recently from 86d8c0b to 3347d42 Compare March 14, 2017 06:22
move tests after content

Move back tests for route, complex component, and service sections

fix spelling errors

another spelling fix

fix lifecycle link

Fix links

More seperation between test and features
@toddjordan toddjordan changed the title [WIP]More gradual testing intro More gradual testing intro Mar 14, 2017
@toddjordan
Copy link
Contributor Author

Also made several updates that address some of the initial comments in #1708

test('should list available rentals.', function (assert) {
});
The launched Chrome web browser shows 10 successful tests.
Ember generates tests that lint each file you create using [JSHint](http://jshint.com/).
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be changed to eslint now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As of 2.11 (which I think the tutorial is at), its still installing jshint.

Running `ember test --server` will show a total of 7 failed tests out of 15.
Each of the 6 tests defined above will fail, plus you'll notice one JSHint failure saying, `assert is defined but never used`.
The tests we defined fail because a QUnit test fails if it is empty.
Tests require a check for a specific condition (known as an `assert`).

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is a great compromise on de-emphasizing testing.

Since we're using Mirage in our development environment, Mirage will return the data we've provided.
When we deploy our app to a production server, we will need to provide a backend for Ember Data to communicate with.
Since we've already set up Ember Mirage in our development environment, Mirage will return the data we requested.
When we deploy our app to a production server, we will likely want to provide a backend server for Ember Data to communicate with to store and retrieve persisted data from.
Copy link
Contributor

Choose a reason for hiding this comment

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

...for storing and retrieving persisted data. Anything saved only in Ember Data's local store will be lost when we close our app.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The last sentence might be confusing because we are talking in this paragraph about using mirage vs a remote server. Will have to think about how to elaborate on providing a backend.
"...we will likely want to replace Mirage with a remote server for Ember Data to communicate with for storing and retrieving persisted data. A remote server will allow for data to be shared and updated across users."

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense.

Copy link
Contributor

@theroncross theroncross left a comment

Choose a reason for hiding this comment

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

This strikes me as a much more reasonable approach, especially for beginners.

The [`vendor` directory](../../addons-and-dependencies/managing-dependencies/#toc_other-assets) in Ember is a special directory where you can include content that gets compiled into your application.

As Ember CLI runs, it takes the `ember-tutorial` CSS file and puts it in a file called `vendor.css`.
The `vender.css` file is referenced in `app/index.html`, making the styles available at runtime.
Copy link
Contributor

Choose a reason for hiding this comment

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

The vendor.css ...

As Ember CLI runs, it takes the `ember-tutorial` CSS file and puts it in `vendor.css` (which is referenced in `app/index.html`).
The addon works by generating a file called `ember-tutorial.css` and putting that file in the super-rentals `vendor` directory.

The [`vendor` directory](../../addons-and-dependencies/managing-dependencies/#toc_other-assets) in Ember is a special directory where you can include content that gets compiled into your application.
Copy link
Contributor

Choose a reason for hiding this comment

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

When Ember CLI builds our app from our source code, it copies ember-tutorial.css into a file called vendor.css.

Run the tests again using the command `ember t -s`, and toggle "Hide passed tests" to show your new passing test.

Now we are listing rentals, and and verifying it with an acceptance test.
This leaves us with 2 remaining acceptance test failure (and 1 jshint failure):
Copy link
Contributor

Choose a reason for hiding this comment

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

... test failures...

@@ -256,7 +247,7 @@ export default Ember.Route.extend({
});
```

Now visiting the root route `/` will result in the `/rentals` URL loading.
Now visiting the root URL `/` will result in the `/rentals` URL loading.
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't route more correct here?

});
});
```

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a quick breakdown of the test here.

assert.equal() takes three arguments. The first two can be any expression, but are usually a test helper followed by the expected result. assert.equal() simply returns true if the expressions are equal, and false if they aren't. The third is a user-friendly message that will be displayed in the test runner. A thorough test suite could be written with nothing but assert.equal() calls.

The CLI `generate util` command will create a utility file and a unit test.
We'll delete the unit test since we don't want to test Google code.
Our app needs a single function, `createMap`, which makes use of `google.maps.Map` to create our map element, `google.maps.Geocoder` to lookup the coordinates of our location, and `google.maps.Marker` to pin our map based on the resolved location.
Finally open the template file for our `rental-listing` component and add the new `location-map` component.
Copy link
Contributor

Choose a reason for hiding this comment

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

You may have noticed that this.get('location') refers to a property location we haven't defined. This property will be passed in to the component by its parent template.


We'll use a unit test to validate the service.
Unit tests are more isolated than integration tests and acceptance test,
and are intended for testing specific login within a class.
Copy link
Contributor

Choose a reason for hiding this comment

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

login logic

When the service calls `createMap` on our fake utility, we will run asserts to validate that it is called.
In our first test notice that we expect four asserts to be run in line 17. Two of the asserts run in the test function, while the other two are run when `createMap` is called.

In the second test, only one assert is expected (line 26), since the map element is fetch from cache and does not use the utility.
Copy link
Contributor

Choose a reason for hiding this comment

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

fetched

```

Now lets render our component using the `render` function.
The `render` function allows use to pass a template string, so that we can declare the component in the same way we do in our templates.
Copy link
Contributor

Choose a reason for hiding this comment

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

use

test('should display rental details', function(assert) {
this.set('rentalObj', rental);
this.render(hbs`{{rental-listing rental=rentalObj}}`);
assert.equal(this.$('.listing h3').text(), 'test-title');
Copy link
Contributor

Choose a reason for hiding this comment

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

Add messages for continuity with earlier tests?

@toddjordan
Copy link
Contributor Author

Thank you so much @theroncross for reviewing! I'll address these this weekend.

@locks locks mentioned this pull request Mar 19, 2017
Closed
This was referenced Mar 20, 2017
Closed
@toddjordan
Copy link
Contributor Author

if you want to review the tutorial without installing middleman, one option is to walk through the rendered markdown files in order:

@acorncom
Copy link
Contributor

@toddjordan Nice work on this. Just sent in a PR to tweak, refine and simplify the language on the first three pages. I think we should merge what we have here and we can keep editorializing on it as we go.

@toddjordan
Copy link
Contributor Author

thanks @acorncom !

Additional tweaks and adjustments to the tutorial
@toddjordan toddjordan merged commit 9202b8f into emberjs:master Mar 22, 2017
@toddjordan toddjordan deleted the more-gradual-testing-intro branch March 22, 2017 00:24
@toddjordan toddjordan mentioned this pull request Mar 22, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants