123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351 |
- import assert from 'assert';
- import { getPageTitle, getTitle, getModerationActions } from 'misago/components/threads/utils';
- import misago from 'misago/index';
- describe("Threads List Title Utils", function() {
- beforeEach(function() {
- // set default title
- misago._context = {
- CATEGORIES_ON_INDEX: false,
- SETTINGS: {
- forum_index_title: "",
- forum_name: "Test forum"
- }
- };
- });
- it("getPageTitle returns valid obj for title service", function() {
- assert.deepEqual(getPageTitle({
- list: {
- longName: "",
- path: ''
- },
- category: {
- name: "Test category"
- }
- }), {
- title: "Test category"
- }, "nonspecial category's name is returned");
- assert.deepEqual(getPageTitle({
- list: {
- longName: "New threads",
- path: 'new/'
- },
- category: {
- name: "Test category"
- }
- }), {
- title: "New threads",
- parent: "Test category"
- }, "list name under category name is returned");
- assert.equal(getPageTitle({
- list: {
- longName: "Threads",
- path: ''
- },
- category: {
- name: "Root",
- special_role: true
- }
- }), null, "null is returned for special category");
- assert.deepEqual(getPageTitle({
- list: {
- longName: "New threads",
- path: 'new/'
- },
- category: {
- name: "Root",
- special_role: true
- }
- }), {
- title: "New threads"
- }, "list name is returned for special category");
- misago._context.CATEGORIES_ON_INDEX = true;
- assert.deepEqual(getPageTitle({
- list: {
- longName: "",
- path: ''
- },
- category: {
- name: "Root",
- special_role: true
- }
- }), {
- title: "Threads"
- }, "fallback title is returned for special category");
- assert.deepEqual(getPageTitle({
- list: {
- longName: "New threads",
- path: 'new/'
- },
- category: {
- name: "Root",
- special_role: true
- }
- }), {
- title: "New threads",
- parent: "Threads"
- }, "list title under fallback is returned for special category");
- });
- it("getTitle returns valid title for header", function() {
- assert.equal(getTitle({
- category: {
- name: "Test category"
- }
- }), "Test category", "nonspecial category's name is returned as title");
- assert.equal(getTitle({
- category: {
- name: "Root",
- special_role: true
- }
- }), "Test forum", "forum name was used for title instead of category's");
- misago._context.SETTINGS.forum_index_title = "Forum index";
- assert.equal(getTitle({
- category: {
- name: "Root",
- special_role: true
- }
- }), "Forum index", "index title was used for title instead of category's");
- misago._context.CATEGORIES_ON_INDEX = true;
- assert.equal(getTitle({
- category: {
- name: "Root",
- special_role: true
- }
- }), "Threads", "fallback title was used for forum threads list");
- });
- });
- describe("Threads List Moderation Actions Util", function() {
- it("shows no moderation for no threads", function() {
- const moderationActions = getModerationActions([]);
- assert.ok(!moderationActions.allow, "moderation is unavaiable");
- });
- it("shows no moderation for unmoderable threads", function() {
- const moderationActions = getModerationActions([
- {
- acl: {
- can_approve: false,
- can_close: false,
- can_hide: false,
- can_merge: false,
- can_move: false,
- can_pin: false
- },
- is_unapproved: false
- }
- ]);
- assert.ok(!moderationActions.allow, "moderation is unavaiable");
- });
- it("shows moderation for unapproved approvable thread", function() {
- const moderationActions = getModerationActions([
- {
- acl: {
- can_approve: true,
- can_close: false,
- can_hide: false,
- can_merge: false,
- can_move: false,
- can_pin: false
- },
- is_unapproved: true
- }
- ]);
- assert.ok(moderationActions.allow, "moderation is allowed");
- assert.ok(moderationActions.can_approve, "approve action is available");
- });
- it("shows no moderation for approved approvable thread", function() {
- const moderationActions = getModerationActions([
- {
- acl: {
- can_approve: true,
- can_close: false,
- can_hide: false,
- can_merge: false,
- can_move: false,
- can_pin: false
- },
- is_unapproved: false
- }
- ]);
- assert.ok(!moderationActions.allow, "moderation is unavaiable");
- assert.ok(!moderationActions.can_approve, "approve action is unavaiable");
- });
- it("shows moderation for closing thread", function() {
- const moderationActions = getModerationActions([
- {
- acl: {
- can_approve: false,
- can_close: true,
- can_hide: false,
- can_merge: false,
- can_move: false,
- can_pin: false
- },
- is_unapproved: false
- }
- ]);
- assert.ok(moderationActions.allow, "moderation is allowed");
- assert.ok(moderationActions.can_close, "close action is available");
- });
- it("shows moderation for hiding thread", function() {
- const moderationActions = getModerationActions([
- {
- acl: {
- can_approve: false,
- can_close: false,
- can_hide: 1,
- can_merge: false,
- can_move: false,
- can_pin: false
- },
- is_unapproved: false
- }
- ]);
- assert.ok(moderationActions.allow, "moderation is allowed");
- assert.equal(moderationActions.can_hide, 1, "delete action is available");
- });
- it("shows moderation for deleting thread", function() {
- const moderationActions = getModerationActions([
- {
- acl: {
- can_approve: false,
- can_close: false,
- can_hide: 2,
- can_merge: false,
- can_move: false,
- can_pin: false
- },
- is_unapproved: false
- }
- ]);
- assert.ok(moderationActions.allow, "moderation is allowed");
- assert.equal(moderationActions.can_hide, 2, "delete action is available");
- });
- it("shows moderation for mergin thread", function() {
- const moderationActions = getModerationActions([
- {
- acl: {
- can_approve: false,
- can_close: false,
- can_hide: false,
- can_merge: true,
- can_move: false,
- can_pin: false
- },
- is_unapproved: false
- }
- ]);
- assert.ok(moderationActions.allow, "moderation is allowed");
- assert.ok(moderationActions.can_merge, "merge action is available");
- });
- it("shows moderation for moving thread", function() {
- const moderationActions = getModerationActions([
- {
- acl: {
- can_approve: false,
- can_close: false,
- can_hide: false,
- can_merge: false,
- can_move: true,
- can_pin: false
- },
- is_unapproved: false
- }
- ]);
- assert.ok(moderationActions.allow, "moderation is allowed");
- assert.ok(moderationActions.can_move, "move action is available");
- });
- it("shows moderation for pinning thread", function() {
- const moderationActions = getModerationActions([
- {
- acl: {
- can_approve: false,
- can_close: false,
- can_hide: false,
- can_merge: false,
- can_move: false,
- can_pin: 1
- },
- is_unapproved: false
- }
- ]);
- assert.ok(moderationActions.allow, "moderation is allowed");
- assert.equal(moderationActions.can_pin, 1, "pin action is available");
- });
- it("shows moderation for pinning thread globally", function() {
- const moderationActions = getModerationActions([
- {
- acl: {
- can_approve: false,
- can_close: false,
- can_hide: false,
- can_merge: false,
- can_move: false,
- can_pin: 2
- },
- is_unapproved: false
- }
- ]);
- assert.ok(moderationActions.allow, "moderation is allowed");
- assert.equal(moderationActions.can_pin, 2, "pin action is available");
- });
- it("shows moderation kitchensink", function() {
- const moderationActions = getModerationActions([
- {
- acl: {
- can_approve: true,
- can_close: true,
- can_hide: 2,
- can_merge: true,
- can_move: true,
- can_pin: 2
- },
- is_unapproved: true
- }
- ]);
- assert.deepEqual(moderationActions, {
- allow: true,
- can_approve: true,
- can_close: true,
- can_hide: 2,
- can_merge: true,
- can_move: true,
- can_pin: 2
- }, "moderation is allowed");
- });
- });
|