PostText/t/thread.t

99 lines
2.8 KiB
Perl
Raw Normal View History

2022-10-01 18:00:23 -04:00
use Mojo::Base -strict;
use Test::More;
use Test::Mojo;
2022-10-01 18:00:23 -04:00
my $t = Test::Mojo->new('PostText');
2022-10-12 23:58:46 -04:00
my %valid_params = (
2022-10-05 22:46:15 -04:00
author => 'Anonymous',
title => 'hi',
body => 'ayy... lmao'
);
2022-10-12 23:58:46 -04:00
2022-10-05 22:46:15 -04:00
my %invalid_title = (
author => 'Anonymous',
title => '',
body => 'ayy... lmao'
);
2022-10-12 23:58:46 -04:00
my %invalid_post = (
2022-10-05 22:46:15 -04:00
author => 'Anonymous',
title => 'hi',
body => 'a'
);
subtest 'List threads by page', sub {
2022-10-12 23:58:46 -04:00
$t->get_ok('/thread/list')->status_is(200)
->text_like(h2 => qr/Threads List/);
$t->get_ok('/thread/list/1')->status_is(200)
->text_like(h2 => qr/Threads List/);
2022-10-05 22:46:15 -04:00
};
subtest 'View single thread', sub {
2022-10-12 23:58:46 -04:00
$t->get_ok('/thread/single/1')->status_is(200)
->text_like(h2 => qr/Thread #1/);
$t->get_ok('/thread/single/1/1')->status_is(200)
->text_like(h2 => qr/Thread #1/);
2022-10-05 22:46:15 -04:00
};
$t->ua->max_redirects(1);
2022-10-08 00:42:31 -04:00
2022-10-05 22:46:15 -04:00
subtest 'Post new thread', sub {
# GET
2022-10-12 23:58:46 -04:00
$t->get_ok('/thread/post')->status_is(200)
2022-10-05 22:46:15 -04:00
->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
2022-10-12 23:58:46 -04:00
$t->post_ok('/thread/post')->status_is(200)
2022-10-05 22:46:15 -04:00
->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/);
2022-10-12 23:58:46 -04:00
$t->post_ok('/thread/post', form => \%invalid_title)->status_is(400)
2022-10-05 22:46:15 -04:00
->text_like(p => qr/Invalid title/);
2022-10-12 23:58:46 -04:00
$t->post_ok('/thread/post', form => \%invalid_post)->status_is(400)
2022-10-05 22:46:15 -04:00
->text_like(p => qr/Invalid text/);
2022-10-12 23:58:46 -04:00
$t->post_ok('/thread/post', form => \%valid_params)->status_is(200)
2022-10-05 22:46:15 -04:00
->text_like(h2 => qr/Thread #[0-9]+/);
};
subtest 'Bumping thread', sub {
2022-10-12 23:58:46 -04:00
$t->get_ok('/thread/list')->status_is(200)
->element_exists('a[href*="bump"]')
->text_like(h2 => qr/Threads List/);
2022-10-13 23:57:58 -04:00
$t->get_ok('/thread/single/1')->status_is(200)
->element_exists('a[href*="bump"]')
->text_like(h2 => qr/Thread #1/);
2022-10-12 23:58:46 -04:00
$t->get_ok('/thread/bump/1')->status_is(200)
->element_exists('p[class="field-with-info"]')
2022-10-13 23:57:58 -04:00
->text_like(p => qr/Thread #1 has been bumped/);
};
2022-10-12 22:14:28 -04:00
subtest 'Flagging thread', sub {
2022-10-12 23:58:46 -04:00
$t->get_ok('/thread/list')->status_is(200)
2022-10-12 22:14:28 -04:00
->element_exists('a[href*="flag"]')
->text_like(h2 => qr/Threads List/);
2022-10-12 23:58:46 -04:00
$t->get_ok('/thread/single/1')->status_is(200)
2022-10-12 22:14:28 -04:00
->element_exists('a[href*="flag"]')
->text_like(h2 => qr/Thread #1/);
2022-10-13 23:57:58 -04:00
$t->get_ok('/thread/flag/1')->status_is(200)
->element_exists('p[class="field-with-info"]')
->text_like(p => qr/Thread #1 has been flagged/);
};
2022-10-12 22:14:28 -04:00
done_testing();