UX: Add groups/custom/new route for admins to create a new group.

This commit is contained in:
Guo Xiang Tan
2018-03-27 16:45:21 +08:00
parent 558914b986
commit 7edab1c0b9
18 changed files with 535 additions and 61 deletions
@@ -1,5 +1,7 @@
import { acceptance, logIn } from "helpers/qunit-helpers";
acceptance("Group");
const response = object => {
return [
200,
@@ -8,63 +10,6 @@ const response = object => {
];
};
acceptance("Groups", {
beforeEach() {
server.get('/groups/snorlax.json', () => { // eslint-disable-line no-undef
return response({"basic_group":{"id":41,"automatic":false,"name":"snorlax","user_count":1,"alias_level":0,"visible":true,"automatic_membership_email_domains":"","automatic_membership_retroactive":false,"primary_group":true,"title":"Team Snorlax","grant_trust_level":null,"incoming_email":null,"has_messages":false,"flair_url":"","flair_bg_color":"","flair_color":"","bio_raw":"","bio_cooked":null,"public":true,"is_group_user":true,"is_group_owner":true}});
});
// Workaround while awaiting https://github.com/tildeio/route-recognizer/issues/53
server.get('/groups/snorlax/logs.json', request => { // eslint-disable-line no-undef
if (request.queryParams["filters[action]"]) {
return response({"logs":[{"action":"change_group_setting","subject":"title","prev_value":null,"new_value":"Team Snorlax","created_at":"2016-12-12T08:27:46.408Z","acting_user":{"id":1,"username":"tgx","avatar_template":"/images/avatar.png"},"target_user":null}],"all_loaded":true});
} else {
return response({"logs":[{"action":"change_group_setting","subject":"title","prev_value":null,"new_value":"Team Snorlax","created_at":"2016-12-12T08:27:46.408Z","acting_user":{"id":1,"username":"tgx","avatar_template":"/images/avatar.png"},"target_user":null},{"action":"add_user_to_group","subject":null,"prev_value":null,"new_value":null,"created_at":"2016-12-12T08:27:27.725Z","acting_user":{"id":1,"username":"tgx","avatar_template":"/images/avatar.png"},"target_user":{"id":1,"username":"tgx","avatar_template":"/images/avatar.png"}}],"all_loaded":true});
}
});
}
});
QUnit.test("Browsing Groups", assert => {
visit("/groups");
andThen(() => {
assert.equal(count('.groups-table-row'), 2, 'it displays visible groups');
assert.equal(find('.group-index-join').length, 1, 'it shows button to join group');
assert.equal(find('.group-index-request').length, 1, 'it shows button to request for group membership');
});
click('.group-index-join');
andThen(() => {
assert.ok(exists('.modal.login-modal'), 'it shows the login modal');
});
click('.login-modal .close');
andThen(() => {
assert.ok(invisible('.modal.login-modal'), 'it closes the login modal');
});
click('.group-index-request');
andThen(() => {
assert.ok(exists('.modal.login-modal'), 'it shows the login modal');
});
click("a[href='/groups/discourse/members']");
andThen(() => {
assert.equal(find('.group-info-name').text().trim(), 'Awesome Team', "it displays the group page");
});
click('.group-index-join');
andThen(() => {
assert.ok(exists('.modal.login-modal'), 'it shows the login modal');
});
});
QUnit.test("Anonymous Viewing Group", assert => {
visit("/groups/discourse");
@@ -0,0 +1,43 @@
import { acceptance, logIn } from "helpers/qunit-helpers";
acceptance("Groups");
QUnit.test("Browsing Groups", assert => {
visit("/groups");
andThen(() => {
assert.equal(count('.groups-table-row'), 2, 'it displays visible groups');
assert.equal(find('.group-index-join').length, 1, 'it shows button to join group');
assert.equal(find('.group-index-request').length, 1, 'it shows button to request for group membership');
});
click('.group-index-join');
andThen(() => {
assert.ok(exists('.modal.login-modal'), 'it shows the login modal');
});
click('.login-modal .close');
andThen(() => {
assert.ok(invisible('.modal.login-modal'), 'it closes the login modal');
});
click('.group-index-request');
andThen(() => {
assert.ok(exists('.modal.login-modal'), 'it shows the login modal');
});
click("a[href='/groups/discourse/members']");
andThen(() => {
assert.equal(find('.group-info-name').text().trim(), 'Awesome Team', "it displays the group page");
});
click('.group-index-join');
andThen(() => {
assert.ok(exists('.modal.login-modal'), 'it shows the login modal');
});
});
@@ -0,0 +1,72 @@
import { acceptance, logIn } from "helpers/qunit-helpers";
acceptance("New Group");
QUnit.test("As an anon user", assert => {
visit("/groups");
andThen(() => {
assert.equal(
find('.groups-admin-dropdown').length, 0,
'it should not display the admin dropdown'
);
});
});
QUnit.test("Creating a new group", assert => {
logIn();
Discourse.reset();
visit("/groups");
selectKit('.groups-admin-dropdown').expand().selectRowByValue("new");
fillIn("input[name='name']", '1');
andThen(() => {
assert.equal(
find('.tip.bad').text().trim(), I18n.t("groups.new.name.too_short"),
'it should show the right validation tooltip'
);
assert.ok(
find("button[title='Create']:disabled").length === 1,
'it should disable the save button'
);
});
fillIn("input[name='name']", 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
andThen(() => {
assert.equal(
find('.tip.bad').text().trim(), I18n.t("groups.new.name.too_long"),
'it should show the right validation tooltip'
);
});
fillIn("input[name='name']", '');
andThen(() => {
assert.equal(
find('.tip.bad').text().trim(), I18n.t("groups.new.name.blank"),
'it should show the right validation tooltip'
);
});
fillIn("input[name='name']", 'goodusername');
andThen(() => {
assert.equal(
find('.tip.good').text().trim(), I18n.t("groups.new.name.available"),
'it should show the right validation tooltip'
);
});
click(".groups-new-public-admission");
andThen(() => {
assert.equal(
find('groups-new-allow-membership-requests').length, 0,
'it should disable the membership requests checkbox'
);
});
});