From 67cd08af9bac6e0376ff66ab60fde77af7c03073 Mon Sep 17 00:00:00 2001 From: cpradio Date: Sun, 3 Apr 2016 20:26:42 -0400 Subject: [PATCH] Add qunit tests --- test/javascripts/controllers/flag-test.js.es6 | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/javascripts/controllers/flag-test.js.es6 b/test/javascripts/controllers/flag-test.js.es6 index ebff4fd1d..4d4775065 100644 --- a/test/javascripts/controllers/flag-test.js.es6 +++ b/test/javascripts/controllers/flag-test.js.es6 @@ -64,3 +64,37 @@ test("canDeleteSpammer spam selected", function(){ flagController.set('userDetails', buildAdminUser({can_delete_all_posts: false, can_be_deleted: false})); canDeleteSpammer(flagController, 'spam', false, 'false if current user is staff, selected is spam, user cannot be deleted'); }); + +test("canSendWarning not staff", function(){ + const store = createStore(); + + var flagController = this.subject({ model: buildPost() }); + sandbox.stub(Discourse.User, 'currentProp').withArgs('staff').returns(false); + + const notifyUserFlag = store.createRecord('post-action-type', {name_key: 'notify_user'}); + flagController.set('selected', notifyUserFlag); + equal(flagController.get('canSendWarning'), false, 'false if current user is not staff'); +}); + +var canSendWarning = function(flagController, postActionType, expected, testName) { + const store = createStore(); + const flag = store.createRecord('post-action-type', {name_key: postActionType}); + flagController.set('selected', flag); + + equal(flagController.get('canSendWarning'), expected, testName); +}; + +test("canSendWarning notify_user not selected", function(){ + sandbox.stub(Discourse.User, 'currentProp').withArgs('staff').returns(true); + var flagController = this.subject({ model: buildPost() }); + canSendWarning(flagController, 'off_topic', false, 'false if current user is staff, but selected is off_topic'); + canSendWarning(flagController, 'inappropriate', false, 'false if current user is staff, but selected is inappropriate'); + canSendWarning(flagController, 'spam', false, 'false if current user is staff, but selected is spam'); + canSendWarning(flagController, 'notify_moderators', false, 'false if current user is staff, but selected is notify_moderators'); +}); + +test("canSendWarning notify_user selected", function(){ + sandbox.stub(Discourse.User, 'currentProp').withArgs('staff').returns(true); + var flagController = this.subject({ model: buildPost() }); + canSendWarning(flagController, 'notify_user', true, 'true if current user is staff, selected is notify_user'); +}); \ No newline at end of file