Upgrade QUnit to latest version

This commit is contained in:
Robin Ward
2017-06-14 13:57:58 -04:00
parent 8ae445766f
commit cc525b1a8d
145 changed files with 7569 additions and 6763 deletions
@@ -1,33 +1,35 @@
moduleFor("controller:admin-group");
moduleFor("controller:admin-group", {
needs: ['controller:adminGroupsType']
});
test("disablePublicSetting", function() {
QUnit.test("disablePublicSetting", function(assert) {
this.subject().setProperties({
model: { visible: false, allow_membership_requests: false }
});
equal(this.subject().get("disablePublicSetting"), true, "it should disable setting");
assert.equal(this.subject().get("disablePublicSetting"), true, "it should disable setting");
this.subject().set("model.visible", true);
equal(this.subject().get("disablePublicSetting"), false, "it should enable setting");
assert.equal(this.subject().get("disablePublicSetting"), false, "it should enable setting");
this.subject().set("model.allow_membership_requests", true);
equal(this.subject().get("disablePublicSetting"), true, "it should disable setting");
assert.equal(this.subject().get("disablePublicSetting"), true, "it should disable setting");
});
test("disableMembershipRequestSetting", function() {
QUnit.test("disableMembershipRequestSetting", function(assert) {
this.subject().setProperties({
model: { visible: false, public: false, canEveryoneMention: true }
});
equal(this.subject().get("disableMembershipRequestSetting"), true, "it should disable setting");
assert.equal(this.subject().get("disableMembershipRequestSetting"), true, "it should disable setting");
this.subject().set("model.visible", true);
equal(this.subject().get("disableMembershipRequestSetting"), false, "it should enable setting");
assert.equal(this.subject().get("disableMembershipRequestSetting"), false, "it should enable setting");
this.subject().set("model.public", true);
equal(this.subject().get("disableMembershipRequestSetting"), true, "it should disalbe setting");
assert.equal(this.subject().get("disableMembershipRequestSetting"), true, "it should disalbe setting");
});
@@ -1,13 +1,13 @@
import { mapRoutes } from 'discourse/mapping-router';
moduleFor("controller:avatar-selector", "controller:avatar-selector", {
setup() {
beforeEach() {
this.registry.register('router:main', mapRoutes());
},
needs: ['controller:modal']
});
test("avatarTemplate", function() {
QUnit.test("avatarTemplate", function(assert) {
const avatarSelectorController = this.subject();
avatarSelectorController.setProperties({
@@ -17,11 +17,11 @@ test("avatarTemplate", function() {
custom_avatar_upload_id: 3
});
equal(avatarSelectorController.get("selectedUploadId"), 1, "we are using system by default");
assert.equal(avatarSelectorController.get("selectedUploadId"), 1, "we are using system by default");
avatarSelectorController.set('selected', 'gravatar');
equal(avatarSelectorController.get("selectedUploadId"), 2, "we are using gravatar when set");
assert.equal(avatarSelectorController.get("selectedUploadId"), 2, "we are using gravatar when set");
avatarSelectorController.set("selected", "custom");
equal(avatarSelectorController.get("selectedUploadId"), 3, "we are using custom when set");
assert.equal(avatarSelectorController.get("selectedUploadId"), 3, "we are using custom when set");
});
@@ -1,20 +1,20 @@
import { mapRoutes } from 'discourse/mapping-router';
moduleFor("controller:create-account", "controller:create-account", {
setup() {
beforeEach() {
this.registry.register('router:main', mapRoutes());
},
needs: ['controller:modal', 'controller:login']
});
test('basicUsernameValidation', function() {
QUnit.test('basicUsernameValidation', function(assert) {
var subject = this.subject;
var testInvalidUsername = function(username, expectedReason) {
var controller = subject({ siteSettings: Discourse.SiteSettings });
controller.set('accountUsername', username);
equal(controller.get('basicUsernameValidation.failed'), true, 'username should be invalid: ' + username);
equal(controller.get('basicUsernameValidation.reason'), expectedReason, 'username validation reason: ' + username + ', ' + expectedReason);
assert.equal(controller.get('basicUsernameValidation.failed'), true, 'username should be invalid: ' + username);
assert.equal(controller.get('basicUsernameValidation.reason'), expectedReason, 'username validation reason: ' + username + ', ' + expectedReason);
};
testInvalidUsername('', undefined);
@@ -24,11 +24,11 @@ test('basicUsernameValidation', function() {
var controller = subject({ siteSettings: Discourse.SiteSettings });
controller.set('accountUsername', 'porkchops');
controller.set('prefilledUsername', 'porkchops');
equal(controller.get('basicUsernameValidation.ok'), true, 'Prefilled username is valid');
equal(controller.get('basicUsernameValidation.reason'), I18n.t('user.username.prefilled'), 'Prefilled username is valid');
assert.equal(controller.get('basicUsernameValidation.ok'), true, 'Prefilled username is valid');
assert.equal(controller.get('basicUsernameValidation.reason'), I18n.t('user.username.prefilled'), 'Prefilled username is valid');
});
test('passwordValidation', function() {
QUnit.test('passwordValidation', function(assert) {
var subject = this.subject;
var controller = subject({ siteSettings: Discourse.SiteSettings });
@@ -38,14 +38,14 @@ test('passwordValidation', function() {
controller.set('prefilledUsername', 'porkchops');
controller.set('accountPassword', 'b4fcdae11f9167');
equal(controller.get('passwordValidation.ok'), true, 'Password is ok');
equal(controller.get('passwordValidation.reason'), I18n.t('user.password.ok'), 'Password is valid');
assert.equal(controller.get('passwordValidation.ok'), true, 'Password is ok');
assert.equal(controller.get('passwordValidation.reason'), I18n.t('user.password.ok'), 'Password is valid');
var testInvalidPassword = function(password, expectedReason) {
var c = subject({ siteSettings: Discourse.SiteSettings });
c.set('accountPassword', password);
equal(c.get('passwordValidation.failed'), true, 'password should be invalid: ' + password);
equal(c.get('passwordValidation.reason'), expectedReason, 'password validation reason: ' + password + ', ' + expectedReason);
assert.equal(c.get('passwordValidation.failed'), true, 'password should be invalid: ' + password);
assert.equal(c.get('passwordValidation.reason'), expectedReason, 'password validation reason: ' + password + ', ' + expectedReason);
};
testInvalidPassword('', undefined);
+26 -26
View File
@@ -18,13 +18,13 @@ var buildAdminUser = function(args) {
};
moduleFor("controller:flag", "controller:flag", {
setup() {
beforeEach() {
this.registry.register('router:main', mapRoutes());
},
needs: ['controller:modal']
});
test("canDeleteSpammer not staff", function(){
QUnit.test("canDeleteSpammer not staff", function(assert) {
const store = createStore();
var flagController = this.subject({ model: buildPost() });
@@ -32,44 +32,44 @@ test("canDeleteSpammer not staff", function(){
const spamFlag = store.createRecord('post-action-type', {name_key: 'spam'});
flagController.set('selected', spamFlag);
equal(flagController.get('canDeleteSpammer'), false, 'false if current user is not staff');
assert.equal(flagController.get('canDeleteSpammer'), false, 'false if current user is not staff');
});
var canDeleteSpammer = function(flagController, postActionType, expected, testName) {
var canDeleteSpammer = function(assert, flagController, postActionType, expected, testName) {
const store = createStore();
const flag = store.createRecord('post-action-type', {name_key: postActionType});
flagController.set('selected', flag);
equal(flagController.get('canDeleteSpammer'), expected, testName);
assert.equal(flagController.get('canDeleteSpammer'), expected, testName);
};
test("canDeleteSpammer spam not selected", function(){
QUnit.test("canDeleteSpammer spam not selected", function(assert) {
sandbox.stub(Discourse.User, 'currentProp').withArgs('staff').returns(true);
var flagController = this.subject({ model: buildPost() });
flagController.set('userDetails', buildAdminUser({can_delete_all_posts: true, can_be_deleted: true}));
canDeleteSpammer(flagController, 'off_topic', false, 'false if current user is staff, but selected is off_topic');
canDeleteSpammer(flagController, 'inappropriate', false, 'false if current user is staff, but selected is inappropriate');
canDeleteSpammer(flagController, 'notify_user', false, 'false if current user is staff, but selected is notify_user');
canDeleteSpammer(flagController, 'notify_moderators', false, 'false if current user is staff, but selected is notify_moderators');
canDeleteSpammer(assert, flagController, 'off_topic', false, 'false if current user is staff, but selected is off_topic');
canDeleteSpammer(assert, flagController, 'inappropriate', false, 'false if current user is staff, but selected is inappropriate');
canDeleteSpammer(assert, flagController, 'notify_user', false, 'false if current user is staff, but selected is notify_user');
canDeleteSpammer(assert, flagController, 'notify_moderators', false, 'false if current user is staff, but selected is notify_moderators');
});
test("canDeleteSpammer spam selected", function(){
QUnit.test("canDeleteSpammer spam selected", function(assert) {
sandbox.stub(Discourse.User, 'currentProp').withArgs('staff').returns(true);
var flagController = this.subject({ model: buildPost() });
flagController.set('userDetails', buildAdminUser({can_delete_all_posts: true, can_be_deleted: true}));
canDeleteSpammer(flagController, 'spam', true, 'true if current user is staff, selected is spam, posts and user can be deleted');
canDeleteSpammer(assert, flagController, 'spam', true, 'true if current user is staff, selected is spam, posts and user can be deleted');
flagController.set('userDetails', buildAdminUser({can_delete_all_posts: false, can_be_deleted: true}));
canDeleteSpammer(flagController, 'spam', false, 'false if current user is staff, selected is spam, posts cannot be deleted');
canDeleteSpammer(assert, flagController, 'spam', false, 'false if current user is staff, selected is spam, posts cannot be deleted');
flagController.set('userDetails', buildAdminUser({can_delete_all_posts: true, can_be_deleted: false}));
canDeleteSpammer(flagController, 'spam', false, 'false if current user is staff, selected is spam, user cannot be deleted');
canDeleteSpammer(assert, flagController, 'spam', false, 'false if current user is staff, selected is spam, user cannot be deleted');
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');
canDeleteSpammer(assert, flagController, 'spam', false, 'false if current user is staff, selected is spam, user cannot be deleted');
});
test("canSendWarning not staff", function(){
QUnit.test("canSendWarning not staff", function(assert) {
const store = createStore();
var flagController = this.subject({ model: buildPost() });
@@ -77,28 +77,28 @@ test("canSendWarning not staff", function(){
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');
assert.equal(flagController.get('canSendWarning'), false, 'false if current user is not staff');
});
var canSendWarning = function(flagController, postActionType, expected, testName) {
var canSendWarning = function(assert, 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);
assert.equal(flagController.get('canSendWarning'), expected, testName);
};
test("canSendWarning notify_user not selected", function(){
QUnit.test("canSendWarning notify_user not selected", function(assert) {
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');
canSendWarning(assert, flagController, 'off_topic', false, 'false if current user is staff, but selected is off_topic');
canSendWarning(assert, flagController, 'inappropriate', false, 'false if current user is staff, but selected is inappropriate');
canSendWarning(assert, flagController, 'spam', false, 'false if current user is staff, but selected is spam');
canSendWarning(assert, flagController, 'notify_moderators', false, 'false if current user is staff, but selected is notify_moderators');
});
test("canSendWarning notify_user selected", function(){
QUnit.test("canSendWarning notify_user selected", function(assert) {
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');
canSendWarning(assert, flagController, 'notify_user', true, 'true if current user is staff, selected is notify_user');
});
@@ -1,19 +1,21 @@
moduleFor("controller:group");
moduleFor("controller:group", {
needs: ['controller:application']
});
test("canEditGroup", function() {
QUnit.test("canEditGroup", function(assert) {
const GroupController = this.subject();
GroupController.setProperties({
model: { is_group_owner: true, automatic: true }
});
equal(GroupController.get("canEditGroup"), false, "automatic groups cannot be edited");
assert.equal(GroupController.get("canEditGroup"), false, "automatic groups cannot be edited");
GroupController.set("model.automatic", false);
equal(GroupController.get("canEditGroup"), true, "owners can edit groups");
assert.equal(GroupController.get("canEditGroup"), true, "owners can edit groups");
GroupController.set("model.is_group_owner", false);
equal(GroupController.get("canEditGroup"), false, "normal users cannot edit groups");
assert.equal(GroupController.get("canEditGroup"), false, "normal users cannot edit groups");
});
@@ -1,27 +1,27 @@
moduleFor("controller:history");
test("displayEdit", function() {
QUnit.test("displayEdit", function(assert) {
const HistoryController = this.subject();
HistoryController.setProperties({
model: { last_revision: 3, current_revision: 3, can_edit: false }
});
equal(
assert.equal(
HistoryController.get("displayEdit"), false,
"it should not display edit button when user cannot edit the post"
);
HistoryController.set("model.can_edit", true);
equal(
assert.equal(
HistoryController.get("displayEdit"), true,
"it should display edit button when user can edit the post"
);
HistoryController.set("model.current_revision", 2);
equal(
assert.equal(
HistoryController.get("displayEdit"), false,
"it should only display the edit button on the latest revision"
);
+36 -38
View File
@@ -1,9 +1,8 @@
import { blank, present } from 'helpers/qunit-helpers';
import { mapRoutes } from 'discourse/mapping-router';
moduleFor('controller:topic', 'controller:topic', {
needs: ['controller:modal', 'controller:composer', 'controller:application'],
setup() {
beforeEach() {
this.registry.register('router:main', mapRoutes());
},
});
@@ -23,27 +22,27 @@ var buildTopic = function() {
};
test("editingMode", function() {
QUnit.test("editingMode", function(assert) {
var topic = buildTopic(),
topicController = this.subject({model: topic});
ok(!topicController.get('editingTopic'), "we are not editing by default");
assert.ok(!topicController.get('editingTopic'), "we are not editing by default");
topicController.set('model.details.can_edit', false);
topicController.send('editTopic');
ok(!topicController.get('editingTopic'), "calling editTopic doesn't enable editing unless the user can edit");
assert.ok(!topicController.get('editingTopic'), "calling editTopic doesn't enable editing unless the user can edit");
topicController.set('model.details.can_edit', true);
topicController.send('editTopic');
ok(topicController.get('editingTopic'), "calling editTopic enables editing if the user can edit");
equal(topicController.get('buffered.title'), topic.get('title'));
equal(topicController.get('buffered.category_id'), topic.get('category_id'));
assert.ok(topicController.get('editingTopic'), "calling editTopic enables editing if the user can edit");
assert.equal(topicController.get('buffered.title'), topic.get('title'));
assert.equal(topicController.get('buffered.category_id'), topic.get('category_id'));
topicController.send('cancelEditingTopic');
ok(!topicController.get('editingTopic'), "cancelling edit mode reverts the property value");
assert.ok(!topicController.get('editingTopic'), "cancelling edit mode reverts the property value");
});
test("toggledSelectedPost", function() {
QUnit.test("toggledSelectedPost", function(assert) {
var tc = this.subject({ model: buildTopic() }),
post = Discourse.Post.create({id: 123, post_number: 2}),
postStream = tc.get('model.postStream');
@@ -51,38 +50,38 @@ test("toggledSelectedPost", function() {
postStream.appendPost(post);
postStream.appendPost(Discourse.Post.create({id: 124, post_number: 3}));
blank(tc.get('selectedPosts'), "there are no selected posts by default");
equal(tc.get('selectedPostsCount'), 0, "there is a selected post count of 0");
ok(!tc.postSelected(post), "the post is not selected by default");
assert.blank(tc.get('selectedPosts'), "there are no selected posts by default");
assert.equal(tc.get('selectedPostsCount'), 0, "there is a selected post count of 0");
assert.ok(!tc.postSelected(post), "the post is not selected by default");
tc.send('toggledSelectedPost', post);
present(tc.get('selectedPosts'), "there is a selectedPosts collection");
equal(tc.get('selectedPostsCount'), 1, "there is a selected post now");
ok(tc.postSelected(post), "the post is now selected");
assert.present(tc.get('selectedPosts'), "there is a selectedPosts collection");
assert.equal(tc.get('selectedPostsCount'), 1, "there is a selected post now");
assert.ok(tc.postSelected(post), "the post is now selected");
tc.send('toggledSelectedPost', post);
ok(!tc.postSelected(post), "the post is no longer selected");
assert.ok(!tc.postSelected(post), "the post is no longer selected");
});
test("selectAll", function() {
QUnit.test("selectAll", function(assert) {
var tc = this.subject({model: buildTopic(), appEvents: AppEvents.create()}),
post = Discourse.Post.create({id: 123, post_number: 2}),
postStream = tc.get('model.postStream');
postStream.appendPost(post);
ok(!tc.postSelected(post), "the post is not selected by default");
assert.ok(!tc.postSelected(post), "the post is not selected by default");
tc.send('selectAll');
ok(tc.postSelected(post), "the post is now selected");
ok(tc.get('allPostsSelected'), "all posts are selected");
assert.ok(tc.postSelected(post), "the post is now selected");
assert.ok(tc.get('allPostsSelected'), "all posts are selected");
tc.send('deselectAll');
ok(!tc.postSelected(post), "the post is deselected again");
ok(!tc.get('allPostsSelected'), "all posts are not selected");
assert.ok(!tc.postSelected(post), "the post is deselected again");
assert.ok(!tc.get('allPostsSelected'), "all posts are not selected");
});
test("Automating setting of allPostsSelected", function() {
QUnit.test("Automating setting of allPostsSelected", function(assert) {
var topic = buildTopic(),
tc = this.subject({model: topic}),
post = Discourse.Post.create({id: 123, post_number: 2}),
@@ -90,39 +89,38 @@ test("Automating setting of allPostsSelected", function() {
topic.set('posts_count', 1);
postStream.appendPost(post);
ok(!tc.get('allPostsSelected'), "all posts are not selected by default");
assert.ok(!tc.get('allPostsSelected'), "all posts are not selected by default");
tc.send('toggledSelectedPost', post);
ok(tc.get('allPostsSelected'), "all posts are selected if we select the only post");
assert.ok(tc.get('allPostsSelected'), "all posts are selected if we select the only post");
tc.send('toggledSelectedPost', post);
ok(!tc.get('allPostsSelected'), "the posts are no longer automatically selected");
assert.ok(!tc.get('allPostsSelected'), "the posts are no longer automatically selected");
});
test("Select Replies when present", function() {
QUnit.test("Select Replies when present", function(assert) {
var topic = buildTopic(),
tc = this.subject({ model: topic, appEvents: AppEvents.create() }),
p1 = Discourse.Post.create({id: 1, post_number: 1, reply_count: 1}),
p2 = Discourse.Post.create({id: 2, post_number: 2}),
p3 = Discourse.Post.create({id: 2, post_number: 3, reply_to_post_number: 1});
ok(!tc.postSelected(p3), "replies are not selected by default");
assert.ok(!tc.postSelected(p3), "replies are not selected by default");
tc.send('toggledSelectedPostReplies', p1);
ok(tc.postSelected(p1), "it selects the post");
ok(!tc.postSelected(p2), "it doesn't select a post that's not a reply");
ok(tc.postSelected(p3), "it selects a post that is a reply");
equal(tc.get('selectedPostsCount'), 2, "it has a selected posts count of two");
assert.ok(tc.postSelected(p1), "it selects the post");
assert.ok(!tc.postSelected(p2), "it doesn't select a post that's not a reply");
assert.ok(tc.postSelected(p3), "it selects a post that is a reply");
assert.equal(tc.get('selectedPostsCount'), 2, "it has a selected posts count of two");
// If we deselected the post whose replies are selected...
tc.send('toggledSelectedPost', p1);
ok(!tc.postSelected(p1), "it deselects the post");
ok(!tc.postSelected(p3), "it deselects the replies too");
assert.ok(!tc.postSelected(p1), "it deselects the post");
assert.ok(!tc.postSelected(p3), "it deselects the replies too");
// If we deselect a reply, it should deselect the parent's replies selected attribute. Weird but what else would make sense?
tc.send('toggledSelectedPostReplies', p1);
tc.send('toggledSelectedPost', p3);
ok(tc.postSelected(p1), "the post stays selected");
ok(!tc.postSelected(p3), "it deselects the replies too");
assert.ok(tc.postSelected(p1), "the post stays selected");
assert.ok(!tc.postSelected(p3), "it deselects the replies too");
});