launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #09491
[Merge] lp:~jcsackett/launchpad/add-yui-tests-for-comments into lp:launchpad
j.c.sackett has proposed merging lp:~jcsackett/launchpad/add-yui-tests-for-comments into lp:launchpad with lp:~jcsackett/launchpad/comment-cleanup as a prerequisite.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~jcsackett/launchpad/add-yui-tests-for-comments/+merge/113118
Summary
=======
Test coverage for the javascript commment module is appalling. This is nowhere
near complete, but starts adding tests.
Implementation
==============
Test are added for the basics of the comment module. This involves updating
the initializer to accept a mock lp_client so we can use
test.helpers.LPClient, and testing those things which require no refactoring
to be testable.
There is clearly more to be done, but one thing at a time.
Tests
=====
bin/test -vvct test_comment --layer=YUI
QA
==
None, this just adds tests.
LoC
===
This is part of disclosure.
Lint
====
Checking for conflicts and issues in changed files.
Linting changed files:
lib/lp/app/javascript/tests/test_comment.html
lib/lp/app/javascript/tests/test_comment.js
lib/lp/app/javascript/comment.js
--
https://code.launchpad.net/~jcsackett/launchpad/add-yui-tests-for-comments/+merge/113118
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jcsackett/launchpad/add-yui-tests-for-comments into lp:launchpad.
=== modified file 'lib/lp/app/javascript/comment.js'
--- lib/lp/app/javascript/comment.js 2012-07-02 21:08:25 +0000
+++ lib/lp/app/javascript/comment.js 2012-07-02 21:08:25 +0000
@@ -8,11 +8,15 @@
*
* @method initializer
*/
- initializer: function() {
+ initializer: function(cfg) {
+ if (Y.Lang.isValue(cfg) && Y.Lang.isValue(cfg.lp_client)) {
+ this.lp_client = cfg.lp_client;
+ } else {
+ this.lp_client = new Y.lp.client.Launchpad();
+ }
this.submit_button = this.get_submit();
this.comment_input = Y.one(
'#add-comment-form [id="field.comment"]');
- this.lp_client = new Y.lp.client.Launchpad();
this.error_handler = new Y.lp.client.ErrorHandler();
this.error_handler.clearProgressUI = Y.bind(
this.clearProgressUI, this);
=== added file 'lib/lp/app/javascript/tests/test_comment.html'
--- lib/lp/app/javascript/tests/test_comment.html 1970-01-01 00:00:00 +0000
+++ lib/lp/app/javascript/tests/test_comment.html 2012-07-02 21:08:25 +0000
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<!--
+Copyright 2012 Canonical Ltd. This software is licensed under the
+GNU Affero General Public License version 3 (see the file LICENSE).
+-->
+
+<html>
+ <head>
+ <title>lp.app.comments Tests</title>
+
+ <!-- YUI and test setup -->
+ <script type="text/javascript"
+ src="../../../../../build/js/yui/yui/yui.js">
+ </script>
+ <link rel="stylesheet"
+ href="../../../../../build/js/yui/console/assets/console-core.css" />
+ <link rel="stylesheet"
+ href="../../../../../build/js/yui/console/assets/skins/sam/console.css" />
+ <link rel="stylesheet"
+ href="../../../../../build/js/yui/test/assets/skins/sam/test.css" />
+
+ <script type="text/javascript"
+ src="../../../../../build/js/lp/app/testing/testrunner.js"></script>
+ <script type="text/javascript"
+ src="../../../../../build/js/lp/app/testing/helpers.js"></script>
+ <link rel="stylesheet"
+ href="../../../../../build/js/lp/app/testing/test.css"/>
+
+ <!-- Dependencies -->
+ <script type="text/javascript"
+ src="../../../../../build/js/lp/app/errors.js"></script>
+ <script type="text/javascript"
+ src="../../../../../build/js/lp/app/client.js"></script>
+ <script type="text/javascript"
+ src="../../../../../build/js/lp/app/client.js"></script>
+ <!-- The module under test. -->
+ <script type="text/javascript" src="../comment.js"></script>
+
+ <!-- The test suite -->
+ <script type="text/javascript" src="test_comment.js"></script>
+
+ </head>
+ <body class="yui3-skin-sam">
+ <ul id="suites">
+ <li>lp.app.comment.test</li>
+ </ul>
+ <div id="add-comment-form">
+ <h2>Add comment</h2>
+ <form action="+addcomment" method="post"
+ enctype="multipart/form-data" accept-charset="UTF-8">
+ <textarea cols="60"
+ id="field.comment" name="field.comment" rows="15"></textarea>
+ <div class="actions">
+ <input disabled="disabled"
+ style="display: inline;" id="field.actions.save"
+ name="field.actions.save" value="Post Comment"
+ class="button js-action" type="submit"/>
+ </div>
+ </form>
+ </div>
+ </body>
+</html>
=== added file 'lib/lp/app/javascript/tests/test_comment.js'
--- lib/lp/app/javascript/tests/test_comment.js 1970-01-01 00:00:00 +0000
+++ lib/lp/app/javascript/tests/test_comment.js 2012-07-02 21:08:25 +0000
@@ -0,0 +1,58 @@
+/* Copyright (c) 2012 Canonical Ltd. All rights reserved. */
+
+YUI.add('lp.app.comment.test', function (Y) {
+
+ var tests = Y.namespace('lp.app.comment.test');
+ tests.suite = new Y.Test.Suite('lp.app.comment Tests');
+
+ tests.suite.add(new Y.Test.Case({
+ name: 'lp.app.comment_tests',
+
+ setUp: function () {},
+ tearDown: function () {},
+
+ test_library_exists: function () {
+ Y.Assert.isObject(Y.lp.app.comment,
+ "Could not locate the lp.app.comment module");
+ },
+
+ test_init: function () {
+ var comment = new Y.lp.app.comment.Comment();
+ Y.Assert.isObject(comment.comment_input);
+ Y.Assert.isObject(comment.submit_button);
+ Y.Assert.isTrue(
+ comment.progress_message.hasClass('update-in-progress-message'));
+ },
+
+ test_validation: function () {
+ var comment = new Y.lp.app.comment.Comment();
+ comment.comment_input.set('value', 'foo ');
+ Y.Assert.isTrue(comment.validate());
+
+ comment.comment_input.set('value', ' ');
+ Y.Assert.isFalse(comment.validate());
+ },
+
+ test_post_comment: function () {
+ window.LP = {
+ cache: {
+ bug: { self_link: '/bug/1/' }
+ }
+ };
+ var mock_client = new Y.lp.testing.helpers.LPClient();
+ cfg = { lp_client: mock_client };
+ var comment = new Y.lp.app.comment.Comment(cfg);
+ var no_op = function () {};
+ mock_client.named_post.args = [];
+ comment.post_comment(no_op);
+ Y.Assert.areEqual(
+ mock_client.received[0][1][0],
+ '/bug/1/');
+ Y.Assert.areEqual(
+ mock_client.received[0][1][1],
+ 'newMessage');
+ }
+ }));
+
+}, '0.1', {'requires': ['test', 'lp.testing.helpers', 'console',
+ 'lp.app.comment']});
Follow ups