Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reshuffle the admin tables to allow short values under long texts #222

Merged
merged 1 commit into from
Mar 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions lib/OpenQA/Controller/Admin/Table.pm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ sub admintable {
select => [ 'key', { count => 'key' } ],
as => [qw/ key var_count /],
group_by => [qw/ key /],
order_by => { -desc => \'count(key)' }
order_by => { -desc => 'count(key)' }
}
);
my @variables = map { $_->key } $rc->all();
Expand All @@ -35,19 +35,27 @@ sub admintable {
my $shortest;
my @col_variables;
for my $v (@variables) {
my $line = $self->db->resultset($resultset)->search( { key => $v }, { select => { 'max' => { 'length' => 'value' } }, as => 'max' });
my $line = $self->db->resultset($resultset)->search(
{ key => $v },
{
select => { 'max' =>{ 'length' => 'value' } },
as => 'max'
}
);
my $max = $line->first->get_column('max');
if ($max > 3) {
# this are purely magic numbers
if ($max > length($v) * 1.2) {
# ignore it on first run
$shortest = undef if ($shortest && $shortest->{len} > $max);
next if $shortest;
$shortest = { len => $max, var => $v };
next;
}
last if @col_variables == 7;
last if length(join(' ', @col_variables)) > 30;
push(@col_variables, $v);
}
if ($shortest && length(join(' ', @col_variables)) < 20) { # if we have space left, we can readd the shortest
# if we have space left, we can readd the shortest
if ($shortest && length(join(' ', @col_variables)) + length($shortest->{var}) < 30) {
push(@col_variables, $shortest->{var});
}

Expand Down
31 changes: 16 additions & 15 deletions t/ui/13-admin.t
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use t::ui::PhantomTest;

my $driver = t::ui::PhantomTest::call_phantom();
if ($driver) {
plan tests => 78;
plan tests => 80;
}
else {
plan skip_all => 'Install phantomjs to run these tests';
Expand Down Expand Up @@ -76,8 +76,8 @@ sub add_machine() {
# the headers are specific to our fixtures - if they change, we have to adapt
is((shift @headers)->get_text(), "name", "1st column");
is((shift @headers)->get_text(), "backend", "2nd column");
is((shift @headers)->get_text(), "LAPTOP", "3rd column");
is((shift @headers)->get_text(), "QEMUCPU", "4th column");
is((shift @headers)->get_text(), "QEMUCPU", "3rd column");
is((shift @headers)->get_text(), "LAPTOP", "4th column");
is((shift @headers)->get_text(), "other variables", "5th column");
is((shift @headers)->get_text(), "action", "6th column");

Expand All @@ -88,8 +88,8 @@ sub add_machine() {
# the headers are specific to our fixtures - if they change, we have to adapt
is((shift @headers)->get_text(), "Laptop_64", "name");
is((shift @headers)->get_text(), "qemu", "backend");
is((shift @headers)->get_text(), "1", "LAPTOP");
is((shift @headers)->get_text(), "qemu64", "cpu");
is((shift @headers)->get_text(), "qemu64", "cpu");
is((shift @headers)->get_text(), "1", "LAPTOP");

is(@{$driver->find_elements('//button[@title="Edit"]')}, 3, "3 edit buttons before");

Expand Down Expand Up @@ -124,14 +124,15 @@ sub add_test_suite() {

my $elem = $driver->find_element('.admintable thead tr', 'css');
my @headers = $driver->find_child_elements($elem, 'th');
is(6, @headers, "6 columns");
is(7, @headers, "7 columns");

# the headers are specific to our fixtures - if they change, we have to adapt
is((shift @headers)->get_text(), "name", "1st column");
is((shift @headers)->get_text(), "prio", "2nd column");
is((shift @headers)->get_text(), "INSTALLONLY", "3rd column");
is((shift @headers)->get_text(), "RAIDLEVEL", "4th column");
is((shift @headers)->get_text(), "other variables", "5th column");
is((shift @headers)->get_text(), "DESKTOP", "3rd column");
is((shift @headers)->get_text(), "PARALLEL_WITH", "4th column");
is((shift @headers)->get_text(), "INSTALLONLY", "5th column");
is((shift @headers)->get_text(), "other variables", "6th column");

# now check one row by example
$elem = $driver->find_element('.admintable tbody tr:nth-child(3)', 'css');
Expand All @@ -140,8 +141,9 @@ sub add_test_suite() {
# the headers are specific to our fixtures - if they change, we have to adapt
is((shift @headers)->get_text(), "RAID0", "name");
is((shift @headers)->get_text(), "50", "prio");
is((shift @headers)->get_text(), "kde", "DESKTOP");
is((shift @headers)->get_text(), "", "PARALLEL_WITH");
is((shift @headers)->get_text(), "1", "INSTALLONLY");
is((shift @headers)->get_text(), "0", "RAIDLEVEL");

is(@{$driver->find_elements('//button[@title="Edit"]')}, 7, "7 edit buttons before");

Expand All @@ -150,13 +152,12 @@ sub add_test_suite() {
$elem = $driver->find_element('.admintable tbody tr:last-child', 'css');
is($elem->get_text(), '=', "new row empty");
my @fields = $driver->find_child_elements($elem, '//input[@type="text"]');
is(6, @fields, "6 fields"); # one column has 2 fields
is(7, @fields, "7 fields"); # one column has 2 fields
(shift @fields)->send_keys('xfce'); # name
(shift @fields)->send_keys('50'); # backend
(shift @fields)->send_keys('50'); # prio
(shift @fields)->send_keys('xfce'); # desktop
(shift @fields)->send_keys(''); # parallelwith
(shift @fields)->send_keys(''); # installonly
(shift @fields)->send_keys(''); # raid
(shift @fields)->send_keys('DESKTOP'); # var
(shift @fields)->send_keys('xfce'); # var

is($driver->find_element('//button[@title="Add"]')->click(), 1, 'added' );
# leave the ajax some time
Expand Down