PostText/t/post.t

78 lines
2.2 KiB
Perl
Raw Normal View History

#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Mojo::File qw{curfile};
use Test::Mojo;
2022-08-24 21:46:20 -04:00
my $script = curfile->dirname->sibling('PostText.pl');
my $t = Test::Mojo->new($script);
my %valid_params = (
2022-09-21 00:27:16 -04:00
author => 'Anonymous',
title => 'hi',
body => 'ayy... lmao'
2022-08-14 00:30:26 -04:00
);
2022-08-24 21:46:20 -04:00
my %invalid_title = (
2022-09-17 02:39:49 -04:00
author => 'Anonymous',
2022-09-21 00:27:16 -04:00
title => '',
body => 'ayy... lmao'
2022-08-15 17:48:58 -04:00
);
2022-08-24 21:46:20 -04:00
my %invalid_post = (
2022-09-17 02:39:49 -04:00
author => 'Anonymous',
2022-09-21 00:27:16 -04:00
title => 'hi',
body => 'a'
2022-08-15 17:11:14 -04:00
);
2022-08-24 21:46:20 -04:00
my %valid_remark = (
2022-09-17 02:39:49 -04:00
author => 'Anonymous',
2022-09-21 00:27:16 -04:00
body => 'hi'
2022-08-24 21:46:20 -04:00
);
my %invalid_remark = (
2022-09-17 02:39:49 -04:00
author => 'Anonymous',
2022-09-21 00:27:16 -04:00
body => 'a'
2022-08-24 21:46:20 -04:00
);
2022-08-15 17:48:58 -04:00
2022-08-14 00:30:26 -04:00
$t->ua->max_redirects(1);
2022-08-15 17:11:14 -04:00
# GET
$t->get_ok('/post')->status_is(200)
->element_exists('form input[name="author"]' )
->element_exists('form input[name="title"]' )
2022-09-21 00:12:16 -04:00
->element_exists('form textarea[name="body"]')
->element_exists('form input[type="submit"]' )
->text_like(h2 => qr/New Thread/);
$t->get_ok('/post/1')->status_is(200)
->element_exists('form input[name="author"]' )
2022-09-21 00:12:16 -04:00
->element_exists('form textarea[name="body"]')
->element_exists('form input[type="submit"]' )
->text_like(h2 => qr/New Remark/);
2022-08-15 17:11:14 -04:00
# POST
$t->post_ok('/post')->status_is(200)
->element_exists('form input[name="author"]' )
->element_exists('form input[name="title"]' )
2022-09-21 00:12:16 -04:00
->element_exists('form textarea[name="body"]')
->element_exists('form input[type="submit"]' )
->text_like(h2 => qr/New Thread/);
2022-08-14 00:30:26 -04:00
2022-08-15 17:48:58 -04:00
$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)
2022-09-21 00:12:16 -04:00
->text_like(p => qr/Invalid text/);
2022-08-14 00:30:26 -04:00
$t->post_ok('/post', form => \%valid_params)->status_is(200)
->text_like(h2 => qr/Thread #[0-9]+/);
2022-08-14 00:30:26 -04:00
$t->post_ok('/post/1')->status_is(200)
->element_exists('form input[name="author"]' )
2022-09-21 00:12:16 -04:00
->element_exists('form textarea[name="body"]')
->element_exists('form input[type="submit"]' )
->text_like(h2 => qr/New Remark/);
2022-08-24 21:46:20 -04:00
$t->post_ok('/post/1', form => \%valid_remark)->status_is(200)
2022-09-20 21:16:42 -04:00
->text_like(h2 => qr/Thread #1/);
2022-08-24 21:46:20 -04:00
$t->post_ok('/post/1', form => \%invalid_remark)->status_is(400)
2022-09-21 00:12:16 -04:00
->text_like(p => qr/Invalid text/);
2022-08-24 21:46:20 -04:00
done_testing();