Implement tests for Bump feature; tweak some tests a bit; begin initial bump feature stuff

This commit is contained in:
swag 2022-10-06 22:46:38 -04:00
parent 7ac2688c32
commit c7e2445c37
7 changed files with 40 additions and 11 deletions

View File

@ -67,7 +67,8 @@ sub startup($self) {
->name('threads_list'); ->name('threads_list');
my $post_thread = $r->under; my $post_thread = $r->under;
$post_thread->any([qw{GET POST}], '/post')->to('thread#create') $post_thread->any([qw{GET POST}], '/post')
->to('thread#create')
->name('post_thread'); ->name('post_thread');
my $single_thread = my $single_thread =
@ -88,6 +89,12 @@ sub startup($self) {
$single_remark->get('/:remark_id', [remark_id => qr/[0-9]+/]) $single_remark->get('/:remark_id', [remark_id => qr/[0-9]+/])
->to('remark#by_id') ->to('remark#by_id')
->name('single_remark'); ->name('single_remark');
# Bump
my $bump_thread = $r->under('/bump');
$bump_thread->get('/:thread_id', [thread_id => qr/[0-9]+/])
->to('bump#create')
->name('bump_thread');
} }
1; 1;

View File

@ -0,0 +1,14 @@
package PostText::Controller::Bump;
use Mojo::Base 'Mojolicious::Controller', -signatures;
sub create($self) {
my $thread_id = $self->param('thread_id');
$self->thread->bump($thread_id);
$self->flash(info => "Thread #$thread_id has been bumped.🔝");
$self->redirect_to('threads_list');
}
1;

View File

14
t/bump.t Normal file
View File

@ -0,0 +1,14 @@
use Mojo::Base -strict;
use Test::More;
use Test::Mojo;
my $t = Test::Mojo->new('PostText');
subtest 'Bumping thread', sub {
$t->get_ok('/list')->status_is(200)
->element_exists('a[href~="bump"]')
->text_like(h2 => qr/Threads List/);
$t->get_ok('/bump/1')->status_is(302)
->header_like(Location => qr/list/);
};

View File

@ -1,5 +1,3 @@
#!/usr/bin/env perl
use Mojo::Base -strict; use Mojo::Base -strict;
use Test::More; use Test::More;
use Test::Mojo; use Test::Mojo;
@ -19,9 +17,9 @@ subtest 'View single remark', sub {
$t->get_ok('/remark/1')->status_is(200)->text_like(h2 => qr/Remark #1/); $t->get_ok('/remark/1')->status_is(200)->text_like(h2 => qr/Remark #1/);
}; };
$t->ua->max_redirects(1);
subtest 'Post new remark', sub { subtest 'Post new remark', sub {
$t->ua->max_redirects(1);
# GET # GET
$t->get_ok('/post/1')->status_is(200) $t->get_ok('/post/1')->status_is(200)
->element_exists('form input[name="author"]' ) ->element_exists('form input[name="author"]' )

View File

@ -1,5 +1,3 @@
#!/usr/bin/env perl
use Mojo::Base -strict; use Mojo::Base -strict;
use Test::More; use Test::More;
use Test::Mojo; use Test::Mojo;

View File

@ -1,5 +1,3 @@
#!/usr/bin/env perl
use Mojo::Base -strict; use Mojo::Base -strict;
use Test::More; use Test::More;
use Test::Mojo; use Test::Mojo;
@ -32,9 +30,9 @@ subtest 'View single thread', sub {
$t->get_ok('/thread/1/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 { subtest 'Post new thread', sub {
$t->ua->max_redirects(1);
# GET # GET
$t->get_ok('/post')->status_is(200) $t->get_ok('/post')->status_is(200)
->element_exists('form input[name="author"]' ) ->element_exists('form input[name="author"]' )