2022-10-01 18:00:23 -04:00
|
|
|
use Mojo::Base -strict;
|
2022-08-19 23:28:16 -04:00
|
|
|
use Test::More;
|
|
|
|
use Test::Mojo;
|
|
|
|
|
2022-10-01 18:00:23 -04:00
|
|
|
my $t = Test::Mojo->new('PostText');
|
2022-08-19 23:28:16 -04:00
|
|
|
|
2022-10-05 22:46:15 -04:00
|
|
|
my %valid_params = (
|
|
|
|
author => 'Anonymous',
|
|
|
|
title => 'hi',
|
|
|
|
body => 'ayy... lmao'
|
|
|
|
);
|
|
|
|
my %invalid_title = (
|
|
|
|
author => 'Anonymous',
|
|
|
|
title => '',
|
|
|
|
body => 'ayy... lmao'
|
|
|
|
);
|
|
|
|
my %invalid_post = (
|
|
|
|
author => 'Anonymous',
|
|
|
|
title => 'hi',
|
|
|
|
body => 'a'
|
|
|
|
);
|
|
|
|
|
|
|
|
subtest 'List threads by page', sub {
|
|
|
|
$t->get_ok('/list' )->status_is(200)->text_like(h2 => qr/Threads List/);
|
|
|
|
$t->get_ok('/list/1')->status_is(200)->text_like(h2 => qr/Threads List/);
|
|
|
|
};
|
|
|
|
|
|
|
|
subtest 'View single thread', sub {
|
|
|
|
$t->get_ok('/thread/1' )->status_is(200)->text_like(h2 => qr/Thread #1/);
|
|
|
|
$t->get_ok('/thread/1/1')->status_is(200)->text_like(h2 => qr/Thread #1/);
|
|
|
|
};
|
|
|
|
|
|
|
|
subtest 'Post new thread', sub {
|
2022-10-06 22:46:38 -04:00
|
|
|
$t->ua->max_redirects(1);
|
|
|
|
|
2022-10-05 22:46:15 -04:00
|
|
|
# GET
|
|
|
|
$t->get_ok('/post')->status_is(200)
|
|
|
|
->element_exists('form input[name="author"]' )
|
|
|
|
->element_exists('form input[name="title"]' )
|
|
|
|
->element_exists('form textarea[name="body"]')
|
|
|
|
->element_exists('form input[type="submit"]' )
|
|
|
|
->text_like(h2 => qr/New Thread/);
|
|
|
|
|
|
|
|
# POST
|
|
|
|
$t->post_ok('/post')->status_is(200)
|
|
|
|
->element_exists('form input[name="author"]' )
|
|
|
|
->element_exists('form input[name="title"]' )
|
|
|
|
->element_exists('form textarea[name="body"]')
|
|
|
|
->element_exists('form input[type="submit"]' )
|
|
|
|
->text_like(h2 => qr/New Thread/);
|
|
|
|
|
|
|
|
$t->post_ok('/post', form => \%invalid_title)->status_is(400)
|
|
|
|
->text_like(p => qr/Invalid title/);
|
|
|
|
$t->post_ok('/post', form => \%invalid_post)->status_is(400)
|
|
|
|
->text_like(p => qr/Invalid text/);
|
|
|
|
$t->post_ok('/post', form => \%valid_params)->status_is(200)
|
|
|
|
->text_like(h2 => qr/Thread #[0-9]+/);
|
|
|
|
};
|
2022-08-19 23:28:16 -04:00
|
|
|
|
|
|
|
done_testing();
|