mattermost-mobile/app/mm-redux/utils/group_utils.test.js
Hossein Ahmadian-Yazdi b6eb3b9349
[MM-23158] Group Mentions & Invites - Display group mentions in suggestions list in the main channel textbox (#4118)
* groups in group mention

* fix sorting issues

* address PR comments

* fix tests

* Update groups.ts

* fix nock

* fix translations

* Adding test

* fix linting

* update redux functions

* Add license check

* adddress PR comments

* remove lodash import

* fix lint problems

* revert package.json changes

* Address PR comments

* address PR comments

* fix naming

* address PR comments

* address PR comments

* Address comments found in second PR

* getAllGroups updated

* address PR comments

* Update app/mm-redux/utils/group_utils.ts

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>

* revert change

* remove unneeded actions

* Use correct server version

* MM-26631: Fix order of group displaying

* MM-26633: Fix group mentions not showing up in group constrained team

* MM-26636: Group mentions not updating when role updates

* MM-26637: Group name not updating right away

* Address PR comments

* TRY AND catch

* address PR comments

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
2020-07-08 07:31:58 -04:00

92 lines
No EOL
3 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import assert from 'assert';
import {
filterGroupsMatchingTerm,
} from './group_utils';
describe('group utils', () => {
describe('filterGroupsMatchingTerm', () => {
const groupA = {
id: 'groupid1',
name: 'board-group',
description: 'group1 description',
display_name: 'board-group',
type: 'ldap',
remote_id: 'group1',
create_at: 1,
update_at: 2,
delete_at: 0,
has_syncables: true,
member_count: 3,
scheme_admin: false,
allow_reference: true,
};
const groupB = {
id: 'groupid2',
name: 'developers-group',
description: 'group2 description',
display_name: 'developers-group',
type: 'ldap',
remote_id: 'group2',
create_at: 1,
update_at: 2,
delete_at: 0,
has_syncables: true,
member_count: 3,
scheme_admin: false,
allow_reference: true,
};
const groupC = {
id: 'groupid3',
name: 'software-engineers',
description: 'group3 description',
display_name: 'software engineers',
type: 'ldap',
remote_id: 'group3',
create_at: 1,
update_at: 2,
delete_at: 0,
has_syncables: true,
member_count: 3,
scheme_admin: false,
allow_reference: true,
};
const groups = [groupA, groupB, groupC];
it('should match all for empty filter', () => {
assert.deepEqual(filterGroupsMatchingTerm(groups, ''), [groupA, groupB, groupC]);
});
it('should filter out results which do not match', () => {
assert.deepEqual(filterGroupsMatchingTerm(groups, 'testBad'), []);
});
it('should match by name', () => {
assert.deepEqual(filterGroupsMatchingTerm(groups, 'software-engineers'), [groupC]);
});
it('should match by split part of the name', () => {
assert.deepEqual(filterGroupsMatchingTerm(groups, 'group'), [groupA, groupB]);
assert.deepEqual(filterGroupsMatchingTerm(groups, 'board'), [groupA]);
});
it('should match by display_name fully', () => {
assert.deepEqual(filterGroupsMatchingTerm(groups, 'software engineers'), [groupC]);
});
it('should match by display_name case-insensitive', () => {
assert.deepEqual(filterGroupsMatchingTerm(groups, 'software ENGINEERS'), [groupC]);
});
it('should ignore leading @ for name', () => {
assert.deepEqual(filterGroupsMatchingTerm(groups, '@developers'), [groupB]);
});
it('should ignore leading @ for display_name', () => {
assert.deepEqual(filterGroupsMatchingTerm(groups, '@software'), [groupC]);
});
});
});