|
8 | 8 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
9 | 9 | // See the License for the specific language governing permissions and |
10 | 10 | // limitations under the License. |
11 | | -// |
| 11 | +// |
12 | 12 | // Automatically generated by addcopyright.py at 04/03/2012 |
13 | 13 | (function($) { |
14 | 14 | module('Detail view', { |
|
17 | 17 | cloudStack.ui.notifications.__add = cloudStack.ui.notifications.add; |
18 | 18 | $.fn.__cloudBrowser = $.fn.cloudBrowser; |
19 | 19 | $.fn.__listView = $.fn.listView; |
| 20 | + $.fn.__dataTable = $.fn.dataTable; |
| 21 | + $.fn.__is = $.fn.is; |
| 22 | + |
| 23 | + $.fn.is = function(args) { |
| 24 | + if (args == ':visible') |
| 25 | + return true; // No test elems will ever be shown, so just pretend they are visible |
| 26 | + |
| 27 | + return true; |
| 28 | + }; |
20 | 29 | }, |
21 | 30 |
|
22 | 31 | teardown: function() { |
23 | 32 | cloudStack.dialog.confirm = cloudStack.dialog.__confirm; |
24 | 33 | cloudStack.ui.notifications.add = cloudStack.ui.notifications.__add; |
25 | 34 | $.fn.cloudBrowser = $.fn.__cloudBrowser; |
26 | 35 | $.fn.listView = $.fn.__listView; |
| 36 | + $.fn.dataTable = $.fn.__dataTable; |
| 37 | + $.fn.is = $.fn.__is; |
27 | 38 | } |
28 | 39 | }); |
29 | 40 |
|
|
419 | 430 |
|
420 | 431 | return this; |
421 | 432 | }; |
422 | | - |
| 433 | + |
423 | 434 | $.fn.cloudBrowser = function(cmd, args) { |
424 | 435 | start(); |
425 | 436 | equal(cmd, 'addPanel', 'Browser add panel called'); |
|
479 | 490 |
|
480 | 491 | return this; |
481 | 492 | }; |
482 | | - |
| 493 | + |
483 | 494 | $.fn.cloudBrowser = function(cmd, args) { |
484 | 495 | start(); |
485 | 496 | equal(cmd, 'addPanel', 'Browser add panel called'); |
|
489 | 500 |
|
490 | 501 | $detailView.find('.view-all a').click(); |
491 | 502 | }); |
| 503 | + |
| 504 | + test('Pre-action', function() { |
| 505 | + var detailView = { |
| 506 | + actions: { |
| 507 | + test: { |
| 508 | + label: 'test', |
| 509 | + preAction: function() { |
| 510 | + start(); |
| 511 | + ok(true, 'Pre-action called'); |
| 512 | + |
| 513 | + return false; |
| 514 | + }, |
| 515 | + action: function() { |
| 516 | + ok(false, 'Action called; pre-action should have blocked it'); |
| 517 | + }, |
| 518 | + messages: { notification: function() { return 'notification'; }} |
| 519 | + } |
| 520 | + }, |
| 521 | + tabs: { |
| 522 | + test: { |
| 523 | + title: 'test', |
| 524 | + label: 'testAction', |
| 525 | + fields: [{ |
| 526 | + fieldA: { label: 'fieldA' }, |
| 527 | + fieldB: { label: 'fieldB' } |
| 528 | + }], |
| 529 | + dataProvider: function(args) { args.response.success({ data: {} }); } |
| 530 | + } |
| 531 | + } |
| 532 | + }; |
| 533 | + var $detailView = $('<div>'); |
| 534 | + |
| 535 | + stop(); |
| 536 | + $detailView.detailView(detailView); |
| 537 | + $detailView.find('.action.test a').click(); |
| 538 | + }); |
| 539 | + |
| 540 | + test('Update data, from list view row', function() { |
| 541 | + var detailView = { |
| 542 | + section: 'testListView', |
| 543 | + context: { |
| 544 | + testListView: [{ |
| 545 | + fieldA: 'fieldA-1', |
| 546 | + fieldB: 'fieldB-1', |
| 547 | + fieldC: 'fieldC-1' |
| 548 | + }] |
| 549 | + }, |
| 550 | + actions: { |
| 551 | + updateDataTestSync: { |
| 552 | + label: 'updateDataTestSync', |
| 553 | + preAction: function(args) { return true; }, |
| 554 | + action: function(args) { |
| 555 | + args.response.success({ |
| 556 | + data: { |
| 557 | + fieldA: 'fieldA-2', |
| 558 | + fieldB: 'fieldB-2' |
| 559 | + } |
| 560 | + }); |
| 561 | + |
| 562 | + start(); |
| 563 | + equal($detailView.data('view-args').context.testListView[0].fieldA, 'fieldA-2', 'Correct context value for fieldA'); |
| 564 | + equal($detailView.data('view-args').context.testListView[0].fieldB, 'fieldB-2', 'Correct context value for fieldB'); |
| 565 | + equal($detailView.data('view-args').context.testListView[0].fieldC, 'fieldC-1', 'Correct context value for fieldC'); |
| 566 | + equal($detailView.find('tr.fieldA .value').html(), 'fieldA-2', 'Correct table value for fieldA'); |
| 567 | + equal($detailView.find('tr.fieldB .value').html(), 'fieldB-2', 'Correct table value for fieldB'); |
| 568 | + equal($detailView.find('tr.fieldC .value').html(), 'fieldC-1', 'Correct table value for fieldC'); |
| 569 | + }, |
| 570 | + messages: { notification: function() { return 'notification'; }} |
| 571 | + } |
| 572 | + }, |
| 573 | + tabs: { |
| 574 | + test: { |
| 575 | + title: 'test', |
| 576 | + fields: [{ |
| 577 | + fieldA: { label: 'fieldA' }, |
| 578 | + fieldB: { label: 'fieldB' }, |
| 579 | + fieldC: { label: 'fieldC' } |
| 580 | + }], |
| 581 | + dataProvider: function(args) { |
| 582 | + args.response.success({ |
| 583 | + data: args.context.testListView[0] |
| 584 | + }); |
| 585 | + } |
| 586 | + } |
| 587 | + } |
| 588 | + }; |
| 589 | + var $detailView = $('<div>'); |
| 590 | + var $listView = $('<div>').addClass('list-view'); |
| 591 | + var $listViewRow = $('<div>').data('json-obj', detailView.context.testListView[0]).appendTo($listView); |
| 592 | + var $cloudStackContainer = $('<div>').attr('cloudStack-container', true).data('cloudStack-args', { |
| 593 | + sections: { |
| 594 | + testListView: {} |
| 595 | + } |
| 596 | + }).appendTo('#qunit-fixture'); |
| 597 | + |
| 598 | + $.fn.dataTable = function() { return this; }; |
| 599 | + $.fn.listView = function(args1, args2) { |
| 600 | + if (args1 == 'replaceItem') |
| 601 | + args2.after(args2.$row.data('json-obj', args2.data)); |
| 602 | + |
| 603 | + return this; |
| 604 | + }; |
| 605 | + |
| 606 | + cloudStack.ui.notifications.add = function(notification, complete) { |
| 607 | + complete(); |
| 608 | + }; |
| 609 | + cloudStack.dialog.confirm = function(args) { |
| 610 | + args.action(); |
| 611 | + }; |
| 612 | + $detailView.data('list-view-row', $listViewRow); |
| 613 | + $detailView.detailView(detailView); |
| 614 | + |
| 615 | + stop(); |
| 616 | + $detailView.find('.action.updateDataTestSync a').click(); |
| 617 | + }); |
492 | 618 | }(jQuery)); |
0 commit comments