PostText/t/remark.t

57 lines
1.5 KiB
Perl
Raw Normal View History

2022-10-01 18:00:23 -04:00
use Mojo::Base -strict;
2022-09-03 13:08:03 -04:00
use Test::More;
use Test::Mojo;
2022-10-01 18:00:23 -04:00
my $t = Test::Mojo->new('PostText');
2022-09-03 13:08:03 -04:00
2022-10-12 23:58:46 -04:00
my %valid_remark = (
2022-10-05 22:46:15 -04:00
author => 'Anonymous',
body => 'hi'
);
2022-10-12 23:58:46 -04:00
2022-10-05 22:46:15 -04:00
my %invalid_remark = (
author => 'Anonymous',
body => 'a'
);
subtest 'View single remark', sub {
2022-10-12 23:58:46 -04:00
$t->get_ok('/remark/single/1')->status_is(200)
->text_like(h2 => qr/Remark #1/);
2022-10-05 22:46:15 -04:00
};
$t->ua->max_redirects(1);
subtest 'Post new remark', sub {
2022-10-05 22:46:15 -04:00
# GET
2022-10-12 23:58:46 -04:00
$t->get_ok('/remark/post/1')->status_is(200)
2022-10-05 22:46:15 -04:00
->element_exists('form input[name="author"]' )
->element_exists('form textarea[name="body"]')
2023-05-20 23:43:32 -04:00
->element_exists('form button[type="submit"]' )
2022-10-05 22:46:15 -04:00
->text_like(h2 => qr/New Remark/);
# POST
2022-10-12 23:58:46 -04:00
$t->post_ok('/remark/post/1')->status_is(200)
2022-10-05 22:46:15 -04:00
->element_exists('form input[name="author"]' )
->element_exists('form textarea[name="body"]')
2023-05-20 23:43:32 -04:00
->element_exists('form button[type="submit"]' )
2022-10-05 22:46:15 -04:00
->text_like(h2 => qr/New Remark/);
2022-10-12 23:58:46 -04:00
$t->post_ok('/remark/post/1', form => \%valid_remark)->status_is(200)
2022-10-05 22:46:15 -04:00
->text_like(h2 => qr/Thread #1/);
2022-10-12 23:58:46 -04:00
$t->post_ok('/remark/post/1', form => \%invalid_remark)->status_is(400)
2022-10-05 22:46:15 -04:00
->text_like(p => qr/Invalid text/);
};
2022-09-03 13:08:03 -04:00
2022-10-12 23:58:46 -04:00
subtest 'Flagging remark', sub {
$t->get_ok('/remark/single/1')->status_is(200)
->element_exists('a[href*="flag"]')
2022-10-13 23:57:58 -04:00
->text_like(h2 => qr/Remark #1/);
$t->get_ok('/remark/flag/1')->status_is(200)
->element_exists('p[class="field-with-info"]')
->text_like(p => qr/Remark #1 has been flagged/);
};
2022-10-12 23:58:46 -04:00
2023-04-25 22:28:11 -04:00
done_testing;