|
| 1 | +library main_test; |
| 2 | + |
| 3 | +import 'package:unittest/unittest.dart'; |
| 4 | +import 'package:di/di.dart'; |
| 5 | +import 'package:di/dynamic_injector.dart'; |
| 6 | +import 'package:angular/angular.dart'; |
| 7 | +import 'package:angular/mock/module.dart'; |
| 8 | + |
| 9 | +import 'main.dart'; |
| 10 | + |
| 11 | +main() { |
| 12 | + setUp(() { |
| 13 | + setUpInjector(); |
| 14 | + module((Module m) => m.install(new MyAppModule())); |
| 15 | + }); |
| 16 | + tearDown(tearDownInjector); |
| 17 | + |
| 18 | + group('recipe-book', () { |
| 19 | + test('should load recipes', async(inject((Injector injector, |
| 20 | + MockHttpBackend backend) { |
| 21 | + backend.expectGET('recipes.json').respond('[{"name": "test1"}]'); |
| 22 | + backend.expectGET('categories.json').respond('["c1"]'); |
| 23 | + |
| 24 | + var recipesController = injector.get(RecipeBookController); |
| 25 | + expect(recipesController.recipes, isEmpty); |
| 26 | + |
| 27 | + microLeap(); |
| 28 | + backend.flush(); |
| 29 | + microLeap(); |
| 30 | + |
| 31 | + expect(recipesController.recipes, isNot(isEmpty)); |
| 32 | + }))); |
| 33 | + |
| 34 | + test('should select recipe', async(inject((Injector injector, |
| 35 | + MockHttpBackend backend) { |
| 36 | + backend.expectGET('recipes.json').respond('[{"name": "test1"}]'); |
| 37 | + backend.expectGET('categories.json').respond('["c1"]'); |
| 38 | + |
| 39 | + var recipesController = injector.get(RecipeBookController); |
| 40 | + expect(recipesController.recipes, isEmpty); |
| 41 | + |
| 42 | + microLeap(); |
| 43 | + backend.flush(); |
| 44 | + microLeap(); |
| 45 | + |
| 46 | + var recipe = recipesController.recipes[0]; |
| 47 | + recipesController.selectRecipe(recipe); |
| 48 | + expect(recipesController.selectedRecipe, same(recipe)); |
| 49 | + }))); |
| 50 | + }); |
| 51 | + |
| 52 | + group('rating component', () { |
| 53 | + test('should show the right number of stars', inject((RatingComponent rating) { |
| 54 | + rating.maxRating = '5'; |
| 55 | + expect(rating.stars, equals([1, 2, 3, 4, 5])); |
| 56 | + })); |
| 57 | + |
| 58 | + test('should handle click', inject((RatingComponent rating) { |
| 59 | + rating.maxRating = '5'; |
| 60 | + rating.handleClick(3); |
| 61 | + expect(rating.rating, equals(3)); |
| 62 | + |
| 63 | + rating.handleClick(1); |
| 64 | + expect(rating.rating, equals(1)); |
| 65 | + |
| 66 | + rating.handleClick(1); |
| 67 | + expect(rating.rating, equals(0)); |
| 68 | + |
| 69 | + rating.handleClick(1); |
| 70 | + expect(rating.rating, equals(1)); |
| 71 | + })); |
| 72 | + }); |
| 73 | + |
| 74 | + group('categoryFilter', () { |
| 75 | + test('should return subset', inject((CategoryFilter filter) { |
| 76 | + var r1 = new Recipe(null, 'C1', null, null, null); |
| 77 | + var r2 = new Recipe(null, 'C2', null, null, null); |
| 78 | + var list = [r1, r2]; |
| 79 | + var map = {"C1": false, "C2": true}; |
| 80 | + expect(filter(list, map), equals([r2])); |
| 81 | + })); |
| 82 | + }); |
| 83 | +} |
0 commit comments