js test for comments updated.
svn path=/plone.app.discussion/trunk/; revision=40166
This commit is contained in:
		
							parent
							
								
									9d0fa61c4d
								
							
						
					
					
						commit
						c364630a8c
					
				@ -1,105 +1,130 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
$(document).ready(function () {
 | 
					$(document).ready(function () {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* TEST SETUP */
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						module("comments", {
 | 
				
			||||||
 | 
						    setup: function () {
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
						        // Create a comments section with one comment inside
 | 
				
			||||||
 | 
								//
 | 
				
			||||||
 | 
								// <div class="discussion">
 | 
				
			||||||
 | 
								//   <div id="1282720906349675" class="comment">
 | 
				
			||||||
 | 
								//     <div class="commentBody">
 | 
				
			||||||
 | 
								//       <p>Lorem ipsum.</p>
 | 
				
			||||||
 | 
								//     </div>
 | 
				
			||||||
 | 
								//     <div class="commentActions">
 | 
				
			||||||
 | 
								//       <button class="reply-to-comment-button"></button>
 | 
				
			||||||
 | 
								//     </div>
 | 
				
			||||||
 | 
								//   </div>
 | 
				
			||||||
 | 
								// </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module("comments", {
 | 
						        var comments = $(document.createElement("div"))
 | 
				
			||||||
    setup: function () {
 | 
						            .addClass("discussion")
 | 
				
			||||||
        // Create a comments section with one comment inside
 | 
						            .append($(document.createElement("div"))
 | 
				
			||||||
        var comments = $(document.createElement("div"))
 | 
						                .addClass("comment")
 | 
				
			||||||
            .addClass("discussion")
 | 
						                .attr("id", "1282720906349675")
 | 
				
			||||||
            .append($(document.createElement("div"))
 | 
										.append($(document.createElement("div"))
 | 
				
			||||||
                .addClass("comment")
 | 
										    .addClass("commentBody")
 | 
				
			||||||
                .attr("id", "1282720906349675")
 | 
						                    .append($(document.createElement("p"))
 | 
				
			||||||
                .append($(document.createElement("div"))
 | 
											    .text("Lorem ipsum.")
 | 
				
			||||||
                    .addClass("commentActions"))
 | 
											)
 | 
				
			||||||
                    .append($(document.createElement("button"))
 | 
										)
 | 
				
			||||||
                        .addClass("reply-to-comment-button")
 | 
						                .append($(document.createElement("div"))
 | 
				
			||||||
                )
 | 
						                    .addClass("commentActions")
 | 
				
			||||||
            );
 | 
						                    .append($(document.createElement("button"))
 | 
				
			||||||
        $(document.body).append(comments);
 | 
						                        .addClass("reply-to-comment-button")
 | 
				
			||||||
                
 | 
						                ))
 | 
				
			||||||
        // Create a basic commenting form
 | 
						            );
 | 
				
			||||||
        var commentform = $(document.createElement("div"))
 | 
						        $(document.body).append(comments);
 | 
				
			||||||
            .append($(document.createElement("form"))
 | 
						                
 | 
				
			||||||
                .addClass("form")
 | 
						        // Create a basic commenting form
 | 
				
			||||||
                .append($(document.createElement("div"))
 | 
						        var commentform = $(document.createElement("div"))
 | 
				
			||||||
                    .addClass("formfield-form-widgets-in_reply_to")
 | 
						            .append($(document.createElement("form"))
 | 
				
			||||||
                    .append($(document.createElement("input"))
 | 
						                .addClass("form")
 | 
				
			||||||
                        .attr("name", "form.widgets.in_reply_to")
 | 
						                .append($(document.createElement("div"))
 | 
				
			||||||
                        .val("")        
 | 
						                    .addClass("formfield-form-widgets-in_reply_to")
 | 
				
			||||||
                    )
 | 
						                    .append($(document.createElement("input"))
 | 
				
			||||||
                )
 | 
						                        .attr("name", "form.widgets.in_reply_to")
 | 
				
			||||||
                .append($(document.createElement("div"))
 | 
						                        .val("")
 | 
				
			||||||
                    .addClass("formfield-form-widgets-author_name")
 | 
						                    )
 | 
				
			||||||
                    .append($(document.createElement("input"))
 | 
						                )
 | 
				
			||||||
                        .attr("name", "form.widgets.author")                        
 | 
						                .append($(document.createElement("div"))
 | 
				
			||||||
                        .attr("type", "text")
 | 
						                    .addClass("formfield-form-widgets-author_name")
 | 
				
			||||||
                    )
 | 
						                    .append($(document.createElement("input"))
 | 
				
			||||||
                )
 | 
						                        .attr("name", "form.widgets.author")                        
 | 
				
			||||||
                .append($(document.createElement("div"))
 | 
						                        .attr("type", "text")
 | 
				
			||||||
                    .addClass("formfield-form-widgets-text")
 | 
						                    )
 | 
				
			||||||
                    .append($(document.createElement("textarea"))
 | 
						                )
 | 
				
			||||||
                        .attr("name", "form.widgets.text")
 | 
						                .append($(document.createElement("div"))
 | 
				
			||||||
                    )
 | 
						                    .addClass("formfield-form-widgets-text")
 | 
				
			||||||
                )
 | 
						                    .append($(document.createElement("textarea"))
 | 
				
			||||||
                .append($(document.createElement("div"))
 | 
						                        .attr("name", "form.widgets.text")
 | 
				
			||||||
                    .addClass("formControls")
 | 
						                    )
 | 
				
			||||||
                    .append($(document.createElement("input"))
 | 
						                )
 | 
				
			||||||
                        .attr("name", "form.buttons.comment"))
 | 
						                .append($(document.createElement("div"))
 | 
				
			||||||
                    .append($(document.createElement("input"))
 | 
						                    .addClass("formControls")
 | 
				
			||||||
                        .attr("name", "form.buttons.cancel"))
 | 
						                    .append($(document.createElement("input"))
 | 
				
			||||||
                )
 | 
						                        .attr("name", "form.buttons.comment"))
 | 
				
			||||||
            )
 | 
						                    .append($(document.createElement("input"))
 | 
				
			||||||
            .addClass("reply")
 | 
						                        .attr("name", "form.buttons.cancel"))
 | 
				
			||||||
            .attr("id", "commenting");
 | 
						                )
 | 
				
			||||||
        $(document.body).append(commentform);
 | 
						            )
 | 
				
			||||||
    },
 | 
						            .addClass("reply")
 | 
				
			||||||
    teardown: function () {
 | 
						            .attr("id", "commenting");
 | 
				
			||||||
        $("#commenting").remove();
 | 
						        $(document.body).append(commentform);
 | 
				
			||||||
        $(".discussion").remove();
 | 
						    },
 | 
				
			||||||
    }
 | 
						    teardown: function () {
 | 
				
			||||||
});
 | 
						        $("#commenting").remove();
 | 
				
			||||||
 | 
						        $(".discussion").remove();
 | 
				
			||||||
 | 
						    }
 | 
				
			||||||
test("Hide the reply and the cancel button for the comment form", function(){
 | 
						});
 | 
				
			||||||
    expect(1);
 | 
						
 | 
				
			||||||
    $(".reply").find("input[name='form.buttons.cancel']").css("display", "none");
 | 
						
 | 
				
			||||||
    equals($("input[name='form.buttons.cancel']").css("display"), "none", "The cancel button should be hidden");
 | 
						/* TESTS */
 | 
				
			||||||
});
 | 
						
 | 
				
			||||||
 | 
						test("Hide the reply and the cancel button for the comment form", function(){
 | 
				
			||||||
test("Show the reply button only when Javascript is enabled", function(){
 | 
						    expect(1);
 | 
				
			||||||
    expect(1);
 | 
						    $(".reply").find("input[name='form.buttons.cancel']").css("display", "none");
 | 
				
			||||||
    $(".reply-to-comment-button").css("display", "inline");
 | 
						    equals($("input[name='form.buttons.cancel']").css("display"), "none", "The cancel button should be hidden");
 | 
				
			||||||
    equals($("button[class='reply-to-comment-button']").attr("style"), "display: inline;", "The reply button should show up when Javascript is enabled");
 | 
						});
 | 
				
			||||||
});
 | 
						
 | 
				
			||||||
 | 
						test("Show the reply button only when Javascript is enabled", function(){
 | 
				
			||||||
test("Create a comment reply form.", function() {
 | 
						    expect(1);
 | 
				
			||||||
    expect(2);
 | 
						    $(".reply-to-comment-button").css("display", "inline");
 | 
				
			||||||
    var comment_div = $("#1282720906349675");
 | 
						    equals($("button[class='reply-to-comment-button']").attr("style"), "display: inline;", "The reply button should show up when Javascript is enabled");
 | 
				
			||||||
    createReplyForm(comment_div);
 | 
						});
 | 
				
			||||||
    var reply_form = comment_div.find(".reply");
 | 
						
 | 
				
			||||||
    ok(reply_form, "Reply form has been copied");
 | 
						test("Create a comment reply form.", function() {
 | 
				
			||||||
    same(reply_form.find("input[name='form.widgets.in_reply_to']").val(), "1282720906349675", "The reply for should have the id of the comment in the in_reply_to field");
 | 
						    expect(2);
 | 
				
			||||||
});
 | 
						    var comment_div = $("#1282720906349675");
 | 
				
			||||||
 | 
							var reply_button = comment_div.find(".reply-to-comment-button");
 | 
				
			||||||
test("Clear all form values from a form.", function() {
 | 
							// Hit the reply button
 | 
				
			||||||
    // Create a reply form with some values
 | 
							reply_button.trigger("click");
 | 
				
			||||||
    var comment_div = $("#1282720906349675");
 | 
						    createReplyForm(comment_div);
 | 
				
			||||||
    createReplyForm(comment_div);
 | 
						    var reply_form = comment_div.find(".reply");
 | 
				
			||||||
    var reply_form = comment_div.find(".reply");
 | 
						    ok(reply_form, "Reply form has been copied");
 | 
				
			||||||
    var author = reply_form.find("input[name='form.widgets.author']");
 | 
						    same(reply_form.find("input[name='form.widgets.in_reply_to']").val(), "1282720906349675", "The reply for should have the id of the comment in the in_reply_to field");
 | 
				
			||||||
    var text = comment_div.find("input[name='form.widgets.text']");
 | 
						});
 | 
				
			||||||
    author.val("my author");
 | 
						
 | 
				
			||||||
    text.val("my text");
 | 
						test("Clear all form values from a form.", function() {
 | 
				
			||||||
    // Call the clearForm function to clear the form
 | 
						    // Create a reply form with some values
 | 
				
			||||||
    clearForm(comment_div);
 | 
						    var comment_div = $("#1282720906349675");
 | 
				
			||||||
    // Check if all form fields have been cleared
 | 
						    createReplyForm(comment_div);
 | 
				
			||||||
    var author = comment_div.find("input[name='form.widgets.author']");
 | 
						    var reply_form = comment_div.find(".reply");
 | 
				
			||||||
    var text = comment_div.find("input[name='form.widgets.text']");
 | 
						    var author = reply_form.find("input[name='form.widgets.author']");
 | 
				
			||||||
    equals(author.val(), "", "The author form value should be empty");
 | 
						    var text = comment_div.find("input[name='form.widgets.text']");
 | 
				
			||||||
    equals(text.text(), "", "The text form value should be empty");
 | 
						    author.val("my author");
 | 
				
			||||||
 | 
						    text.val("my text");
 | 
				
			||||||
});
 | 
						    // Call the clearForm function to clear the form
 | 
				
			||||||
 | 
						    clearForm(comment_div);
 | 
				
			||||||
 | 
						    // Check if all form fields have been cleared
 | 
				
			||||||
 | 
						    var author = comment_div.find("input[name='form.widgets.author']");
 | 
				
			||||||
 | 
						    var text = comment_div.find("input[name='form.widgets.text']");
 | 
				
			||||||
 | 
						    equals(author.val(), "", "The author form value should be empty");
 | 
				
			||||||
 | 
						    equals(text.text(), "", "The text form value should be empty");
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user