Merge lp:~rharding/launchpad/fix_banner_cleanup into lp:launchpad

Proposed by Richard Harding
Status: Merged
Approved by: j.c.sackett
Approved revision: no longer in the source branch.
Merged at revision: 16113
Proposed branch: lp:~rharding/launchpad/fix_banner_cleanup
Merge into: lp:launchpad
Diff against target: 171 lines (+28/-50)
5 files modified
lib/lp/app/javascript/banners/banner.js (+7/-2)
lib/lp/app/javascript/banners/privacy.js (+8/-8)
lib/lp/app/javascript/banners/tests/test_privacy.js (+7/-39)
lib/lp/app/javascript/information_type.js (+2/-0)
lib/lp/app/javascript/tests/test_information_type.js (+4/-1)
To merge this branch: bzr merge lp:~rharding/launchpad/fix_banner_cleanup
Reviewer Review Type Date Requested Status
j.c.sackett (community) Approve
Review via email: mp+128026@code.launchpad.net

Commit message

Slight clean and decouple of the banner and information type JS.

Description of the change

= Summary =

Originally I introduced a bug in the privacy banner and information type
updates. I had moved a function off the JS module namespace that was used
elsewhere. In the process of updating that, some other code was added that
isn't required. This tries to decouple back up the banner from the information
type as much as possible.

== Implementation Notes ==

The test for the text_node is purely because of the testing. It's a lot of extra html to bootstrap that we don't need to test against.

We force the event driven code to pass the banner text so that the information_type method get_banner_text is kept within it's module and privacy.js isn't calling into it.

The test_privacy then no longer needs to bootstrap all the information_type data in the LP.cache and the tests are updated to make sure the text data is passed into the event.

The event drive code isn't currently used, but will be tied into place in a future branch.

== Q/A ==

The banner should fire and work when a bug is changed to private, to public,
and security related information types.

== Tests ==

test_information_type.html
test_privacy.html

To post a comment you must log in.
Revision history for this message
j.c.sackett (jcsackett) wrote :

Looks fine.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/app/javascript/banners/banner.js'
2--- lib/lp/app/javascript/banners/banner.js 2012-09-28 02:39:42 +0000
3+++ lib/lp/app/javascript/banners/banner.js 2012-10-08 11:39:21 +0000
4@@ -125,7 +125,12 @@
5 if (!Y.Lang.isValue(new_text)) {
6 new_text = this.get('notification_text');
7 }
8- text_node.set('text', new_text);
9+
10+ if (text_node) {
11+ text_node.set('text', new_text);
12+ } else {
13+ Y.log('No text node to update banner text.', 'error');
14+ }
15 }
16
17 }, {
18@@ -147,5 +152,5 @@
19 });
20
21 }, '0.1', {
22- requires: ['base', 'node', 'anim', 'widget', 'lp.mustache']
23+ requires: ['base', 'node', 'anim', 'widget', 'lp.mustache', 'yui-log']
24 });
25
26=== modified file 'lib/lp/app/javascript/banners/privacy.js'
27--- lib/lp/app/javascript/banners/privacy.js 2012-09-27 03:17:02 +0000
28+++ lib/lp/app/javascript/banners/privacy.js 2012-10-08 11:39:21 +0000
29@@ -75,26 +75,26 @@
30
31 _make_private: function (ev) {
32 // Update the text in the banner before we show it.
33- var banner_text;
34 var body = Y.one('body');
35 body.replaceClass('public', 'private');
36
37- if (ev.text) {
38- banner_text = ev.text;
39- } else {
40- banner_text = Y.lp.app.information_type.get_banner_text(ev.value);
41+ if (!ev.text) {
42+ throw('Showing a privacy banner must supply text for the banner');
43 }
44-
45- this.updateText(banner_text);
46+ this.updateText(ev.text);
47 this.show();
48 },
49
50 bindUI: function () {
51 var that = this;
52+ var info_type = Y.lp.app.information_type;
53 Banner.prototype.bindUI.apply(this, arguments);
54- var info_type = Y.lp.app.information_type;
55+
56+ // We care about changes to Information Type in the UI.
57 Y.on(info_type.EV_ISPUBLIC, that._make_public, that);
58 Y.on(info_type.EV_ISPRIVATE, that._make_private, that);
59+
60+ // And provide our own manual events for the Security banner usage.
61 Y.on(ns.EV_SHOW, that._custom_message, that);
62 Y.on(ns.EV_HIDE, function (ev) {
63 that.hide();
64
65=== modified file 'lib/lp/app/javascript/banners/tests/test_privacy.js'
66--- lib/lp/app/javascript/banners/tests/test_privacy.js 2012-09-27 03:17:02 +0000
67+++ lib/lp/app/javascript/banners/tests/test_privacy.js 2012-10-08 11:39:21 +0000
68@@ -11,42 +11,6 @@
69 name: 'privacy_tests',
70
71 setUp: function () {
72- window.LP = {
73- cache: {
74- context: {
75- web_link: ''
76- },
77- notifications_text: {
78- muted: ''
79- },
80- bug: {
81- information_type: 'Public',
82- self_link: '/bug/1'
83- },
84- information_type_data: {
85- PUBLIC: {
86- value: 'PUBLIC', name: 'Public',
87- is_private: false, order: 1,
88- description: 'Public Description'
89- },
90- PUBLICSECURITY: {
91- value: 'PUBLICSECURITY', name: 'Public Security',
92- is_private: false, order: 2,
93- description: 'Public Security Description'
94- },
95- PROPRIETARY: {
96- value: 'PROPRIETARY', name: 'Proprietary',
97- is_private: true, order: 3,
98- description: 'Private Description'
99- },
100- USERDATA: {
101- value: 'USERDATA', name: 'Private',
102- is_private: true, order: 4,
103- description: 'Private Description'
104- }
105- }
106- }
107- };
108 var main = Y.Node.create('<div id="maincontent"></div>');
109 var login_logout = Y.Node.create('<div></div>')
110 .addClass('login-logout');
111@@ -120,11 +84,15 @@
112
113 test_info_type_private_event: function () {
114 var banner = Y.lp.app.banner.privacy.getPrivacyBanner();
115+ var body = Y.one('body');
116+ var msg = 'Some private message';
117+ Y.fire('information_type:is_private', {
118+ text: msg,
119+ value: 'PROPRIETARY'
120+ });
121 Y.Assert.areEqual(
122- 'The information on this page is private.',
123+ msg,
124 Y.one('.global-notification').get('text'));
125- Y.fire('information_type:is_private');
126- var body = Y.one('body');
127 Y.Assert.isTrue(body.hasClass('private'),
128 'Body should be private');
129 Y.Assert.isTrue(banner.get('visible'),
130
131=== modified file 'lib/lp/app/javascript/information_type.js'
132--- lib/lp/app/javascript/information_type.js 2012-09-28 16:47:42 +0000
133+++ lib/lp/app/javascript/information_type.js 2012-10-08 11:39:21 +0000
134@@ -38,6 +38,7 @@
135 *
136 * @event information_type:is_private
137 * @param value The new information type value.
138+ * @param text A message about the new information type value.
139 */
140 Y.publish(ns.EV_ISPRIVATE, {
141 emitFacade: true
142@@ -61,6 +62,7 @@
143 'value',
144 'is_private')) {
145 Y.fire(ns.EV_ISPRIVATE, {
146+ text: ns.get_banner_text(ev.value),
147 value: ev.value
148 });
149 } else {
150
151=== modified file 'lib/lp/app/javascript/tests/test_information_type.js'
152--- lib/lp/app/javascript/tests/test_information_type.js 2012-09-28 01:25:36 +0000
153+++ lib/lp/app/javascript/tests/test_information_type.js 2012-10-08 11:39:21 +0000
154@@ -42,7 +42,7 @@
155 PROPRIETARY: {
156 value: 'PROPRIETARY', name: 'Proprietary',
157 is_private: true, order: 3,
158- description: 'Private Description'
159+ description: 'Proprietary Description'
160 },
161 USERDATA: {
162 value: 'USERDATA', name: 'Private',
163@@ -402,6 +402,9 @@
164 });
165 var private_ev = Y.on('information_type:is_private', function (ev) {
166 Y.Assert.areEqual('PROPRIETARY', ev.value);
167+ Y.Assert.areEqual(
168+ 'This page contains Proprietary information.',
169+ ev.text);
170 called = true;
171 });
172