From a170fc1a749effa98bfd1c2e1b30297ed47b451b Mon Sep 17 00:00:00 2001
From: Lucas Galfasó
Date: Fri, 12 Jul 2013 17:20:40 -0300
Subject: feat(ngPluralize): add alternative mapping using attributes
Add an alternative way to define a mapping for ng:pluralize using
attributes instead of the `when` attribute
Closes #2454
---
test/ng/directive/ngPluralizeSpec.js | 63 ++++++++++++++++++++++++++++++++++--
1 file changed, 60 insertions(+), 3 deletions(-)
(limited to 'test/ng/directive/ngPluralizeSpec.js')
diff --git a/test/ng/directive/ngPluralizeSpec.js b/test/ng/directive/ngPluralizeSpec.js
index 0ca2d23e..4d596efd 100644
--- a/test/ng/directive/ngPluralizeSpec.js
+++ b/test/ng/directive/ngPluralizeSpec.js
@@ -1,11 +1,13 @@
'use strict';
describe('ngPluralize', function() {
- var element;
+ var element,
+ elementAlt;
afterEach(function(){
dealoc(element);
+ dealoc(elementAlt);
});
@@ -13,10 +15,18 @@ describe('ngPluralize', function() {
beforeEach(inject(function($rootScope, $compile) {
element = $compile(
'" +
'')($rootScope);
+ elementAlt = $compile(
+ '" +
+ '')($rootScope);
}));
@@ -24,38 +34,52 @@ describe('ngPluralize', function() {
$rootScope.email = 0;
$rootScope.$digest();
expect(element.text()).toBe('You have no new email');
+ expect(elementAlt.text()).toBe('You have no new email');
$rootScope.email = '0';
$rootScope.$digest();
expect(element.text()).toBe('You have no new email');
+ expect(elementAlt.text()).toBe('You have no new email');
$rootScope.email = 1;
$rootScope.$digest();
expect(element.text()).toBe('You have one new email');
+ expect(elementAlt.text()).toBe('You have one new email');
$rootScope.email = 0.01;
$rootScope.$digest();
expect(element.text()).toBe('You have 0.01 new emails');
+ expect(elementAlt.text()).toBe('You have 0.01 new emails');
$rootScope.email = '0.1';
$rootScope.$digest();
expect(element.text()).toBe('You have 0.1 new emails');
+ expect(elementAlt.text()).toBe('You have 0.1 new emails');
$rootScope.email = 2;
$rootScope.$digest();
expect(element.text()).toBe('You have 2 new emails');
+ expect(elementAlt.text()).toBe('You have 2 new emails');
$rootScope.email = -0.1;
$rootScope.$digest();
expect(element.text()).toBe('You have -0.1 new emails');
+ expect(elementAlt.text()).toBe('You have -0.1 new emails');
$rootScope.email = '-0.01';
$rootScope.$digest();
expect(element.text()).toBe('You have -0.01 new emails');
+ expect(elementAlt.text()).toBe('You have -0.01 new emails');
$rootScope.email = -2;
$rootScope.$digest();
expect(element.text()).toBe('You have -2 new emails');
+ expect(elementAlt.text()).toBe('You have -2 new emails');
+
+ $rootScope.email = -1;
+ $rootScope.$digest();
+ expect(element.text()).toBe('You have negative email. Whohoo!');
+ expect(elementAlt.text()).toBe('You have negative email. Whohoo!');
}));
@@ -63,38 +87,47 @@ describe('ngPluralize', function() {
$rootScope.email = '';
$rootScope.$digest();
expect(element.text()).toBe('');
+ expect(elementAlt.text()).toBe('');
$rootScope.email = null;
$rootScope.$digest();
expect(element.text()).toBe('');
+ expect(elementAlt.text()).toBe('');
$rootScope.email = undefined;
$rootScope.$digest();
expect(element.text()).toBe('');
+ expect(elementAlt.text()).toBe('');
$rootScope.email = 'a3';
$rootScope.$digest();
expect(element.text()).toBe('');
+ expect(elementAlt.text()).toBe('');
$rootScope.email = '011';
$rootScope.$digest();
expect(element.text()).toBe('You have 11 new emails');
+ expect(elementAlt.text()).toBe('You have 11 new emails');
$rootScope.email = '-011';
$rootScope.$digest();
expect(element.text()).toBe('You have -11 new emails');
+ expect(elementAlt.text()).toBe('You have -11 new emails');
$rootScope.email = '1fff';
$rootScope.$digest();
expect(element.text()).toBe('You have one new email');
+ expect(elementAlt.text()).toBe('You have one new email');
$rootScope.email = '0aa22';
$rootScope.$digest();
expect(element.text()).toBe('You have no new email');
+ expect(elementAlt.text()).toBe('You have no new email');
$rootScope.email = '000001';
$rootScope.$digest();
expect(element.text()).toBe('You have one new email');
+ expect(elementAlt.text()).toBe('You have one new email');
}));
});
@@ -117,35 +150,48 @@ describe('ngPluralize', function() {
describe('deal with pluralized strings with offset', function() {
it('should show single/plural strings with offset', inject(function($rootScope, $compile) {
element = $compile(
- "" +
"")($rootScope);
+ elementAlt = $compile(
+ "" +
+ "")($rootScope);
$rootScope.p1 = 'Igor';
$rootScope.p2 = 'Misko';
$rootScope.viewCount = 0;
$rootScope.$digest();
expect(element.text()).toBe('Nobody is viewing.');
+ expect(elementAlt.text()).toBe('Nobody is viewing.');
$rootScope.viewCount = 1;
$rootScope.$digest();
expect(element.text()).toBe('Igor is viewing.');
+ expect(elementAlt.text()).toBe('Igor is viewing.');
$rootScope.viewCount = 2;
$rootScope.$digest();
expect(element.text()).toBe('Igor and Misko are viewing.');
+ expect(elementAlt.text()).toBe('Igor and Misko are viewing.');
$rootScope.viewCount = 3;
$rootScope.$digest();
expect(element.text()).toBe('Igor, Misko and one other person are viewing.');
+ expect(elementAlt.text()).toBe('Igor, Misko and one other person are viewing.');
$rootScope.viewCount = 4;
$rootScope.$digest();
expect(element.text()).toBe('Igor, Misko and 2 other people are viewing.');
+ expect(elementAlt.text()).toBe('Igor, Misko and 2 other people are viewing.');
}));
});
@@ -165,23 +211,34 @@ describe('ngPluralize', function() {
"'one': '[[p1%% and one other person are viewing.'," +
"'other': '[[p1%% and {} other people are viewing.'}\">" +
"")($rootScope);
+ elementAlt = $compile(
+ "" +
+ "")($rootScope);
$rootScope.p1 = 'Igor';
$rootScope.viewCount = 0;
$rootScope.$digest();
expect(element.text()).toBe('Nobody is viewing.');
+ expect(elementAlt.text()).toBe('Nobody is viewing.');
$rootScope.viewCount = 1;
$rootScope.$digest();
expect(element.text()).toBe('Igor is viewing.');
+ expect(elementAlt.text()).toBe('Igor is viewing.');
$rootScope.viewCount = 2;
$rootScope.$digest();
expect(element.text()).toBe('Igor and one other person are viewing.');
+ expect(elementAlt.text()).toBe('Igor and one other person are viewing.');
$rootScope.viewCount = 3;
$rootScope.$digest();
expect(element.text()).toBe('Igor and 2 other people are viewing.');
+ expect(elementAlt.text()).toBe('Igor and 2 other people are viewing.');
});
})
});
--
cgit v1.2.3