summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--web-ui/app/js/mail_view/data/feedback_sender.js49
-rw-r--r--web-ui/app/js/mail_view/ui/feedback_box.js4
-rw-r--r--web-ui/test/spec/mail_view/data/feedback_sender.spec.js27
-rw-r--r--web-ui/test/spec/mail_view/ui/feedback_box.spec.js6
4 files changed, 81 insertions, 5 deletions
diff --git a/web-ui/app/js/mail_view/data/feedback_sender.js b/web-ui/app/js/mail_view/data/feedback_sender.js
new file mode 100644
index 00000000..2232dbe4
--- /dev/null
+++ b/web-ui/app/js/mail_view/data/feedback_sender.js
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2015 ThoughtWorks, Inc.
+ *
+ * Pixelated is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Pixelated is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
+ */
+define(
+ [
+ 'flight/lib/component',
+ 'helpers/monitored_ajax',
+ 'page/events'
+ ],
+ function (defineComponent, monitoredAjax, events) {
+ 'use strict';
+
+ return defineComponent(function () {
+ this.defaultAttrs({
+ feedbackResource: '/feedback'
+ });
+
+ this.successSubmittingFeedback = function() {
+ this.trigger(document, events.feedback.submitted);
+ };
+
+ this.submitFeedback = function(event, data) {
+ monitoredAjax.call(_, this, this.attr.feedbackResource, {
+ type: 'POST',
+ dataType: 'json',
+ contentType: 'application/json; charset=utf-8',
+ data: JSON.stringify(data)
+ }).done(this.successSubmittingFeedback());
+ };
+
+ this.after('initialize', function () {
+ this.on(document, events.feedback.submit, this.submitFeedback);
+ });
+
+ });
+});
diff --git a/web-ui/app/js/mail_view/ui/feedback_box.js b/web-ui/app/js/mail_view/ui/feedback_box.js
index f6994554..aad35f2a 100644
--- a/web-ui/app/js/mail_view/ui/feedback_box.js
+++ b/web-ui/app/js/mail_view/ui/feedback_box.js
@@ -43,8 +43,8 @@ define(['flight/lib/component', 'views/templates', 'page/events', 'features'],
this.submitFeedback = function () {
var feedback = this.select('textBox').val();
- this.trigger(document, events.feedback.submit, { feedback: feedback});
- }
+ this.trigger(document, events.feedback.submit, { feedback: feedback });
+ };
this.after('initialize', function () {
if (features.isEnabled('feedback')) {
diff --git a/web-ui/test/spec/mail_view/data/feedback_sender.spec.js b/web-ui/test/spec/mail_view/data/feedback_sender.spec.js
new file mode 100644
index 00000000..30952c3f
--- /dev/null
+++ b/web-ui/test/spec/mail_view/data/feedback_sender.spec.js
@@ -0,0 +1,27 @@
+describeComponent('mail_view/data/feedback_sender', function () {
+ 'use strict';
+
+
+ beforeEach(function () {
+ this.setupComponent();
+ });
+
+ it('sends feedback with a POST to the server', function() {
+ var data = {feedback: 'Pixelated is awesome!'};
+ var feedbackSubmittedEventSpy = spyOnEvent(document, Pixelated.events.feedback.submitted);
+ var deferred = $.Deferred();
+
+ spyOn($, 'ajax').and.returnValue(deferred);
+
+ this.component.trigger(document, Pixelated.events.feedback.submit, data);
+
+ deferred.resolve();
+
+ expect(feedbackSubmittedEventSpy).toHaveBeenTriggeredOn(document);
+
+ expect($.ajax.calls.mostRecent().args[0]).toEqual('/feedback');
+ expect($.ajax.calls.mostRecent().args[1].type).toEqual('POST');
+ expect(JSON.parse($.ajax.calls.mostRecent().args[1].data)).toEqual(data);
+ });
+
+});
diff --git a/web-ui/test/spec/mail_view/ui/feedback_box.spec.js b/web-ui/test/spec/mail_view/ui/feedback_box.spec.js
index a034b028..f0d55791 100644
--- a/web-ui/test/spec/mail_view/ui/feedback_box.spec.js
+++ b/web-ui/test/spec/mail_view/ui/feedback_box.spec.js
@@ -21,10 +21,10 @@ describeComponent('mail_view/ui/feedback_box', function () {
it('should fire submit feedback event', function () {
var spy = spyOnEvent(document, Pixelated.events.feedback.submit);
- this.component.select("textBox").val("Pixelated is Awesome!");
+ this.component.select('textBox').val('Pixelated is Awesome!');
this.component.select('submitButton').click();
- expect(spy).toHaveBeenTriggeredOnAndWith(document, {feedback: "Pixelated is Awesome!"});
- })
+ expect(spy).toHaveBeenTriggeredOnAndWith(document, {feedback: 'Pixelated is Awesome!'});
+ });
it('should close feedback box after submit', function() {
var spy = spyOnEvent(document, Pixelated.events.dispatchers.rightPane.openNoMessageSelected);