Simplify the tests

This commit is contained in:
swagg boi 2022-10-05 22:46:15 -04:00
parent 42a00c313c
commit 971b14aa8a
5 changed files with 87 additions and 91 deletions

View file

@ -35,7 +35,6 @@ Run the tests locally (against development environment):
1. Bump button/counter 1. Bump button/counter
1. Some sort of admin/moderator login and view 1. Some sort of admin/moderator login and view
1. CSS 1. CSS
1. Subtests for funsies
## Crazy future ideas ## Crazy future ideas

View file

@ -1,12 +0,0 @@
#!/usr/bin/env perl
use Mojo::Base -strict;
use Test::More;
use Test::Mojo;
my $t = Test::Mojo->new('PostText');
$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/);
done_testing();

View file

@ -1,75 +0,0 @@
#!/usr/bin/env perl
use Mojo::Base -strict;
use Test::More;
use Test::Mojo;
my $t = Test::Mojo->new('PostText');
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'
);
my %valid_remark = (
author => 'Anonymous',
body => 'hi'
);
my %invalid_remark = (
author => 'Anonymous',
body => 'a'
);
$t->ua->max_redirects(1);
# 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/);
$t->get_ok('/post/1')->status_is(200)
->element_exists('form input[name="author"]' )
->element_exists('form textarea[name="body"]')
->element_exists('form input[type="submit"]' )
->text_like(h2 => qr/New Remark/);
# 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]+/);
$t->post_ok('/post/1')->status_is(200)
->element_exists('form input[name="author"]' )
->element_exists('form textarea[name="body"]')
->element_exists('form input[type="submit"]' )
->text_like(h2 => qr/New Remark/);
$t->post_ok('/post/1', form => \%valid_remark)->status_is(200)
->text_like(h2 => qr/Thread #1/);
$t->post_ok('/post/1', form => \%invalid_remark)->status_is(400)
->text_like(p => qr/Invalid text/);
done_testing();

View file

@ -6,6 +6,40 @@ use Test::Mojo;
my $t = Test::Mojo->new('PostText'); my $t = Test::Mojo->new('PostText');
$t->get_ok('/remark/1')->status_is(200)->text_like(h2 => qr/Remark #1/); my %valid_remark = (
author => 'Anonymous',
body => 'hi'
);
my %invalid_remark = (
author => 'Anonymous',
body => 'a'
);
subtest 'View single remark', sub {
$t->get_ok('/remark/1')->status_is(200)->text_like(h2 => qr/Remark #1/);
};
$t->ua->max_redirects(1);
subtest 'Post new remark', sub {
# GET
$t->get_ok('/post/1')->status_is(200)
->element_exists('form input[name="author"]' )
->element_exists('form textarea[name="body"]')
->element_exists('form input[type="submit"]' )
->text_like(h2 => qr/New Remark/);
# POST
$t->post_ok('/post/1')->status_is(200)
->element_exists('form input[name="author"]' )
->element_exists('form textarea[name="body"]')
->element_exists('form input[type="submit"]' )
->text_like(h2 => qr/New Remark/);
$t->post_ok('/post/1', form => \%valid_remark)->status_is(200)
->text_like(h2 => qr/Thread #1/);
$t->post_ok('/post/1', form => \%invalid_remark)->status_is(400)
->text_like(p => qr/Invalid text/);
};
done_testing(); done_testing();

View file

@ -6,7 +6,57 @@ use Test::Mojo;
my $t = Test::Mojo->new('PostText'); my $t = Test::Mojo->new('PostText');
$t->get_ok('/thread/1' )->status_is(200)->text_like(h2 => qr/Thread #1/); my %valid_params = (
$t->get_ok('/thread/1/1')->status_is(200)->text_like(h2 => qr/Thread #1/); 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/);
};
$t->ua->max_redirects(1);
subtest 'Post new thread', sub {
# 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]+/);
};
done_testing(); done_testing();