OSDN Git Service

97211641df455913b804578818b2e8800fe55a32
[newslash/newslash.git] / src / newslash_web / dom_t / domtest.t
1 # -*-Perl-*-
2 # DOM and runtime script test
3 use Mojo::Base -strict;
4 use Test::More;
5 use Test::Mojo;
6 use Newslash::Util::DOMTestRunner;
7 use FindBin;
8 use Data::Dumper;
9
10 my $t = Test::Mojo->new('Newslash::Web');
11 my $dom_test = Newslash::Util::DOMTestRunner->new('Newslash::Web',
12                                                   ignore_messages => ['adsbygoogle'],
13                                                   domtest_finish_timeout => 3000,
14                                                   domtest_script => "$FindBin::Bin/app.js",
15                                                   mode => $t->app->mode,
16                                                  );
17
18 sub test_path {
19     my ($path, $code) = @_;
20     $code ||= 200;
21     if (!$path) {
22         fail("invalid path: $path");
23         return;
24     }
25     $t->get_ok($path)->status_is($code, "GET $path return $code");
26   SKIP: {
27         skip "get NG for $path", 1 if !$t->success;
28         $dom_test->test($path);
29     }
30 }
31
32 #index page
33 test_path("/");
34
35 # top directory
36 for my $path (qw[recent popular journals submissions polls]) { #comments
37     test_path("/$path");
38 }
39
40 # story
41 my $items = $t->app->model('stories')->select(limit => 1);
42 ok($items->[0]->{sid}, "retrive valid sid");
43 my $path = "/story/$items->[0]->{sid}";
44 test_path($path);
45
46 # comment
47 $items = $t->app->model('comments')->select(limit => 1);
48 ok($items->[0]->{id}, "retrive valid cid");
49 $path = "/comment/$items->[0]->{id}";
50 test_path($path);
51
52 # journal
53 $items = $t->app->model('journals')->select(limit => 1);
54 ok($items->[0]->{id}, "retrive valid journal_id");
55 $path = "/journal/$items->[0]->{id}";
56 test_path($path, 301);
57
58 my $user = $t->app->users->get_user(uid => $items->[0]->{uid});
59 ok($user, "get valid user");
60 $path = "/~$user->{nickname}/journal/$items->[0]->{id}";
61 test_path($path, 200);
62
63 # submission
64 $items = $t->app->model('submissions')->select(limit => 1, order_by => { subid => 'DESC'});
65 #diag Dumper $items;
66 ok($items->[0]->{subid}, "retrive valid subid");
67 $path = "/submission/$items->[0]->{subid}";
68 test_path($path);
69
70 # polls
71 $items = $t->app->model('polls')->select(limit => 1);
72 ok($items->[0]->{qid}, "retrive valid polls qid");
73 $path = "/poll/$items->[0]->{qid}";
74 test_path($path);
75
76 # archive
77
78 # tag
79 SKIP: {
80     skip "mode is 'test'", 4 if ($t->app->mode eq 'test');
81     test_path("/tag/");
82     test_path("/tag/linux/");
83     test_path("/tag/linux/story/");
84     test_path("/tag/linux/story/?page=2");
85 }
86
87 # user
88
89
90 done_testing;
91