Add manual Components.Validator::validator method
Support manual validation where needed, add unit tests. This also slightly changes the behaviour of non-required field, since an empty non-required field should be valid.
This commit is contained in:
parent
c9fc877d12
commit
ca6cbecb83
4 changed files with 127 additions and 10 deletions
104
test/client/components/components-validator-test.vala
Normal file
104
test/client/components/components-validator-test.vala
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* Copyright 2019 Michael Gratton <mike@vee.net>
|
||||
*
|
||||
* This software is licensed under the GNU Lesser General Public License
|
||||
* (version 2.1 or later). See the COPYING file in this distribution.
|
||||
*/
|
||||
|
||||
|
||||
public class Components.ValidatorTest : TestCase {
|
||||
|
||||
|
||||
private Gtk.Entry? entry = null;
|
||||
|
||||
|
||||
public ValidatorTest() {
|
||||
base("Components.ValidatorTest");
|
||||
add_test("manual_empty", manual_empty);
|
||||
add_test("manual_valid", manual_valid);
|
||||
add_test("manual_not_required", manual_not_required);
|
||||
}
|
||||
|
||||
public override void set_up() {
|
||||
this.entry = new Gtk.Entry();
|
||||
}
|
||||
|
||||
public override void tear_down() {
|
||||
this.entry = null;
|
||||
}
|
||||
|
||||
public void manual_empty() throws GLib.Error {
|
||||
Validator test_article = new Validator(this.entry);
|
||||
|
||||
bool finished = false;
|
||||
Validator.Trigger? reason = null;
|
||||
Validator.Validity? prev_state = null;
|
||||
test_article.state_changed.connect((r, p) => {
|
||||
finished = true;
|
||||
reason = r;
|
||||
prev_state = p;
|
||||
});
|
||||
|
||||
test_article.validate();
|
||||
|
||||
while (!finished) {
|
||||
this.main_loop.iteration(true);
|
||||
}
|
||||
|
||||
assert_false(test_article.is_valid);
|
||||
assert_true(test_article.state == EMPTY);
|
||||
assert_true(reason == MANUAL);
|
||||
assert_true(prev_state == INDETERMINATE);
|
||||
}
|
||||
|
||||
public void manual_valid() throws GLib.Error {
|
||||
this.entry.text = "OHHAI";
|
||||
Validator test_article = new Validator(this.entry);
|
||||
|
||||
bool finished = false;
|
||||
Validator.Trigger? reason = null;
|
||||
Validator.Validity? prev_state = null;
|
||||
test_article.state_changed.connect((r, p) => {
|
||||
finished = true;
|
||||
reason = r;
|
||||
prev_state = p;
|
||||
});
|
||||
|
||||
test_article.validate();
|
||||
|
||||
while (!finished) {
|
||||
this.main_loop.iteration(true);
|
||||
}
|
||||
|
||||
assert_true(test_article.is_valid);
|
||||
assert_true(test_article.state == VALID);
|
||||
assert_true(reason == MANUAL);
|
||||
assert_true(prev_state == INDETERMINATE);
|
||||
}
|
||||
|
||||
public void manual_not_required() throws GLib.Error {
|
||||
Validator test_article = new Validator(this.entry);
|
||||
test_article.is_required = false;
|
||||
|
||||
bool finished = false;
|
||||
Validator.Trigger? reason = null;
|
||||
Validator.Validity? prev_state = null;
|
||||
test_article.state_changed.connect((r, p) => {
|
||||
finished = true;
|
||||
reason = r;
|
||||
prev_state = p;
|
||||
});
|
||||
|
||||
test_article.validate();
|
||||
|
||||
while (!finished) {
|
||||
this.main_loop.iteration(true);
|
||||
}
|
||||
|
||||
assert_true(test_article.is_valid);
|
||||
assert_true(test_article.state == VALID);
|
||||
assert_true(reason == MANUAL);
|
||||
assert_true(prev_state == INDETERMINATE);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -84,6 +84,7 @@ geary_test_client_sources = [
|
|||
'client/application/application-configuration-test.vala',
|
||||
'client/components/client-web-view-test.vala',
|
||||
'client/components/client-web-view-test-case.vala',
|
||||
'client/components/components-validator-test.vala',
|
||||
'client/composer/composer-web-view-test.vala',
|
||||
'client/util/util-avatar-test.vala',
|
||||
'client/util/util-cache-test.vala',
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ int main(string[] args) {
|
|||
client.add_suite(new Application.ConfigurationTest().get_suite());
|
||||
client.add_suite(new ClientWebViewTest().get_suite());
|
||||
client.add_suite(new Composer.WebViewTest().get_suite());
|
||||
client.add_suite(new Components.ValidatorTest().get_suite());
|
||||
client.add_suite(new Util.Avatar.Test().get_suite());
|
||||
client.add_suite(new Util.Cache.Test().get_suite());
|
||||
client.add_suite(new Util.Email.Test().get_suite());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue