Last active
March 22, 2016 17:23
-
-
Save preaction/a5d8227fd6d8de2f007c to your computer and use it in GitHub Desktop.
Testing HTML constructs with Test::Mojo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Test::Mojo::WithRoles 'HTML'; | |
$t->form_ok( 'main form' => { | |
username => 'ddupree', | |
name => 'Debbie Dupree', | |
email => '[email protected]', | |
password => '', | |
password_verify => '', | |
active => 1, | |
role => 'admin', | |
groups => [ 'Foo', 'Bar' ], | |
can_do_thing => 1, | |
can_do_other => 0, | |
} ); | |
# DL without ordering | |
$t->dl_ok( 'main dl' => { | |
foo => 'bar', | |
baz => 'biz', | |
fuzz => 'buzz', | |
} ); | |
# DL with ordering | |
$t->dl_ok( 'main dl' => [ | |
foo => 'bar', | |
baz => 'biz', | |
fuzz => 'buzz', | |
] ); | |
# Table without column ordering | |
$t->table_ok( 'main table' => [ | |
{ | |
foo => 'bar', | |
baz => 'biz', | |
fuzz => 'buzz', | |
}, | |
# ... | |
] ); | |
# Table with column ordering, without column titles | |
$t->table_ok( 'main table' => [ | |
[ 'bar', 'biz', 'buzz' ], | |
# ... | |
] ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
subtest 'test form' => sub { | |
my $form = $t->tx->res->dom->at( 'main form' ); | |
is $form->at( '[name=username]' )->attr( 'value' ), 'ddupree', 'username is set from param'; | |
is $form->at( '[name=name]' )->attr( 'value' ), 'Debbie Dupree', 'name is set from param'; | |
is $form->at( '[name=email]' )->attr( 'value' ), '[email protected]', 'email is set from param'; | |
is $form->at( '[name=password]' )->attr( 'type' ), 'password', 'password field exists'; | |
ok !$form->at( '[name=password]' )->attr( 'value' ), 'password is always empty'; | |
is $form->at( '[name=password_verify]' )->attr( 'type' ), 'password', 'password_verify field exists'; | |
ok !$form->at( '[name=password_verify]' )->attr( 'value' ), 'password_verify is always empty'; | |
ok $form->at( '[name=active][value=1]' )->attr( 'checked' ), 'active "yes" is checked from param'; | |
ok !$form->at( '[name=active][value=0]' )->attr( 'checked' ), 'active "no" is not checked from param'; | |
ok $form->at( '[name=role] [value=admin]' )->attr( 'selected' ), 'role "admin" is selected from param'; | |
ok !$form->at( '[name=role] [value=tech]' )->attr( 'selected' ), 'role "tech" is not selected from param'; | |
ok !$form->at( '[name=role] [value=other]' )->attr( 'selected' ), 'role "other" is not selected from param'; | |
ok $form->at( '[name=groups][value=Foo]' )->attr( 'checked' ), 'group "Foo" is checked'; | |
ok ! $form->at( '[name=groups][value=Bar]' )->attr( 'checked' ), 'group "Bar" is not checked'; | |
ok $form->at( '[name=can_do_thing]' )->attr( 'checked' ), 'can_do_thing is checked from param'; | |
ok !$form->at( '[name=can_do_other]' )->attr( 'checked' ), 'can_do_other is not checked from param'; | |
}; | |
subtest 'test dictionary list' => sub { | |
my %hash = ( | |
foo => 'bar', | |
baz => 'biz', | |
fuzz => 'buzz', | |
); | |
my $dl = $t->tx->res->dom->at( 'main dl' ); | |
my @dt = $dl->find( 'dt' ); | |
is scalar @dt, scalar keys %hash, 'correct number of definition terms found'; | |
for my $dt ( @dt ) { | |
is $dt->next_node->text, $hash{ $dt->text }, 'text for definition of ' . $dt->text . ' is correct'; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment