Friday, June 5, 2015

GWTBootstrap - custom email validation for TextBox

=== JAVA CODE ===

TextBox emailLookup = new TextBox();
emailLookup.addValidator(new Validator() {
            @Override
            public int getPriority() {
                return 0;
            }

            @Override
            public List<EditorError> validate(Editor editor, Object value) {
                List<EditorError> result = new ArrayList<EditorError>();
                String valueStr = value == null ? "" : value.toString();
                if (!valueStr.matches(EMAIL_REGEXP)) {
                    result.add(new BasicEditorError(emailLookup, value, "Not a valid email address"));
                } else if (isEmailReapeated(valueStr)) {
                    result.add(new BasicEditorError(emailLookup, value, "Email address is repeated"));
                }
                return result;
            }
        });

=== UI BINDER ===

<b:Row addStyleNames="{style.padding}">
    <b:Column size="XS_12">
        <b:Row>
            <b:Column size="XS_2">
                <b:FormGroup>
                    <b:TextBox ui:field="emailLookup" placeholder="Enter email" allowBlank="false"/>
                    <b:InlineHelpBlock iconType="EXCLAMATION"/>
                </b:FormGroup>
            </b:Column>

            <b:Column size="XS_1">
                <b:Button ui:field="addContact" text="Add"/>
            </b:Column>

        </b:Row>
    </b:Column>
</b:Row>

D3 Karma Jasmine testing

http://busypeoples.github.io/post/testing-d3-with-jasmine/

JavaScript Karma Jasmine - JSON parsing tests

http://stackoverflow.com/questions/20938320/loading-external-file-from-karma-jasmine-test
http://stackoverflow.com/questions/25035688/json-parse-fails-in-jasmine

ANGULAR + KARMA + JASMINE: test controller with $http, $scope

https://docs.angularjs.org/api/ngMock/service/$httpBackend