File: OverviewPreview.t

package info (click to toggle)
znuny 6.5.18-1
  • links: PTS
  • area: non-free
  • in suites: forky, sid
  • size: 205,344 kB
  • sloc: perl: 1,038,694; xml: 74,551; javascript: 65,276; sql: 23,574; sh: 417; makefile: 63
file content (422 lines) | stat: -rw-r--r-- 15,290 bytes parent folder | download | duplicates (5)
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
# --
# Copyright (C) 2001-2021 OTRS AG, https://otrs.com/
# Copyright (C) 2021 Znuny GmbH, https://znuny.org/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
# --

use strict;
use warnings;
use utf8;

use vars (qw($Self));

my $Selenium = $Kernel::OM->Get('Kernel::System::UnitTest::Selenium');

$Selenium->RunTest(
    sub {

        my $HelperObject       = $Kernel::OM->Get('Kernel::System::UnitTest::Helper');
        my $UserObject         = $Kernel::OM->Get('Kernel::System::User');
        my $AutoResponseObject = $Kernel::OM->Get('Kernel::System::AutoResponse');
        my $TicketObject       = $Kernel::OM->Get('Kernel::System::Ticket');

        # Get sort attributes config params.
        my %SortOverview = (
            Age          => 1,
            Title        => 1,
            TicketNumber => 1,
        );

        # Defines from which ticket attributes the agent can select the result order.
        $HelperObject->ConfigSettingChange(
            Key   => 'TicketOverviewMenuSort###SortAttributes',
            Value => \%SortOverview,
        );
        $HelperObject->ConfigSettingChange(
            Valid => 1,
            Key   => 'TicketOverviewMenuSort###SortAttributes',
            Value => \%SortOverview,
        );
        $HelperObject->ConfigSettingChange(
            Valid => 1,
            Key   => 'Ticket::NewArticleIgnoreSystemSender',
            Value => 0,
        );

        # Override FirstnameLastnameOrder setting to check if it is taken into account
        #   (see bug#12554 for more information).
        $HelperObject->ConfigSettingChange(
            Valid => 1,
            Key   => 'FirstnameLastnameOrder',
            Value => 5,
        );

        # Create test user.
        my $TestUserLogin = $HelperObject->TestUserCreate(
            Groups => [ 'admin', 'users' ],
        ) || die "Did not get test user";

        # Get test user ID
        my $TestUserID = $UserObject->UserLookup(
            UserLogin => $TestUserLogin,
        );

        # Get user data.
        my %TestUser = $UserObject->GetUserData(
            UserID => $TestUserID,
        );

        my $RandomID = $HelperObject->GetRandomID();

        # Create test queue.
        my $QueueName = 'Queue' . $RandomID;
        my $QueueID   = $Kernel::OM->Get('Kernel::System::Queue')->QueueAdd(
            Name            => $QueueName,
            ValidID         => 1,
            GroupID         => 1,
            SystemAddressID => 1,
            SalutationID    => 1,
            SignatureID     => 1,
            Comment         => 'Selenium Queue',
            UserID          => $TestUserID,
        );
        $Self->True(
            $QueueID,
            "QueueAdd() successful for test $QueueName - ID $QueueID",
        );

        # Create auto response.
        my $AutoResponseID = $AutoResponseObject->AutoResponseAdd(
            Name        => 'AutoResponse' . $RandomID,
            ValidID     => 1,
            Subject     => 'Some Subject..',
            Response    => 'Auto Response Test....',
            ContentType => 'text/plain',
            AddressID   => 1,
            TypeID      => 1,
            UserID      => 1,
        );
        $Self->True(
            $AutoResponseID,
            "Auto response created.",
        );

        my $AutoResponseSuccess = $AutoResponseObject->AutoResponseQueue(
            QueueID         => $QueueID,
            AutoResponseIDs => [$AutoResponseID],
            UserID          => 1,
        );
        $Self->True(
            $AutoResponseSuccess,
            "Auto response added for created queue.",
        );

        $TicketObject->{SendNoNotification} = 0;

        # Create test tickets.
        my @TicketIDs;
        my @TicketNumbers;
        for my $Ticket ( 1 .. 15 ) {
            my $TicketNumber = $TicketObject->TicketCreateNumber();
            my $TicketID     = $TicketObject->TicketCreate(
                TN           => $TicketNumber,
                Title        => 'Some Ticket Title',
                Queue        => $QueueName,
                Lock         => 'unlock',
                Priority     => '3 normal',
                State        => 'new',
                CustomerID   => 'TestCustomer',
                CustomerUser => 'customer@example.com',
                OwnerID      => $TestUserID,
                UserID       => $TestUserID,
            );

            $Self->True(
                $TicketID,
                "Ticket is created - $TicketID"
            );

            push @TicketIDs,     $TicketID;
            push @TicketNumbers, $TicketNumber;
        }
        my @SortTicketNumbers = sort @TicketNumbers;

        my $RandomNumber = $HelperObject->GetRandomNumber();

        my $ArticleBackendObject = $Kernel::OM->Get('Kernel::System::Ticket::Article')->BackendForChannel(
            ChannelName => 'Email',
        );

        for my $Index (qw(0 1 2)) {

            # Add articles to tickets.
            my $ArticleID1 = $ArticleBackendObject->ArticleCreate(
                TicketID             => $TicketIDs[$Index],
                SenderType           => 'customer',
                IsVisibleForCustomer => 1,
                ContentType          => 'text/plain',
                From                 => "Some Customer A <customer-a$RandomNumber\@example.com>",
                To                   => "Some otrs system <email$RandomNumber\@example.com>",
                Subject              => "First article of the ticket # $Index",
                Body                 => 'the message text',
                HistoryComment       => 'Some free text!',
                HistoryType          => 'NewTicket',
                UserID               => 1,
                AutoResponseType     => 'auto reply',
                OrigHeader           => {
                    'Subject' => "First article of the ticket # $Index",
                    'Body'    => 'the message text',
                    'To'      => "Some otrs system <email$RandomNumber\@example.com>",
                    'From'    => "Some Customer A <customer-a$RandomNumber\@example.com>",
                },
            );

            $Self->True(
                $ArticleID1,
                "First article created for ticket# $Index",
            );

            # Only for third ticket add agent article.
            if ( $Index > 1 ) {
                my $ArticleID2 = $ArticleBackendObject->ArticleCreate(
                    TicketID             => $TicketIDs[$Index],
                    SenderType           => 'agent',
                    IsVisibleForCustomer => 1,
                    ContentType          => 'text/plain',
                    From                 => "Some otrs system <email$RandomNumber\@example.com>",
                    To                   => "Some Customer A <customer-a$RandomNumber\@example.com>",
                    Subject              => "Second article of the ticket # $Index",
                    Body                 => 'agent reply',
                    HistoryComment       => 'Some free text!',
                    HistoryType          => 'SendAnswer',
                    UserID               => 1,
                );
                $Self->True(
                    $ArticleID2,
                    "Second article created for ticket# $Index",
                );
            }
        }

        # Login as test user.
        $Selenium->Login(
            Type     => 'Agent',
            User     => $TestUserLogin,
            Password => $TestUserLogin,
        );

        # Go to queue ticket overview.
        my $ScriptAlias = $Kernel::OM->Get('Kernel::Config')->Get('ScriptAlias');
        $Selenium->VerifiedGet("${ScriptAlias}index.pl?Action=AgentTicketQueue;QueueID=$QueueID;View=");

        # Switch to large view.
        $Selenium->find_element( "a.Large", 'css' )->VerifiedClick();

        # Check if owner name conforms to current FirstnameLastNameOrder setting.
        $Self->True(
            index( $Selenium->get_page_source(), $TestUser{UserFullname} ) > -1,
            "$TestUser{UserFullname} - found on screen"
        );

        # Sort by ticket number.
        $Selenium->InputFieldValueSet(
            Element => '#SortBy',
            Value   => 'TicketNumber|Up',
        );

        # Wait for page reload after changing sort param.
        $Selenium->WaitFor(
            JavaScript =>
                'return typeof($) === "function" && $("a[href*=\'SortBy=TicketNumber;OrderBy=Up\']").length'
        );
        $Selenium->VerifiedRefresh();

        # Set 10 tickets per page.
        $Selenium->find_element( "a#ShowContextSettingsDialog", 'css' )->click();
        sleep 1;
        $Selenium->WaitFor(
            JavaScript => 'return $(".Dialog.Modal #UserTicketOverviewPreviewPageShown").length'
        );
        $Selenium->InputFieldValueSet(
            Element => '#UserTicketOverviewPreviewPageShown',
            Value   => '10',
        );
        $Selenium->find_element( "#DialogButton1", 'css' )->click();
        $Selenium->WaitFor(
            JavaScript => 'return !$(".Dialog.Modal").length'
        );

        # Check for ticket with lowest ticket number on first 1st page and verify that ticket
        # with highest ticket number number is not present.
        $Self->True(
            index( $Selenium->get_page_source(), $SortTicketNumbers[0] ) > -1,
            "$SortTicketNumbers[0] - found on screen"
        );
        $Self->True(
            index( $Selenium->get_page_source(), $SortTicketNumbers[14] ) == -1,
            "$SortTicketNumbers[14] - not found on screen"
        );

        # Switch to 2nd page to test pagination.
        $Selenium->find_element( "#AgentTicketQueuePage2", 'css' )->VerifiedClick();

        # Check for ticket with highest ticket number.
        $Self->True(
            index( $Selenium->get_page_source(), $SortTicketNumbers[14] ) > -1,
            "$SortTicketNumbers[14] - found on screen"
        );

        # Check if settings are stored when switching between view.
        $Selenium->find_element( "a.Medium", 'css' )->VerifiedClick();
        $Selenium->find_element( "a.Large",  'css' )->VerifiedClick();
        $Self->True(
            index( $Selenium->get_page_source(), $SortTicketNumbers[0] ) > -1,
            "$SortTicketNumbers[0] - found on screen after changing views"
        );
        $Self->True(
            index( $Selenium->get_page_source(), $SortTicketNumbers[14] ) == -1,
            "$SortTicketNumbers[14] - not found on screen after changing views"
        );

        # Check which articles are selected.
        my $SelectedArticle1 = $Selenium->execute_script(
            "return \$('li#TicketID_" . $TicketIDs[0] . " .Preview li.Active').index();",
        );
        $Self->Is(
            $SelectedArticle1,
            1,
            "Selected article for First ticket is OK.",
        );

        my $SelectedArticle2 = $Selenium->execute_script(
            "return \$('li#TicketID_" . $TicketIDs[1] . " .Preview li.Active').index();",
        );
        $Self->Is(
            $SelectedArticle2,
            1,
            "Selected article for Second ticket is OK.",
        );

        my $SelectedArticle3 = $Selenium->execute_script(
            "return \$('li#TicketID_" . $TicketIDs[2] . " .Preview li.Active').index();",
        );
        $Self->Is(
            $SelectedArticle3,
            2,
            "Selected article for Third ticket is OK.",
        );

        # Update Ticket::NewArticleIgnoreSystemSender.
        $HelperObject->ConfigSettingChange(
            Valid => 1,
            Key   => 'Ticket::NewArticleIgnoreSystemSender',
            Value => 1,
        );

        # Reload the page.
        $Selenium->VerifiedGet("${ScriptAlias}index.pl?Action=AgentTicketQueue;QueueID=$QueueID;View=");

        # Sort by ticket number.
        $Selenium->InputFieldValueSet(
            Element => '#SortBy',
            Value   => 'TicketNumber|Up',
        );

        # Wait for page reload after changing sort param.
        $Selenium->WaitFor(
            JavaScript =>
                'return typeof($) === "function" && $("a[href*=\'SortBy=TicketNumber;OrderBy=Up\']").length'
        );

        # Check which articles are selected.
        $SelectedArticle1 = $Selenium->execute_script(
            "return \$('li#TicketID_" . $TicketIDs[0] . " .Preview li.Active').index();",
        );
        $Self->Is(
            $SelectedArticle1,
            0,
            "Selected article for First ticket is OK(Ticket::NewArticleIgnoreSystemSender enabled).",
        );

        $SelectedArticle2 = $Selenium->execute_script(
            "return \$('li#TicketID_" . $TicketIDs[1] . " .Preview li.Active').index();",
        );
        $Self->Is(
            $SelectedArticle2,
            0,
            "Selected article for Second ticket is OK(Ticket::NewArticleIgnoreSystemSender enabled).",
        );

        $SelectedArticle3 = $Selenium->execute_script(
            "return \$('li#TicketID_" . $TicketIDs[2] . " .Preview li.Active').index();",
        );
        $Self->Is(
            $SelectedArticle3,
            2,
            "Selected article for Third ticket is OK(Ticket::NewArticleIgnoreSystemSender enabled).",
        );

        # Delete created test tickets.
        my $Success;
        for my $TicketID (@TicketIDs) {
            $Success = $TicketObject->TicketDelete(
                TicketID => $TicketID,
                UserID   => $TestUserID,
            );

            # Ticket deletion could fail if apache still writes to ticket history. Try again in this case.
            if ( !$Success ) {
                sleep 3;
                $Success = $TicketObject->TicketDelete(
                    TicketID => $TicketID,
                    UserID   => $TestUserID,
                );
            }
            $Self->True(
                $Success,
                "Delete ticket - $TicketID"
            );
        }

        my $DBObject = $Kernel::OM->Get('Kernel::System::DB');

        # Delete auto response links(queue).
        $Success = $DBObject->Do(
            SQL => "DELETE FROM queue_auto_response WHERE auto_response_id = $AutoResponseID",
        );
        $Self->True(
            $Success,
            "Delete auto response links - $AutoResponseID",
        );

        # Delete created auto response.
        $Success = $DBObject->Do(
            SQL => "DELETE FROM auto_response WHERE id = $AutoResponseID",
        );
        $Self->True(
            $Success,
            "Delete auto response - $AutoResponseID",
        );

        # Delete created test queue.
        $Success = $DBObject->Do(
            SQL => "DELETE FROM queue WHERE id = $QueueID",
        );
        $Self->True(
            $Success,
            "Delete queue - $QueueID",
        );

        my $CacheObject = $Kernel::OM->Get('Kernel::System::Cache');

        # Make sure cache is correct.
        for my $Cache (qw( Ticket Queue )) {
            $CacheObject->CleanUp( Type => $Cache );
        }
    }
);

1;