Workshop
AngularJS 1.x Team Lead
Make sure you have node installed
clone using git
git clone https://github.com/petebacondarwin/foodme-further
or download zip file
https://github.com/petebacondarwin/foodme-further/archive/master.zip
or copy from USB stick
Set up the tools and workspace
A JavaScript library for writing unit tests
angular-mocks.js provides helper methods
Write and run some simple unit tests
Angular provides various mock services to help with testing
$httpBackend.when(...).respond(...);
$httpBackend.flush();
$rootScope.$digest();
Mocking services in unit tests
When injecting we can wrap params in underscores
inject(function(_$http_) { ... })
There are two ways to get hold of a filter
Create unit tests for rating filter
The general approach is:
We can clean up our tests by defining custom matchers:
expect(element.find('li')).toHaveClass('selected', 3);
karma-ng-html2js-preprocessor
Create unit tests for `fmRating` component
Implement routing to enable multiple URL driven views
Add additional static views and navigation links
Install & configure protractor
Create and run basic e2e tests
Use a PageObject to make e2e tests clearer
$location.path() provides the relative path to the current route
Provides hooks to trigger animations declaratively
Applying a CSS class to an element, in combination with ngAnimate specific CSS classes, allows you to trigger animations with an animation enabled directive
Add animated navigation indicators
Add a shared restaurantService
Routes can be parameterized to match more than one URL:
The value of the parameters are made available on the $routeParams service
.when('/restaurants/:id', { ... });
Add a new view for a single restaurant showing its menu
Display a menu on the restaurant page
Services are injected based on named parameters:
But if you minimize the code then you lose the name
so you must annotate
or
function FmRestaurantView(restaurantService, currentOrder, $state) { ... }
function FmRestaurantView(a, b, c) { ... }
['restaurantService', 'currentOrder', '$state',
function FmRestaurantView(restaurantService, currentOrder, $state) { ... }]
FmRestaurantView.$inject = ['restaurantService', 'currentOrder', '$state'];
Add injection annotations to prevent minification issues
Enable ordering of items from the menu