rt 4.2.14 (#13852)
[freeside.git] / rt / t / web / dashboards-in-menu.t
1 use strict;
2 use warnings;
3
4 use RT::Test tests => undef;
5 my ($baseurl, $m) = RT::Test->started_ok;
6
7 my $system_foo = RT::Dashboard->new($RT::SystemUser);
8 $system_foo->Save(
9     Name    => 'system foo',
10     Privacy => 'RT::System-' . $RT::System->id,
11 );
12
13 my $system_bar = RT::Dashboard->new($RT::SystemUser);
14 $system_bar->Save(
15     Name    => 'system bar',
16     Privacy => 'RT::System-' . $RT::System->id,
17 );
18
19 ok( $m->login(), "logged in" );
20
21 diag "global setting";
22 # in case "RT at a glance" contains dashboards stuff.
23 $m->get_ok( $baseurl . "/Search/Simple.html" );
24 ok( !$m->find_link( text => 'system foo' ), 'no system foo link' );
25 $m->get_ok( $baseurl."/Admin/Global/DashboardsInMenu.html");
26
27 my $form_name = 'SelectionBox-dashboards_in_menu';
28 $m->form_name($form_name);
29
30 $m->field('dashboards_in_menu-Available' => [$system_foo->id],);
31 $m->click_button(name => 'add');
32 $m->content_contains('Global dashboards in menu saved.', 'saved');
33
34 $m->logout;
35 ok( $m->login(), "relogged in" );
36
37 $m->get_ok( $baseurl . "/Search/Simple.html" );
38 $m->follow_link_ok( { text => 'system foo' }, 'follow system foo link' );
39 $m->title_is( 'system foo Dashboard', 'got system foo dashboard page' );
40
41 diag "setting in admin users";
42 my $root = RT::CurrentUser->new( $RT::SystemUser );
43 ok( $root->Load('root') );
44 my $self_foo = RT::Dashboard->new($root);
45 $self_foo->Save( Name => 'self foo', Privacy => 'RT::User-' . $root->id );
46 my $self_bar = RT::Dashboard->new($root);
47 $self_bar->Save( Name => 'self bar', Privacy => 'RT::User-' . $root->id );
48
49 ok( !$m->find_link( text => 'self foo' ), 'no self foo link' );
50 $m->get_ok( $baseurl."/Admin/Users/DashboardsInMenu.html?id=" . $root->id);
51 $m->form_name($form_name);
52 $m->field('dashboards_in_menu-Available' => [$self_foo->id]);
53 $m->click_button(name => 'add');
54 $m->content_contains( 'Preferences saved for dashboards in menu.',
55     'prefs saved' );
56 $m->form_name($form_name);
57 $m->field('dashboards_in_menu-Selected' => [$system_foo->id]);
58 $m->content_contains( 'Preferences saved for dashboards in menu.',
59     'prefs saved' );
60 $m->click_button(name => 'remove');
61
62 $m->logout;
63 ok( $m->login(), "relogged in" );
64 $m->get_ok( $baseurl . "/Search/Simple.html" );
65 ok( !$m->find_link( text => 'system foo' ), 'no system foo link' );
66 $m->follow_link_ok( { text => 'self foo' }, 'follow self foo link' );
67 $m->title_is( 'self foo Dashboard', 'got self foo dashboard page' );
68
69 diag "setting in prefs";
70 $m->get_ok( $baseurl."/Prefs/DashboardsInMenu.html");
71 $m->form_name($form_name);
72 $m->field('dashboards_in_menu-Available' => [$self_bar->id]);
73 $m->click_button(name => 'add');
74 $m->content_contains( 'Preferences saved for dashboards in menu.',
75     'prefs saved' );
76 $m->follow_link_ok( { text => 'self bar' }, 'follow self bar link' );
77 $m->title_is( 'self bar Dashboard', 'got self bar dashboard page' );
78
79 diag "Test deleting dashboard";
80 $m->follow_link_ok( { text => 'self foo' }, 'follow self foo link' );
81 $m->follow_link_ok( { text => 'Basics' }, 'Click dashboard Basics' );
82 $m->form_name('ModifyDashboard');
83 $m->click_button(name => 'Delete');
84
85 diag "Reset dashboard menu";
86 $m->get_ok( $baseurl."/Prefs/DashboardsInMenu.html");
87 $m->form_with_fields('Reset');
88 $m->click;
89 $m->content_contains( 'Preferences saved', 'prefs saved' );
90 ok( $m->find_link( text => 'system foo' ), 'got system foo link' );
91 ok( !$m->find_link( text => 'self bar' ), 'no self bar link' );
92
93 diag "Delete system dashboard";
94 $m->get_ok( $baseurl . "/Dashboards/index.html" );
95 $m->follow_link_ok( { text => 'system foo' }, 'follow self foo link' );
96 $m->follow_link_ok( { text => 'Basics' }, 'Click dashboard Basics' );
97 $m->form_name('ModifyDashboard');
98 $m->click_button(name => 'Delete');
99 $m->get_ok( $baseurl . "/Dashboards/index.html" );
100 $m->content_lacks('system foo', 'Dashboard is deleted');
101
102 undef $m;
103 done_testing;