|
| 1 | +use Test::More; # tests => 1; |
| 2 | +use strict; |
| 3 | +use warnings; |
| 4 | + |
| 5 | +use Log::Report; |
| 6 | +use GADS::Layout; |
| 7 | +use GADS::Record; |
| 8 | +use GADS::Records; |
| 9 | +use GADS::Schema; |
| 10 | +use GADS::Filter; |
| 11 | +use GADS::View; |
| 12 | + |
| 13 | +use lib 't/lib'; |
| 14 | +use Test::GADS::DataSheet; |
| 15 | + |
| 16 | +use Data::Dump qw(pp); |
| 17 | + |
| 18 | +my $long_string = "Y3EucBXt2aTYnHNb2hXJTrgAg0QqRieA1kxNo1ud2TbcyxrXMXqu" |
| 19 | + . "/m83YtthBWYXiEdocydX69XqB/6IK+6NqGDZJgofxgjVxGJmP1HONBT651Yj/" |
| 20 | + . "47mRf4+coC3gqvzh6vQ1nCeZyWeVKVuoiiG5INOuwanGJESPDgJrvichI00Czskjah5Ju6/" |
| 21 | + . "tHOez+6p3hciNXUYuq76g6KFkTn4tbWegJd2Hh/bNVYqTX5yDW0MIQQQSoe2i+NLA5xi"; |
| 22 | + |
| 23 | +my $data = [ |
| 24 | + { |
| 25 | + string1 => [$long_string], |
| 26 | + }, |
| 27 | + { |
| 28 | + string1 => ['The quick brown fox jumps over the lazy dog.'], |
| 29 | + } |
| 30 | +]; |
| 31 | + |
| 32 | +my $sheet = Test::GADS::DataSheet->new( |
| 33 | + data => $data, |
| 34 | + multivalue => 0, |
| 35 | + calc_code => " |
| 36 | + function evaluate (L1string1) |
| 37 | + return L1string1 |
| 38 | + end |
| 39 | + ", |
| 40 | + calc_return_type => 'string', |
| 41 | +); |
| 42 | +$sheet->create_records; |
| 43 | + |
| 44 | +my $schema = $sheet->schema; |
| 45 | +my $layout = $sheet->layout; |
| 46 | +my $columns = $sheet->columns; |
| 47 | +my $user = $sheet->user_normal1; |
| 48 | + |
| 49 | +my $string1 = $columns->{string1}; |
| 50 | +my $calc1 = $columns->{calc1}; |
| 51 | + |
| 52 | +my $record = GADS::Record->new( |
| 53 | + layout => $layout, |
| 54 | + schema => $schema, |
| 55 | + instance_id => 1, |
| 56 | + user => $user, |
| 57 | +); |
| 58 | + |
| 59 | +$record->find_current_id(1); |
| 60 | + |
| 61 | +my $filter = GADS::Filter->new( |
| 62 | + as_hash => { |
| 63 | + rules => [ |
| 64 | + { |
| 65 | + id => $calc1->id, |
| 66 | + type => 'string', |
| 67 | + value => $long_string, |
| 68 | + operator => 'equal', |
| 69 | + } |
| 70 | + ], |
| 71 | + }, |
| 72 | +); |
| 73 | + |
| 74 | +my $view = GADS::View->new( |
| 75 | + name => 'View table', |
| 76 | + filter => $filter, |
| 77 | + instance_id => 1, |
| 78 | + layout => $layout, |
| 79 | + schema => $schema, |
| 80 | + is_shared => 1, |
| 81 | +); |
| 82 | + |
| 83 | +$view->write( no_errors => 1 ); |
| 84 | + |
| 85 | +my $records = GADS::Records->new( |
| 86 | + user => $user, |
| 87 | + layout => $layout, |
| 88 | + schema => $schema, |
| 89 | + view => $view |
| 90 | +); |
| 91 | + |
| 92 | +is $records->count, 1, "One record found with long string in calc field"; |
| 93 | + |
| 94 | +$filter->as_hash->{rules}[0]{value} = "brown"; |
| 95 | +$filter->as_hash->{rules}[0]{operator} = "contains"; |
| 96 | + |
| 97 | +my $view2 = GADS::View->new( |
| 98 | + name => 'View table 2', |
| 99 | + filter => $filter, |
| 100 | + instance_id => 1, |
| 101 | + layout => $layout, |
| 102 | + schema => $schema, |
| 103 | + is_shared => 1, |
| 104 | +); |
| 105 | + |
| 106 | +$view2->write( no_errors => 1 ); |
| 107 | + |
| 108 | +$records->clear; |
| 109 | + |
| 110 | +$records->view($view2); |
| 111 | + |
| 112 | +is $records->count, 1, "One record found with the word `brown` in the string field"; |
| 113 | + |
| 114 | +$records->clear; |
| 115 | + |
| 116 | +$records->view(undef); |
| 117 | + |
| 118 | +is $records->count, 2, "No filter, two records found"; |
| 119 | + |
| 120 | +$records->clear; |
| 121 | + |
| 122 | +$filter->as_hash->{rules}[0]{value} = "non-existing string"; |
| 123 | +$filter->as_hash->{rules}[0]{operator} = "equal"; |
| 124 | + |
| 125 | +my $view3 = GADS::View->new( |
| 126 | + name => 'View table 3', |
| 127 | + filter => $filter, |
| 128 | + instance_id => 1, |
| 129 | + layout => $layout, |
| 130 | + schema => $schema, |
| 131 | + is_shared => 1, |
| 132 | +); |
| 133 | + |
| 134 | +$records->view($view); |
| 135 | + |
| 136 | +is $records->count, 0, "No records found with non-existing string"; |
| 137 | + |
| 138 | +done_testing; |
0 commit comments