From af7fa15060d65039c575654516e9d54c23ce6348 Mon Sep 17 00:00:00 2001 From: quenenni Date: Sat, 6 Apr 2013 22:37:03 +0200 Subject: [PATCH] Added front-end test --- static/js/ep_email.js | 26 +++- .../frontend/specs/email_notifications.js | 126 ++++++++++++++++++ 2 files changed, 146 insertions(+), 6 deletions(-) create mode 100644 static/tests/frontend/specs/email_notifications.js diff --git a/static/js/ep_email.js b/static/js/ep_email.js index 4be591a..487a973 100644 --- a/static/js/ep_email.js +++ b/static/js/ep_email.js @@ -123,7 +123,9 @@ exports.handleClientMessage_emailNotificationMissingParams = function (hook, con // (string | mandatory) the text inside the notification text: window._('ep_email_notifications.msgParamsMissing'), // (bool | optional) if you want it to fade out on its own or just sit there - sticky: true + sticky: true, + // (string | optional) add a class name to the gritter msg + class_name: "emailNotificationsParamsMissing" }); // Hide the notification menu in mysettings @@ -179,6 +181,8 @@ function askClientToEnterEmail(){ sticky: true, // (int | optional) the time you want it to be alive for before fading out time: 2000, + // (string | optional) add a class name to the gritter msg + class_name: "emailNotificationsPopupForm", // the function to bind to the form after_open: function(e){ $('#ep_email_form_popup').submit(function(){ @@ -219,7 +223,9 @@ function checkAndSend(e) { // (string | mandatory) the heading of the notification title: window._('ep_email_notifications.titleGritterError'), // (string | mandatory) the text inside the notification - text: window._('ep_email_notifications.msgOptionsNotChecked') + text: window._('ep_email_notifications.msgOptionsNotChecked'), + // (string | optional) add a class name to the gritter msg + class_name: "emailNotificationsSubscrOptionsMissing" }); } else if (email) { $('#' + formName).submit(); @@ -278,7 +284,9 @@ function showRegistrationSuccess(){ // (string | mandatory) the text inside the notification text: window._('ep_email_notifications.msgSubscrSuccess'), // (int | optional) the time you want it to be alive for before fading out - time: 10000 + time: 10000, + // (string | optional) add a class name to the gritter msg + class_name: "emailNotificationsSubscrResponseGood" }); } @@ -299,7 +307,9 @@ function showAlreadyRegistered(type){ // (string | mandatory) the text inside the notification text: msg, // (int | optional) the time you want it to be alive for before fading out - time: 7000 + time: 7000, + // (string | optional) add a class name to the gritter msg + class_name: "emailNotificationsSubscrResponseBad" }); } @@ -314,7 +324,9 @@ function showUnregistrationSuccess(){ // (string | mandatory) the text inside the notification text: window._('ep_email_notifications.msgUnsubscrSuccess'), // (int | optional) the time you want it to be alive for before fading out - time: 10000 + time: 10000, + // (string | optional) add a class name to the gritter msg + class_name: "emailNotificationsUnsubscrResponseGood" }); } @@ -328,7 +340,9 @@ function showWasNotRegistered(){ // (string | mandatory) the text inside the notification text: window._('ep_email_notifications.msgUnsubscrNotExisting'), // (int | optional) the time you want it to be alive for before fading out - time: 7000 + time: 7000, + // (string | optional) add a class name to the gritter msg + class_name: "emailNotificationsUnsubscrResponseBad" }); } diff --git a/static/tests/frontend/specs/email_notifications.js b/static/tests/frontend/specs/email_notifications.js new file mode 100644 index 0000000..b3f91fc --- /dev/null +++ b/static/tests/frontend/specs/email_notifications.js @@ -0,0 +1,126 @@ +describe("email notifications plugin", function(){ + //create a new pad before each test run + beforeEach(function(cb){ + helper.newPad(cb); + this.timeout(60000); + }); + + // Subscribe malformed email + var malformedEmail = "tutti@bad-email"; + + // Subscribe good email + var goodEmail = "tutti@non-existing-domain.org"; + + // Test the form in mysetting menu + + // Launch the tests + // First test without options selected + it("makes test without options selected", function(done) { + var chrome$ = helper.padChrome$; + + //click on the settings button to make settings visible + var $settingsButton = chrome$(".buttonicon-settings"); + $settingsButton.click(); + + // Show the notification form + chrome$('.ep_email_settings').slideDown(function() { + + chrome$('#ep_email_form_mysettings [name=ep_email]').val(goodEmail); + chrome$('#ep_email_form_mysettings [name=ep_email_onStart]').prop('checked', false); + chrome$('#ep_email_form_mysettings [name=ep_email_onEnd]').prop('checked', false); + + chrome$('#ep_email_form_mysettings [name=ep_email_subscribe]').click(); //function() { + + // Is the correct gritter msg there + helper.waitFor(function() { + return chrome$(".gritter-item").is(':visible') == true; + }) + .done(function(){ + expect(chrome$(".emailNotificationsSubscrOptionsMissing").is(':visible')).to.be(true); + done(); + }); + }); + }); + + // Second, test with a malformed email + it("makes test subscription with malformed email address", function(done) { + var chrome$ = helper.padChrome$; + + //click on the settings button to make settings visible + var $settingsButton = chrome$(".buttonicon-settings"); + $settingsButton.click(); + + // Show the notification form + chrome$('.ep_email_settings').slideDown(function() { + + chrome$('#ep_email_form_mysettings [name=ep_email]').val(malformedEmail); + chrome$('#ep_email_form_mysettings [name=ep_email_onStart]').prop('checked', true); + + chrome$('#ep_email_form_mysettings [name=ep_email_subscribe]').click(); + + // Is the correct gritter msg there + helper.waitFor(function() { + return chrome$(".gritter-item").is(':visible') == true; + }) + .done(function(){ + expect(chrome$(".emailNotificationsSubscrResponseBad").is(':visible')).to.be(true); + done(); + }); + }); + }); + + // Third, test unsubscription with an email not registered + it("makes test unsubscription with an unregistered email address", function(done) { + var chrome$ = helper.padChrome$; + + //click on the settings button to make settings visible + var $settingsButton = chrome$(".buttonicon-settings"); + $settingsButton.click(); + + // Show the notification form + chrome$('.ep_email_settings').slideDown(function() { + + chrome$('#ep_email_form_mysettings [name=ep_email]').val(goodEmail); + + chrome$('#ep_email_form_mysettings [name=ep_email_unsubscribe]').click(); + + // Is the correct gritter msg there + helper.waitFor(function() { + return chrome$(".gritter-item").is(':visible') == true; + }) + .done(function(){ + expect(chrome$(".emailNotificationsUnsubscrResponseBad").is(':visible')).to.be(true); + + done(); + }); + }); + }); + + // Fourth, test subscription with a good email + it("makes test subscription with an unregistered email address", function(done) { + var chrome$ = helper.padChrome$; + + //click on the settings button to make settings visible + var $settingsButton = chrome$(".buttonicon-settings"); + $settingsButton.click(); + + // Show the notification form + chrome$('.ep_email_settings').slideDown(function() { + + chrome$('#ep_email_form_mysettings [name=ep_email]').val(goodEmail); + chrome$('#ep_email_form_mysettings [name=ep_email_onStart]').prop('checked', true); + + chrome$('#ep_email_form_mysettings [name=ep_email_subscribe]').click(); + + // Is the correct gritter msg there + helper.waitFor(function() { + return chrome$(".gritter-item").is(':visible') == true; + }) + .done(function(){ + expect(chrome$(".emailNotificationsSubscrResponseGood").is(':visible')).to.be(true); + + done(); + }); + }); + }); +});