Skip to content

Commit

Permalink
Merge pull request #4032 from ehuelsmann/expand-bdd-ar
Browse files Browse the repository at this point in the history
Expand bdd ar
  • Loading branch information
ehuelsmann committed Apr 9, 2019
2 parents a1b9e8a + 93ab9f3 commit 05d5446
Show file tree
Hide file tree
Showing 10 changed files with 265 additions and 14 deletions.
14 changes: 7 additions & 7 deletions old/bin/aa.pl
Expand Up @@ -816,9 +816,9 @@ sub form_header {
<th class=listheading>| . $locale->text('Payments') . qq|</th>
</tr>
<tr id="invoice-payments-table">
<tr>
<td>
<table width=100%>
<table width=100% id="invoice-payments-table">
|;

if ( $form->{currency} eq $form->{defaultcurrency} ) {
Expand All @@ -836,9 +836,9 @@ sub form_header {
$column_data{source} = "<th>" . $locale->text('Source') . "</th>";
$column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";

print "
print qq|
<tr>
";
|;

for (@column_index) { print "$column_data{$_}\n" }

Expand All @@ -855,9 +855,9 @@ sub form_header {

$form->hide_form("cleared_$i");

print "
<tr>
";
print q|
<tr class="invoice-payment">
|;

$form->{"select$form->{ARAP}_paid_$i"} =
$form->{"select$form->{ARAP}_paid"};
Expand Down
2 changes: 1 addition & 1 deletion old/bin/ir.pl
Expand Up @@ -847,7 +847,7 @@ sub form_footer {
$form->hide_form("cleared_$i");

print qq|
<tr>
<tr class="invoice-payment">
|;

$form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
Expand Down
4 changes: 2 additions & 2 deletions old/bin/is.pl
Expand Up @@ -956,8 +956,8 @@ sub form_footer {

$form->hide_form("cleared_$i");

print "
<tr>\n";
print qq{
<tr class="invoice-payment">\n};

$form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
$form->{"selectAR_paid_$i"} =~
Expand Down
5 changes: 4 additions & 1 deletion old/lib/LedgerSMB/Form.pm
Expand Up @@ -1093,12 +1093,15 @@ for the button.
=cut

my $btn = 0;

sub print_button {
my ( $self, $button, $name ) = @_;

my $type = $button->{$name}{type} // 'dijit/form/Button';
$btn++;
print
qq|<button data-dojo-type="$type" class="submit" type="submit" name="action" value="$name" accesskey="$button->{$name}{key}" title="$button->{$name}{value} [Alt-$button->{$name}{key}]">$button->{$name}{value}</button>\n|;
qq|<button data-dojo-type="$type" class="submit" type="submit" name="action" value="$name" id="action-$name-$btn" accesskey="$button->{$name}{key}" title="$button->{$name}{value} [Alt-$button->{$name}{key}]">$button->{$name}{value}</button>\n|;
}


Expand Down
2 changes: 1 addition & 1 deletion t/10-form.t
Expand Up @@ -267,7 +267,7 @@ is($form->sort_order($aryref, {name => 0, projectnumber => 3, startdate => 1}),
## $form->print_button checks
$form = Form->new;
@r = trap{$form->print_button({'pear' => {'key' => 'P', 'value' => 'Pears'}}, 'pear')};
is($trap->stdout, "<button data-dojo-type=\"dijit/form/Button\" class=\"submit\" type=\"submit\" name=\"action\" value=\"pear\" accesskey=\"P\" title=\"Pears [Alt-P]\">Pears</button>\n", 'print_button');
is($trap->stdout, "<button data-dojo-type=\"dijit/form/Button\" class=\"submit\" type=\"submit\" name=\"action\" value=\"pear\" id=\"action-pear-1\" accesskey=\"P\" title=\"Pears [Alt-P]\">Pears</button>\n", 'print_button');

## $form->like checks
$form = Form->new;
Expand Down
24 changes: 23 additions & 1 deletion xt/66-cucumber/11-ar/invoice.feature
Expand Up @@ -40,4 +40,26 @@ Scenario: Creation of a new sales invoice, no taxes
Then I expect to see an invoice with these lines
| Item | Number | Description | Qty | Unit | OH | Price | % | Extended | TaxForm | Delivery Date | Notes | Serial No. |
| 1 | p1 | Part 1 | 1 | ea | 0 | 30.00 | 0 | 30.00 | | | | |
And I expect to see the invoice subtotal of 30.00 and total of 30.00 without taxes
And I expect to see the invoice subtotal of 30.00 and total of 30.00 without taxes
And I expect to see 1 empty payment line
When I post the invoice
Then I expect to see these invoice header fields and values
| name | value |
| Invoice Created | $$today |
| Invoice Date | $$today |
| Due Date | $$today |
| Record in | 1200--Accounts Receivables |
| Currency | USD |
| Description | |
| Shipping Point | |
| Ship via | |
| Invoice Number | 2 |
| Order Number | |
| PO Number | |
And I expect to see an invoice with these lines
| Item | Number | Description | Qty | Unit | OH | Price | % | Extended | TaxForm | Delivery Date | Notes | Serial No. |
| 1 | p1 | Part 1 | 1 | ea | -1 | 30.00 | 0 | 30.00 | | | | |
And I expect to see the invoice subtotal of 30.00 and total of 30.00 without taxes
###TODO:
# And I expect to see 1 empty payment line
## For some reason, there are 2 empty payment lines?!
59 changes: 58 additions & 1 deletion xt/66-cucumber/11-ar/step_definitions/pageobject_steps.pl
Expand Up @@ -68,6 +68,14 @@
$inv->update;
};

When qr/I post the invoice/, sub {

my $session = S->{ext_wsl};
my $inv = $session->page->body->maindiv->content;
$inv->post;

};

Then qr/I expect to see an invoice with (\d+) (empty )?lines?/, sub {
my ($count, $empty) = ($1, $2);

Expand Down Expand Up @@ -97,7 +105,7 @@
S->{ext_wsl}->page->body->maindiv->content->lines->all_lines;

while (1) {
my $expected_line = shift @{$expected_lines};
my $expected_line = shift @{$expected_lines};
my $actual_line = shift @{$actual_lines};

if (! $expected_line && ! $actual_line) {
Expand Down Expand Up @@ -189,5 +197,54 @@
}
};

Then qr/I expect to see (\d+) (empty )?payment lines?/, sub {
my ($count, $empty) = ($1, $2);
my $page = S->{ext_wsl}->page->body->maindiv->content;
###TODO: verify this is an invoice!

$page = $page->payments;
my @payments = $page->payment_lines;
if ($empty) {
@payments = grep { $_->is_empty } @payments;
}
is(scalar(@payments), $count, 'Expected number of lines matches actual');
};

Then qr/I expect to see these payment lines/, sub {
my $expected_payments = C->data;
my $actual_payments =
S->{ext_wsl}->page->body->maindiv->content->payments->payment_lines;

while (1) {
my $expected_line = shift @{$expected_payments};
my $actual_line = shift @{$actual_payments};

if (! $expected_line && ! $actual_line) {
last;
}
elsif (! $expected_line && $actual_line->is_empty) {
next;
}
elsif (! $expected_line) {
fail('all actual lines in the list of expected lines');
}
elsif ($expected_line &&
(! $actual_line || $actual_line->is_empty)) {
fail('all expected lines present as actual lines');
}
else { # $expected_line isn't empty and neither is $actual_line
for my $field (keys %$expected_line) {
S->{ext_wsl}->wait_for(
sub {
return $actual_line->field_value($field) eq $expected_line->{$field};
});
is($actual_line->field_value($field),
$expected_line->{$field},
qq{Actual value for field $field matches expectation});
}
}
}
};


1;
37 changes: 37 additions & 0 deletions xt/lib/PageObject/App/AR/Invoice.pm
Expand Up @@ -7,6 +7,7 @@ use Carp;
use PageObject;
use PageObject::App::Invoices::Lines;
use PageObject::App::Invoices::Header;
use PageObject::App::Invoices::Payments;

use Moose;
use namespace::autoclean;
Expand Down Expand Up @@ -35,6 +36,34 @@ sub update {
$self->session->page->body->maindiv->wait_for_content;
}

sub _post_btn {
my ($self) = @_;

my $outer = $self->find('.//span[contains(@widgetid,"action-post-")]
| .//span[contains(@widgetid,"action-approve-")]');
my $lbl_id = $outer->get_attribute('widgetid');
my $label = $self->find(qq{//span[\@id="${lbl_id}_label"]});
return $label;
}

sub _post_btn_text {
my ($self) = @_;

return $self->_post_btn->get_text;
}

sub post {
my ($self) = @_;
if ($self->_post_btn_text eq 'Save') {
# 2-step in case separation of duties is enabled
$self->_post_btn->click;
$self->session->page->body->maindiv->wait_for_content;
}

$self->session->page->body->maindiv->content->_post_btn->click;
$self->session->page->body->maindiv->wait_for_content;
}

sub select_customer {
my ($self, $customer) = @_;

Expand Down Expand Up @@ -62,6 +91,14 @@ sub lines {
return $self->find('*invoice-lines');
}

sub payments {
my ($self) = @_;

$self->verify;
return $self->find('*invoice-payments',
widget_args => [ counterparty_type => 'customer' ]);
}

sub _extract_total {
my ($self, $type) = @_;
my $total_elm = $self->find(".invoice-$type", scheme => 'css');
Expand Down
89 changes: 89 additions & 0 deletions xt/lib/PageObject/App/Invoices/Payment.pm
@@ -0,0 +1,89 @@
package PageObject::App::Invoices::Payment;

use strict;
use warnings;

use Carp;
use PageObject;


use Moose;
use namespace::autoclean;
extends 'PageObject';

use PageObject::App;

__PACKAGE__->self_register(
'invoice-payment',
'.//tr[contains(@class,"invoice-payment")]',
tag_name => 'tr',
attributes => {
'class' => 'invoice-payment',
});

# counterparty_type IN ('customer', 'vendor')
has counterparty_type => (is => 'ro', isa => 'Str', required => 1);

has field_map => (is => 'ro', isa => 'HashRef', lazy => 1, builder => '_build_field_map');

sub _verify {
my ($self) = @_;

###TODO

return $self;
};

sub _build_field_map {
my ($self) = @_;

return {
'Date' => 'datepaid',
'Source' => 'source',
'Memo' => 'memo',
'Amount' => 'amount',
'Account' => ($self->counterparty_type eq 'customer' ? 'AR' : 'AP') . '_paid',
};
}

sub field {
my ($self, $label) = @_;
my $fieldname = $self->field_map->{$label};
return $self->find(qq{.//*[contains(\@name,"${fieldname}")]});
}

sub field_value {
my ($self, $label, $new_value) = @_;
my $fieldname = $self->field_map->{$label};
my $field = $self->find(
qq{.//input[contains(\@id,"${fieldname}")]
| .//input[\@type="hidden" and
contains(\@name,"${fieldname}")]});
die "Payment line column ${fieldname} not found"
if not defined $field;
my $rv = $field->value;

$rv = ''
if ($field->tag_name eq 'input'
&& $field->get_attribute('type') eq 'checkbox'
&& ! $field->selected);

if (defined $new_value) {
$field->click;
$field->clear;
$field->send_keys($new_value);
}

return $rv;
}


sub is_empty {
my ($self) = @_;
return ($self->field_value('Date') eq '');
}


__PACKAGE__->meta->make_immutable;

1;
43 changes: 43 additions & 0 deletions xt/lib/PageObject/App/Invoices/Payments.pm
@@ -0,0 +1,43 @@
package PageObject::App::Invoices::Payments;

use strict;
use warnings;

use Carp;
use PageObject;
use PageObject::App::Invoices::Payment;

use Moose;
use namespace::autoclean;
extends 'PageObject';

__PACKAGE__->self_register(
'invoice-payments',
'.//*[@id="invoice-payments-table"]',
tag_name => 'table',
attributes => {
id => 'invoice-payments-table',
});

# counterparty_type IN ('customer', 'vendor')
has counterparty_type => (is => 'ro', isa => 'Str', required => 1);


sub _verify {
my ($self) = @_;

return $self;
}

sub payment_lines {
my ($self) = @_;

$self->verify;
return $self->find_all('*invoice-payment',
widget_args => [ counterparty_type => $self->counterparty_type ]);
}


__PACKAGE__->meta->make_immutable;

1;

0 comments on commit 05d5446

Please sign in to comment.