Test::Mojo::Role::Moai - Test::Mojo role to test UI components
version 0.008
my $t = Test::Mojo->with_roles( '+Moai' )->new; $t->get_ok( '/' ) ->table_is( '#mytable', [ [ '1BDI' => 'Turanga Leela' ], [ 'TJAM' => 'URL' ], ], 'NNY officers are listed', );
This module provides component tests for web pages: Instead of selecting individual elements and testing their parts, these methods test complete components in a way that allows for cosmetic, non-material changes to be made without editing the test.
These methods are designed for Mojolicious::Plugin::Moai components, but do not require Mojolicious::Plugin::Moai to function. Use them on any web site you want!
# <table> # <thead><tr><th>ID</th><th>Name</th></tr></thead> # <tbody><tr><td>1</td><td>Doug</td></tr></tbody> # </table> $t = $t->table_is( '#mytable', [ [ 1, 'Doug' ] ] ); $t = $t->table_is( '#mytable', [ [ 1, 'Doug' ] ], 'user table' ); $t = $t->table_is( '#mytable', [ { ID => 1, Name => 'Doug' } ] );
Check data in a table is complete and correct. Data can be tested as arrays (ordered) or hashes (unordered).
If a table contains a <tbody> element, this method will test the data inside. If not, it will test all rows in the table.
<tbody>
# <table><tr><td>1</td><td>Doug</td></tr></table> $t = $t->table_is( '#mytable', [ [ 1, 'Doug' ] ] );
To test attributes and elements inside the table cells, values can be hashrefs with a text attribute (for the cell text), an elem attribute to test descendant elements, and other keys for the cell's attributes.
text
elem
# <table><tr> # <td class="center">1</td> # <td><a href="/user/doug">Doug</a> <em>(admin)</em></td> # </tr></table> $t = $t->table_is( '#mytable', [ [ { text => 1, class => 'center' }, { elem => { 'a' => { text => 'Doug', href => '/user/doug', }, 'em' => '(admin)', } }, ], ] );
Test a table has the given data, ignoring extra data in the table that is not in the test.
Element text and attribute values should allow regex matching in addition to complete equality.
Test a list
Test a dictionary list
Test an individual element (using "at" in Mojo::DOM).
Test a collection of elements (using "find" in Mojo::DOM).
Elements should be able to test whether they are a link to a named route with certain stash values set. This allows for the route's URL to change without needing to change the test.
Any Moai components that have special effects or contain multiple testable elements should be given their own method, with _is and _has variants.
_is
_has
Mojolicious::Plugin::Moai, Mojolicious::Guides::Testing
Doug Bell <preaction@cpan.org>
This software is copyright (c) 2019 by Doug Bell.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Mojolicious::Plugin::Moai, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious::Plugin::Moai
CPAN shell
perl -MCPAN -e shell install Mojolicious::Plugin::Moai
For more information on module installation, please visit the detailed CPAN module installation guide.