2022-10-01 22:00:23 +00:00
|
|
|
use Mojo::Base -strict;
|
2022-09-03 17:08:03 +00:00
|
|
|
use Test::More;
|
|
|
|
use Test::Mojo;
|
|
|
|
|
2022-10-01 22:00:23 +00:00
|
|
|
my $t = Test::Mojo->new('PostText');
|
2022-09-03 17:08:03 +00:00
|
|
|
|
2022-10-13 03:58:46 +00:00
|
|
|
my %valid_remark = (
|
2022-10-06 02:46:15 +00:00
|
|
|
author => 'Anonymous',
|
|
|
|
body => 'hi'
|
|
|
|
);
|
2022-10-13 03:58:46 +00:00
|
|
|
|
2022-10-06 02:46:15 +00:00
|
|
|
my %invalid_remark = (
|
|
|
|
author => 'Anonymous',
|
|
|
|
body => 'a'
|
|
|
|
);
|
|
|
|
|
|
|
|
subtest 'View single remark', sub {
|
2022-10-13 03:58:46 +00:00
|
|
|
$t->get_ok('/remark/single/1')->status_is(200)
|
2023-06-25 04:01:13 +00:00
|
|
|
->text_like(h2 => qr/Remark #1/)
|
2023-06-28 00:55:41 +00:00
|
|
|
->element_exists('a[href$="/remark/post/1/1"]')
|
|
|
|
->element_exists('h2 sup a[href$=".txt"]');
|
2023-06-27 05:30:32 +00:00
|
|
|
$t->get_ok('/remark/single/65536')->status_is(404)
|
|
|
|
->text_like(p => qr/Remark not found/);
|
|
|
|
|
|
|
|
$t->get_ok('/remark/single/1.txt')->status_is(200)
|
|
|
|
->content_type_like(qr{text/plain});
|
|
|
|
$t->get_ok('/remark/single/65536.txt')->status_is(404)
|
|
|
|
->content_type_like(qr{text/plain});
|
2022-10-06 02:46:15 +00:00
|
|
|
};
|
|
|
|
|
2022-10-08 05:58:18 +00:00
|
|
|
$t->ua->max_redirects(1);
|
2022-10-07 02:46:38 +00:00
|
|
|
|
2022-10-08 05:58:18 +00:00
|
|
|
subtest 'Post new remark', sub {
|
2022-10-06 02:46:15 +00:00
|
|
|
# GET
|
2022-10-13 03:58:46 +00:00
|
|
|
$t->get_ok('/remark/post/1')->status_is(200)
|
2022-10-06 02:46:15 +00:00
|
|
|
->element_exists('form input[name="author"]' )
|
|
|
|
->element_exists('form textarea[name="body"]')
|
2023-05-21 03:43:32 +00:00
|
|
|
->element_exists('form button[type="submit"]' )
|
2023-06-04 22:10:08 +00:00
|
|
|
->text_like(h2 => qr/Remark on Thread #/);
|
2023-06-27 05:30:32 +00:00
|
|
|
$t->get_ok('/remark/post/65536')->status_is(404)
|
|
|
|
->text_like(p => qr/Thread not found/);
|
2023-06-25 04:01:13 +00:00
|
|
|
# Test the remark-to-remark thing
|
|
|
|
$t->get_ok('/remark/post/1/1')->status_is(200)
|
|
|
|
->element_exists('form input[name="author"]' )
|
|
|
|
->element_exists('form textarea[name="body"]')
|
|
|
|
->element_exists('form button[type="submit"]' )
|
|
|
|
->element_exists('a[href$="/remark/single/1"]')
|
|
|
|
->text_like(h3 => qr/Last Remark/);
|
2022-10-06 02:46:15 +00:00
|
|
|
|
|
|
|
# POST
|
2022-10-13 03:58:46 +00:00
|
|
|
$t->post_ok('/remark/post/1')->status_is(200)
|
2022-10-06 02:46:15 +00:00
|
|
|
->element_exists('form input[name="author"]' )
|
|
|
|
->element_exists('form textarea[name="body"]')
|
2023-05-21 03:43:32 +00:00
|
|
|
->element_exists('form button[type="submit"]' )
|
2023-06-04 22:10:08 +00:00
|
|
|
->text_like(h2 => qr/Remark on Thread #/);
|
2022-10-06 02:46:15 +00:00
|
|
|
|
2022-10-13 03:58:46 +00:00
|
|
|
$t->post_ok('/remark/post/1', form => \%valid_remark)->status_is(200)
|
2022-10-06 02:46:15 +00:00
|
|
|
->text_like(h2 => qr/Thread #1/);
|
2022-10-13 03:58:46 +00:00
|
|
|
|
|
|
|
$t->post_ok('/remark/post/1', form => \%invalid_remark)->status_is(400)
|
2023-05-28 04:42:07 +00:00
|
|
|
->text_like(p => qr/Must be between/);
|
2022-10-06 02:46:15 +00:00
|
|
|
};
|
2022-09-03 17:08:03 +00:00
|
|
|
|
2023-04-26 02:28:11 +00:00
|
|
|
done_testing;
|