| [1703] | 1 | describe("Others common methods (admin/js/common.js)", function() { |
|---|
| [1724] | 2 | describe("postsActionsHelper", function() { |
|---|
| 3 | it("A confirm popup must appear if action is \"delete\" and at least on checkbox is checked", function() { |
|---|
| 4 | loadFixtures('posts_list.html'); |
|---|
| 5 | dotclear.postsActionsHelper(); |
|---|
| 6 | |
|---|
| [2726] | 7 | spyOn(window, 'confirm').and.returnValue(false); |
|---|
| 8 | var submitCallback = jasmine.createSpy().and.returnValue(false); |
|---|
| [1724] | 9 | $('#form-entries').submit(submitCallback); |
|---|
| [1703] | 10 | |
|---|
| [1724] | 11 | $('select[name="action"] option[value="delete"]').attr('selected', 'selected'); |
|---|
| 12 | $('input[type="checkbox"][name="entries[]"][value="2"]').attr('checked', 'checked'); |
|---|
| [1703] | 13 | |
|---|
| [1724] | 14 | $('#form-entries').trigger('submit'); |
|---|
| 15 | expect(window.confirm).toHaveBeenCalled(); |
|---|
| 16 | }); |
|---|
| 17 | it("Confirm popup doesn't appear if action is \"delete\" but no checkbox is checked", function() { |
|---|
| 18 | loadFixtures('posts_list.html'); |
|---|
| 19 | dotclear.postsActionsHelper(); |
|---|
| 20 | |
|---|
| [2726] | 21 | spyOn(window, 'confirm').and.returnValue(false); |
|---|
| 22 | var submitCallback = jasmine.createSpy().and.returnValue(false); |
|---|
| [1724] | 23 | $('#form-entries').submit(submitCallback); |
|---|
| 24 | |
|---|
| 25 | $('select[name="action"] option[value="delete"]').attr('selected', 'selected'); |
|---|
| 26 | $('#form-entries').trigger('submit'); |
|---|
| 27 | expect(window.confirm).not.toHaveBeenCalled(); |
|---|
| 28 | }); |
|---|
| 29 | it("Others actions don't show confirm popup", function() { |
|---|
| 30 | loadFixtures('posts_list.html'); |
|---|
| 31 | dotclear.postsActionsHelper(); |
|---|
| 32 | |
|---|
| [2726] | 33 | spyOn(window, 'confirm').and.returnValue(false); |
|---|
| 34 | var submitCallback = jasmine.createSpy().and.returnValue(false); |
|---|
| [1724] | 35 | $('#form-entries').submit(submitCallback); |
|---|
| 36 | |
|---|
| 37 | $('select[name="action"] option[value="publish"]').attr('selected', 'selected'); |
|---|
| 38 | $('#form-entries').trigger('submit'); |
|---|
| 39 | expect(window.confirm).not.toHaveBeenCalled(); |
|---|
| 40 | }); |
|---|
| [1703] | 41 | }); |
|---|
| 42 | |
|---|
| [1724] | 43 | describe("commentsActionsHelper", function() { |
|---|
| 44 | it("A confirm popup must appear if action is \"delete\" and at least on checkbox is checked", function() { |
|---|
| 45 | loadFixtures('comments_list.html'); |
|---|
| 46 | dotclear.commentsActionsHelper(); |
|---|
| 47 | |
|---|
| [2726] | 48 | spyOn(window, 'confirm').and.returnValue(false); |
|---|
| 49 | var submitCallback = jasmine.createSpy().and.returnValue(false); |
|---|
| [1724] | 50 | $('#form-comments').submit(submitCallback); |
|---|
| 51 | |
|---|
| 52 | $('select[name="action"] option[value="delete"]').attr('selected', 'selected'); |
|---|
| 53 | $('input[type="checkbox"][name="comments[]"][value="2"]').attr('checked', 'checked'); |
|---|
| 54 | |
|---|
| 55 | $('#form-comments').trigger('submit'); |
|---|
| 56 | expect(window.confirm).toHaveBeenCalled(); |
|---|
| 57 | }); |
|---|
| 58 | it("Confirm popup doesn't appear if action is \"delete\" but no checkbox is checked", function() { |
|---|
| 59 | loadFixtures('comments_list.html'); |
|---|
| 60 | dotclear.commentsActionsHelper(); |
|---|
| 61 | |
|---|
| [2726] | 62 | spyOn(window, 'confirm').and.returnValue(false); |
|---|
| 63 | var submitCallback = jasmine.createSpy().and.returnValue(false); |
|---|
| [1724] | 64 | $('#form-comments').submit(submitCallback); |
|---|
| 65 | |
|---|
| 66 | $('select[name="action"] option[value="delete"]').attr('selected', 'selected'); |
|---|
| 67 | $('#form-comments').trigger('submit'); |
|---|
| 68 | expect(window.confirm).not.toHaveBeenCalled(); |
|---|
| 69 | }); |
|---|
| 70 | it("Others actions don't show confirm popup", function() { |
|---|
| 71 | loadFixtures('comments_list.html'); |
|---|
| 72 | dotclear.commentsActionsHelper(); |
|---|
| 73 | |
|---|
| [2726] | 74 | spyOn(window, 'confirm').and.returnValue(false); |
|---|
| 75 | var submitCallback = jasmine.createSpy().and.returnValue(false); |
|---|
| [1724] | 76 | $('#form-comments').submit(submitCallback); |
|---|
| 77 | |
|---|
| 78 | $('select[name="action"] option[value="publish"]').attr('selected', 'selected'); |
|---|
| 79 | $('#form-comments').trigger('submit'); |
|---|
| 80 | expect(window.confirm).not.toHaveBeenCalled(); |
|---|
| 81 | }); |
|---|
| [1703] | 82 | }); |
|---|
| [2200] | 83 | |
|---|
| 84 | describe("checkboxesHelpers", function() { |
|---|
| 85 | it("Must add links to select all,none or invert selection", function() { |
|---|
| 86 | loadFixtures('entries_list.html'); |
|---|
| 87 | dotclear.checkboxesHelpers($('.checkboxes-helpers', '#form-entries')); |
|---|
| 88 | |
|---|
| 89 | expect($('.checkboxes-helpers a', '#form-entries').length).toBe(3); |
|---|
| 90 | expect($('.checkboxes-helpers a:eq(0)', '#form-entries').text()).toBe(dotclear.msg.select_all); |
|---|
| 91 | expect($('.checkboxes-helpers a:eq(1)', '#form-entries').text()).toBe(dotclear.msg.no_selection); |
|---|
| 92 | expect($('.checkboxes-helpers a:eq(2)', '#form-entries').text()).toBe(dotclear.msg.invert_sel); |
|---|
| 93 | }); |
|---|
| 94 | |
|---|
| 95 | it("Click all must select all checkboxes", function() { |
|---|
| 96 | loadFixtures('entries_list.html'); |
|---|
| 97 | dotclear.checkboxesHelpers($('.checkboxes-helpers', '#form-entries')); |
|---|
| 98 | |
|---|
| 99 | $('.checkboxes-helpers a:eq(0)').click(); |
|---|
| 100 | expect($('#form-entries input[name="entries[]"]:checked').length).toBe(4); |
|---|
| 101 | }); |
|---|
| 102 | |
|---|
| 103 | it("Click 'no selection' must uncheck all checkboxes", function() { |
|---|
| 104 | loadFixtures('entries_list.html'); |
|---|
| 105 | dotclear.checkboxesHelpers($('.checkboxes-helpers', '#form-entries')); |
|---|
| 106 | |
|---|
| 107 | $('input[name="entries[]"]:eq(1)').click(); |
|---|
| 108 | $('input[name="entries[]"]:eq(3)').click(); |
|---|
| 109 | $('.checkboxes-helpers a:eq(1)').click(); |
|---|
| 110 | expect($('#form-entries input[name="entries[]"]:checked').length).toBe(0); |
|---|
| 111 | }); |
|---|
| 112 | |
|---|
| 113 | it("Click invert must select all uncheck checkboxes", function() { |
|---|
| 114 | loadFixtures('entries_list.html'); |
|---|
| 115 | dotclear.checkboxesHelpers($('.checkboxes-helpers', '#form-entries')); |
|---|
| 116 | |
|---|
| 117 | $('input[name="entries[]"]:eq(1)').click(); |
|---|
| 118 | $('.checkboxes-helpers a:eq(2)').click(); |
|---|
| 119 | expect($('#form-entries input[name="entries[]"]:checked').length).toBe(3); |
|---|
| 120 | expect($('input[name="entries[]"]:eq(0)')).toBeChecked(); |
|---|
| 121 | expect($('input[name="entries[]"]:eq(1)')).not.toBeChecked(); |
|---|
| 122 | expect($('input[name="entries[]"]:eq(2)')).toBeChecked(); |
|---|
| 123 | expect($('input[name="entries[]"]:eq(3)')).toBeChecked(); |
|---|
| 124 | }); |
|---|
| 125 | |
|---|
| 126 | it("Must take in consideration checkbox added dynamically", function() { |
|---|
| 127 | loadFixtures('entries_list.html'); |
|---|
| 128 | dotclear.checkboxesHelpers($('.checkboxes-helpers', '#form-entries')); |
|---|
| 129 | |
|---|
| 130 | $('<li><input type="checkbox" name="entries[]" value="5"/><p>title 5</p></li>').appendTo('#form-entries ul'); |
|---|
| 131 | |
|---|
| 132 | $('.checkboxes-helpers a:eq(0)').click(); |
|---|
| 133 | expect($('#form-entries input[name="entries[]"]:checked').length).toBe(5); |
|---|
| 134 | }); |
|---|
| 135 | }); |
|---|
| [1703] | 136 | }); |
|---|