From ff2c3a8053ead0b6681755feb902923ec948667b Mon Sep 17 00:00:00 2001 From: Manager Bot Date: Mon, 28 Nov 2022 21:53:51 +0000 Subject: [PATCH] More tests, more fixes. --- Web/lib/MJB/Web/Controller/Dashboard.pm | 4 +- .../04_dashboard/13_blog_config.t | 43 +++++++++++++ .../04_dashboard/14_do_blog_config.t | 60 +++++++++++++++++++ Web/templates/dashboard/blog_config.html.ep | 2 +- 4 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 Web/t/01_endpoints/04_dashboard/13_blog_config.t create mode 100644 Web/t/01_endpoints/04_dashboard/14_do_blog_config.t diff --git a/Web/lib/MJB/Web/Controller/Dashboard.pm b/Web/lib/MJB/Web/Controller/Dashboard.pm index 102725a..53bb308 100644 --- a/Web/lib/MJB/Web/Controller/Dashboard.pm +++ b/Web/lib/MJB/Web/Controller/Dashboard.pm @@ -246,7 +246,7 @@ sub blog_config ( $c ) { my $jekyll = $c->jekyll($blog->domain->name); my $config = $jekyll->config; - my $config_text = $c->stash->{form_config} = $config->as_text; + my $config_text = $c->stash->{form}->{config} = $config->as_text; } #== @@ -261,7 +261,7 @@ sub do_blog_config ( $c ) { my $jekyll = $c->jekyll($blog->domain->name); my $config = $jekyll->config; - my $config_text = $c->stash->{form_config} = $c->param( 'blogConfig' ); + my $config_text = $c->stash->{form}->{config} = $c->param( 'blogConfig' ); $config->set_from_text( $config_text ); diff --git a/Web/t/01_endpoints/04_dashboard/13_blog_config.t b/Web/t/01_endpoints/04_dashboard/13_blog_config.t new file mode 100644 index 0000000..2337b24 --- /dev/null +++ b/Web/t/01_endpoints/04_dashboard/13_blog_config.t @@ -0,0 +1,43 @@ +#!/usr/bin/env perl +use MJB::Web::Test; + +#== +# This test ensures that the config panel for the blog can be viewed. +# +# 1. Create user and login. +# 2. Make a new blog. +# 3. Go to the settings -> advanced config panel +# 4. Confirm the stash values. +#== + +my $t = Test::Mojo::MJB->new('MJB::Web'); + +my $blog_id = $t->create_user + ->post_ok( '/blog/domain', form => { + domain => 'blog.example.com', + calling_route => 'show_blog_domain_owned', + }) + ->get_ok( '/dashboard' ) + ->stash->{blogs}->[0]->id; + +$t->get_ok( "/dashboard/blog/$blog_id" ) + ->status_is( 200 ) + ->code_block( sub { + my $self = shift; + ok exists $self->stash->{blog}, "The blog loads!"; + is $self->stash->{blog}->domain->name, 'blog.example.com', "Correct domain name for id."; + }); + +$t->get_ok( "/dashboard/blog/$blog_id/settings" ) + ->code_block(sub { + my $self = shift; + ok exists $self->stash->{form}->{config}, 'There is a config'; + }) + ->status_is( 200 ); + +#== +# Remove Jekyll blog repos that were created as a part of this test. +#== +$t->clear_tempdir; + +done_testing; diff --git a/Web/t/01_endpoints/04_dashboard/14_do_blog_config.t b/Web/t/01_endpoints/04_dashboard/14_do_blog_config.t new file mode 100644 index 0000000..e50b1af --- /dev/null +++ b/Web/t/01_endpoints/04_dashboard/14_do_blog_config.t @@ -0,0 +1,60 @@ +#!/usr/bin/env perl +use MJB::Web::Test; + +#== +# This test ensures that the config panel for the blog can be used to +# change the config/settings. +# +# 1. Create user and login. +# 2. Make a new blog. +# 3. Go to the config panel +# 4. Confirm the stash values. +# 5. Change all of the values with the config update +# 6. Confirm the changes took effect. +#== + +my $t = Test::Mojo::MJB->new('MJB::Web'); + +my $blog_id = $t->create_user + ->post_ok( '/blog/domain', form => { + domain => 'blog.example.com', + calling_route => 'show_blog_domain_owned', + }) + ->get_ok( '/dashboard' ) + ->stash->{blogs}->[0]->id; + +$t->get_ok( "/dashboard/blog/$blog_id" ) + ->status_is( 200 ) + ->code_block( sub { + my $self = shift; + ok exists $self->stash->{blog}, "The blog loads!"; + is $self->stash->{blog}->domain->name, 'blog.example.com', "Correct domain name for id."; + }); + +# Check the settings page and confirm the settings values exist. +$t->get_ok( "/dashboard/blog/$blog_id/config" ) + ->code_block(sub { + my $self = shift; + ok exists $self->stash->{form}->{config}, 'There is a config'; + }) + ->status_is( 200 ); + +# Make the update and then confirm the changes. +$t->post_ok( "/dashboard/blog/$blog_id/config", form => { + blogConfig => "title: Test title", + }) + ->status_is( 302 ) + ->header_is( location => "/dashboard/blog/$blog_id/config" ) + ->get_ok( "/dashboard/blog/$blog_id/config" ) + ->status_is( 200 ) + ->code_block(sub { + my $self = shift; + is $self->stash->{form}->{config}, "---\ntitle: Test title\n", 'The correct config is set'; + }); + +#== +# Remove Jekyll blog repos that were created as a part of this test. +#== +$t->clear_tempdir; + +done_testing; diff --git a/Web/templates/dashboard/blog_config.html.ep b/Web/templates/dashboard/blog_config.html.ep index a817e05..62d516d 100644 --- a/Web/templates/dashboard/blog_config.html.ep +++ b/Web/templates/dashboard/blog_config.html.ep @@ -7,7 +7,7 @@
- +