Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <gerwitm@lovullo.com>2016-06-27 11:37:27 -0400
committerMike Gerwitz <gerwitm@lovullo.com>2016-06-28 10:27:56 -0400
commitb90f6d7474adda808147c0dbbb98d27b417845e6 (patch)
treeb7dbeee992ec2a26a5f55fc3e9327e1914a9aaa2 /test/validate
parent31f3ab010edc4bdbb22b5d47d386b45d882a6fa5 (diff)
downloadliza-b90f6d7474adda808147c0dbbb98d27b417845e6.tar.gz
liza-b90f6d7474adda808147c0dbbb98d27b417845e6.tar.bz2
liza-b90f6d7474adda808147c0dbbb98d27b417845e6.zip
Add accept/reject styler
* src/validate/formatter/AcceptReject.js: Added. * test/validate/formatter/AcceptRejectTest.js: Added.
Diffstat (limited to 'test/validate')
-rw-r--r--test/validate/formatter/AcceptRejectTest.js93
1 files changed, 93 insertions, 0 deletions
diff --git a/test/validate/formatter/AcceptRejectTest.js b/test/validate/formatter/AcceptRejectTest.js
new file mode 100644
index 0000000..3c9a6cc
--- /dev/null
+++ b/test/validate/formatter/AcceptRejectTest.js
@@ -0,0 +1,93 @@
+/**
+ * Accept/reject formatter test
+ *
+ * Copyright (C) 2016 LoVullo Associates, Inc.
+ *
+ * This file is part of liza.
+ *
+ * liza is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+var liza = require( '../../../' ),
+ Class = require( 'easejs' ).Class,
+ Sut = liza.validate.formatter.AcceptReject,
+ EchoFormatter = liza.validate.formatter.EchoFormatter,
+ ValidatorFormatter = liza.validate.ValidatorFormatter,
+ common = require( './common' ),
+ expect = require( 'chai' ).expect;
+
+var DummyFormatter = Class.implement( ValidatorFormatter )
+ .extend(
+{
+ 'virtual parse': function( data )
+ {
+ return '+' + data;
+ },
+
+ 'virtual retrieve': function( data )
+ {
+ return '-' + data;
+ },
+} );
+
+
+describe( 'validate.formatter.Number', function()
+{
+ common.testValidate( EchoFormatter.use( Sut )(), {
+ "": [ '' ],
+ "0": [ "0", "Rejected" ],
+ "1": [ "1", "Accepted" ],
+ "Rejected": [ "0", "Rejected" ],
+ "Accepted": [ "1", "Accepted" ],
+
+ // arbitrary text left alone
+ "foo": [ "foo" ],
+ } );
+
+
+ describe( '#parse', function()
+ {
+ it( 'considers accept/reject before supertype formatting', function()
+ {
+ // will equal +Accepted if supertype is called first
+ expect( DummyFormatter.use( Sut )().parse( 'Accepted' ) )
+ .to.equal( '1' );
+
+ // will equal +1 if supertype is called first
+ expect( DummyFormatter.use( Sut )().parse( '1' ) )
+ .to.equal( '1' );
+ } );
+ } );
+
+
+ describe( '#retrieve', function()
+ {
+ it( 'considers accept/reject before supertype formatting', function()
+ {
+ // will equal -1 if supertype is called first
+ expect( DummyFormatter.use( Sut )().retrieve( '1' ) )
+ .to.equal( 'Accepted' );
+ } );
+ } );
+
+
+ common.testMixin(
+ EchoFormatter,
+ Sut,
+ 'asdf',
+ 'given',
+ 'asdfgiven',
+ 'asdfgiven'
+ );
+} );