-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Before moving on to CoverImage, finish writing tests for MoonPhase. Figured out how to do UI testing using Selenium 2.0 and Selenium::Remote::Driver. Just need to make that work with Test::Mojo; @kraih and @tempire hints about rolling a daemon on my own instead of using Test::Mojo->test_server and using Test::Fork to do blocking IO.
- Loading branch information
Showing
3 changed files
with
59 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env perl | ||
use Mojo::Base -strict; | ||
|
||
use Test::More tests => 22; | ||
use Test::Mojo; | ||
use Model::MoonPhase qw(illumination is_waxing); | ||
|
||
BEGIN { use_ok 'Mojoten' or BAIL_OUT "Mojoten is broken" } | ||
|
||
my $t = Test::Mojo->new('Mojoten'); | ||
$t->get_ok('/moonphase')->status_is(200)->content_like(qr/Moon Phase/i); | ||
|
||
my $time = "42 days ago at 7am"; | ||
|
||
# default output (HTML) | ||
$t->post_form_ok('/moonphase/check', {time => $time})->status_is(200) | ||
->content_type_like(qr#text/html#)->element_exists('div.success') | ||
->content_like(qr/.+full/); | ||
$t->post_form_ok('/moonphase/check', {time => 'fail'})->status_is(200) | ||
->content_type_like(qr#text/html#)->element_exists('div.error') | ||
->content_like(qr/no date or time I can recognize!/); | ||
|
||
# REST output (JSON) | ||
my $json = { | ||
time => $time, | ||
illuminated => sprintf("%.1f", illumination($time) * 100), | ||
phase => is_waxing($time) ? 'waxing' : 'waning' | ||
}; | ||
$t->post_form_ok('/moonphase/check', {time => $time, format => 'json'}) | ||
->status_is(200)->content_type_is('application/json') | ||
->json_content_is($json); | ||
$t->post_form_ok('/moonphase/check', {time => 'fail', format => 'json'}) | ||
->status_is(200)->content_type_is('application/json') | ||
->json_content_is( | ||
{error => "What, that's no date or time I can recognize!"}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env perl | ||
use Modern::Perl; | ||
use Astro::MoonPhase; | ||
use Time::ParseDate; | ||
use Test::More tests => 5; | ||
|
||
BEGIN { | ||
use_ok('Model::MoonPhase', qw(illumination is_waxing)) | ||
or BAIL_OUT "Can't see the moon in cloudy skies"; | ||
} | ||
|
||
my $time = "42 days ago at 5pm"; | ||
is_deeply( | ||
[Model::MoonPhase::moonphase($time)], | ||
[phase(parsedate($time))], | ||
"correct moon phase" | ||
); | ||
|
||
my @phase = Model::MoonPhase::moonphase($time); | ||
is(illumination($time), $phase[1], "correct moon illumination"); | ||
is(Model::MoonPhase::age($time), $phase[2], "correct moon age"); | ||
is(is_waxing($time), $phase[2] < (29.53 / 2), "moon is/is not waxing"); |