1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
use strict;
use warnings;
use Test::More;
use FixMyStreet::TestMech;
use Web::Scraper;
my $mech = FixMyStreet::TestMech->new;
my $test_user = 'council_user@example.com';
my $test_pass = 'password';
my $test_council = 2651;
my $test_ward = 20723;
$mech->delete_user( $test_user );
my $user = FixMyStreet::App->model('DB::User')->create( {
email => $test_user,
password => $test_pass,
} );
my $p_user = FixMyStreet::App->model('DB::User')->find_or_create( {
email => 'p_user@example.com'
} );
$mech->not_logged_in_ok;
$mech->get_ok('/dashboard');
$mech->content_contains( 'sign in' );
$mech->submit_form(
with_fields => { email => $test_user, password_sign_in => $test_pass }
);
is $mech->status, '404', 'If not council user get 404';
$user->from_council( $test_council );
$user->update;
$mech->log_out_ok;
$mech->get_ok('/dashboard');
$mech->submit_form_ok( {
with_fields => { email => $test_user, password_sign_in => $test_pass }
} );
$mech->content_contains( 'Summary Statistics for City of Edinburgh' );
FixMyStreet::App->model('DB::Contact')->search( { area_id => $test_council } )
->delete;
FixMyStreet::App->model('DB::Problem')->search( { council => $test_council } )
->delete();
my @cats = qw( Grafitti Litter Potholes );
for my $contact ( @cats ) {
FixMyStreet::App->model('DB::Contact')->create(
{
area_id => $test_council,
category => $contact,
email => "$contact\@example.org",
confirmed => 1,
whenedited => DateTime->now,
deleted => 0,
editor => 'test',
note => 'test',
}
);
}
$mech->get_ok('/dashboard');
my $categories = scraper {
process "select[name=category] > option", 'cats[]' => 'TEXT',
process "select[name=ward] > option", 'wards[]' => 'TEXT',
process "table[id=overview] > tr", 'rows[]' => scraper {
process 'td', 'cols[]' => 'TEXT'
},
process "tr[id=total] > td", 'totals[]' => 'TEXT',
process "tr[id=fixed_council] > td", 'council[]' => 'TEXT',
process "tr[id=fixed_user] > td", 'user[]' => 'TEXT',
process "tr[id=total_fixed] > td", 'total_fixed[]' => 'TEXT',
process "tr[id=in_progress] > td", 'in_progress[]' => 'TEXT',
process "tr[id=planned] > td", 'planned[]' => 'TEXT',
process "tr[id=investigating] > td", 'investigating[]' => 'TEXT',
process "tr[id=marked] > td", 'marked[]' => 'TEXT',
process "tr[id=avg_marked] > td", 'avg_marked[]' => 'TEXT',
process "tr[id=avg_fixed] > td", 'avg_fixed[]' => 'TEXT',
process "tr[id=not_marked] > td", 'not_marked[]' => 'TEXT',
};
my $expected_cats = [ 'All', '-- Pick a category --', @cats, 'Other' ];
my $res = $categories->scrape( $mech->content );
is_deeply( $res->{cats}, $expected_cats, 'correct list of categories' );
foreach my $row ( @{ $res->{rows} }[1 .. 11] ) {
foreach my $col ( @{ $row->{cols} } ) {
is $col, 0;
}
}
make_problem( { state => 'confirmed', conf_dt => DateTime->now } );
$mech->get_ok('/dashboard');
$res = $categories->scrape( $mech->content );
is $res->{ totals }->[1], 1, 'Report in total';
is $res->{ not_marked }->[1], 1, 'Report in not marked';
sub make_problem {
my $args = shift;
my $p = FixMyStreet::App->model('DB::Problem')->create( {
title => 'a problem',
name => 'a user',
anonymous => 1,
detail => 'some detail',
state => $args->{state},
confirmed => $args->{conf_dt},
whensent => $args->{conf_dt},
council => $test_council,
postcode => 'EH99 1SP',
latitude => '51',
longitude => '1',
areas => $test_ward,
used_map => 0,
user_id => $p_user->id,
} );
}
done_testing;
|