From aeefb7cc58cf8c7f9ef9211851bb12855d055c0e Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Mon, 10 Nov 2014 09:27:44 +0000 Subject: [PATCH] step-11 Custom Filters - Implement a custom `checkmark` filter. - Update the `phoneDetail` template to use the `checkmark` filter. - Add a unit test for the `checkmark` filter. --- app/app.module.js | 1 + app/core/checkmark/checkmark.filter.js | 9 +++++++++ app/core/checkmark/checkmark.filter.spec.js | 14 ++++++++++++++ app/core/core.module.js | 4 ++++ app/index.html | 2 ++ app/phone-detail/phone-detail.template.html | 10 +++++----- 6 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 app/core/checkmark/checkmark.filter.js create mode 100644 app/core/checkmark/checkmark.filter.spec.js create mode 100644 app/core/core.module.js diff --git a/app/app.module.js b/app/app.module.js index b4f676f30..651b0a20b 100644 --- a/app/app.module.js +++ b/app/app.module.js @@ -3,6 +3,7 @@ // Define the `phonecatApp` module angular.module('phonecatApp', [ 'ngRoute', + 'core', 'phoneDetail', 'phoneList' ]); diff --git a/app/core/checkmark/checkmark.filter.js b/app/core/checkmark/checkmark.filter.js new file mode 100644 index 000000000..0132dfc02 --- /dev/null +++ b/app/core/checkmark/checkmark.filter.js @@ -0,0 +1,9 @@ +'use strict'; + +angular. + module('core'). + filter('checkmark', function() { + return function(input) { + return input ? '\u2713' : '\u2718'; + }; + }); diff --git a/app/core/checkmark/checkmark.filter.spec.js b/app/core/checkmark/checkmark.filter.spec.js new file mode 100644 index 000000000..4d53baab9 --- /dev/null +++ b/app/core/checkmark/checkmark.filter.spec.js @@ -0,0 +1,14 @@ +'use strict'; + +describe('checkmark', function() { + + beforeEach(module('core')); + + it('should convert boolean values to unicode checkmark or cross', + inject(function(checkmarkFilter) { + expect(checkmarkFilter(true)).toBe('\u2713'); + expect(checkmarkFilter(false)).toBe('\u2718'); + }) + ); + +}); diff --git a/app/core/core.module.js b/app/core/core.module.js new file mode 100644 index 000000000..93922c310 --- /dev/null +++ b/app/core/core.module.js @@ -0,0 +1,4 @@ +'use strict'; + +// Define the `core` module +angular.module('core', []); diff --git a/app/index.html b/app/index.html index e8457c675..653eb7453 100644 --- a/app/index.html +++ b/app/index.html @@ -9,6 +9,8 @@ + + diff --git a/app/phone-detail/phone-detail.template.html b/app/phone-detail/phone-detail.template.html index 02a9d8eb9..45ea62b09 100644 --- a/app/phone-detail/phone-detail.template.html +++ b/app/phone-detail/phone-detail.template.html @@ -48,9 +48,9 @@

{{$ctrl.phone.name}}

Bluetooth
{{$ctrl.phone.connectivity.bluetooth}}
Infrared
-
{{$ctrl.phone.connectivity.infrared}}
+
{{$ctrl.phone.connectivity.infrared | checkmark}}
GPS
-
{{$ctrl.phone.connectivity.gps}}
+
{{$ctrl.phone.connectivity.gps | checkmark}}
  • @@ -79,7 +79,7 @@

    {{$ctrl.phone.name}}

    Screen resolution
    {{$ctrl.phone.display.screenResolution}}
    Touch screen
    -
    {{$ctrl.phone.display.touchScreen}}
    +
    {{$ctrl.phone.display.touchScreen | checkmark}}
  • @@ -92,9 +92,9 @@

    {{$ctrl.phone.name}}

    Audio / headphone jack
    {{$ctrl.phone.hardware.audioJack}}
    FM Radio
    -
    {{$ctrl.phone.hardware.fmRadio}}
    +
    {{$ctrl.phone.hardware.fmRadio | checkmark}}
    Accelerometer
    -
    {{$ctrl.phone.hardware.accelerometer}}
    +
    {{$ctrl.phone.hardware.accelerometer | checkmark}}