mattermost-mobile/app/mm-redux/selectors/entities/groups.test.js
Miguel Alatzar 2d81b497cf [MM-23520] Port mattermost-redux (#4088)
* Remove mattermost-redux

* Move mm-redux files into app/redux

* Add @redux path to tsconfig.json

* Fix imports

* Install missing dependencies

* Fix tsc errors

* Fix i18n_utils test

* Fix more imports

* Remove redux websocket

* Fix tests

* Rename @redux

* Apply changes from mattermost-redux PR 1103

* Remove mattermost-redux mention in template

* Add missing imports

* Rename app/redux/ to app/mm-redux/

* Remove test file

* Fix fetching Sidebar GM profiles

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
2020-04-17 21:12:09 -07:00

117 lines
5 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import assert from 'assert';
import deepFreezeAndThrowOnMutation from '@mm-redux/utils/deep_freeze';
import * as Selectors from '@mm-redux/selectors/entities/groups';
describe('Selectors.Groups', () => {
const teamID = 'c6ubwm63apgftbjs71enbjjpsh';
const expectedAssociatedGroupID1 = 'xh585kyz3tn55q6ipfo57btwnc';
const expectedAssociatedGroupID2 = 'emdwu98u6jg9xfn9p5zu48bojo';
const teamAssociatedGroupIDs = [expectedAssociatedGroupID1, expectedAssociatedGroupID2];
const channelID = 'c6ubwm63apgftbjs71enbjjpzz';
const expectedAssociatedGroupID3 = 'xos794c6tfb57eog481acokozc';
const expectedAssociatedGroupID4 = 'tnd8zod9f3fdtqosxjmhwucbth';
const channelAssociatedGroupIDs = [expectedAssociatedGroupID3, expectedAssociatedGroupID4];
const testState = deepFreezeAndThrowOnMutation({
entities: {
groups: {
syncables: {},
members: {},
groups: {
[expectedAssociatedGroupID1]: {
id: expectedAssociatedGroupID1,
name: '9uobsi3xb3y5tfjb3ze7umnh1o',
display_name: 'abc',
description: '',
source: 'ldap',
remote_id: 'abc',
create_at: 1553808969975,
update_at: 1553808969975,
delete_at: 0,
has_syncables: false,
member_count: 2,
},
[expectedAssociatedGroupID3]: {
id: expectedAssociatedGroupID3,
name: '5mte953ncbfpunpr3zmtopiwbo',
display_name: 'developers',
description: '',
source: 'ldap',
remote_id: 'developers',
create_at: 1553808970570,
update_at: 1553808970570,
delete_at: 0,
has_syncables: false,
member_count: 5,
},
[expectedAssociatedGroupID4]: {
id: [expectedAssociatedGroupID4],
name: 'nobctj4brfgtpj3a1peiyq47tc',
display_name: 'engineering',
description: '',
source: 'ldap',
create_at: 1553808971099,
remote_id: 'engineering',
update_at: 1553808971099,
delete_at: 0,
has_syncables: false,
member_count: 8,
},
[expectedAssociatedGroupID2]: {
id: expectedAssociatedGroupID2,
name: '7ybu9oy77jgedqp4pph8f4j5ge',
display_name: 'xyz',
description: '',
source: 'ldap',
remote_id: 'xyz',
create_at: 1553808972099,
update_at: 1553808972099,
delete_at: 0,
has_syncables: false,
member_count: 2,
},
},
},
teams: {
groupsAssociatedToTeam: {
[teamID]: {ids: teamAssociatedGroupIDs},
},
},
channels: {
groupsAssociatedToChannel: {
[channelID]: {ids: channelAssociatedGroupIDs},
},
},
},
});
it('getGroupsAssociatedToTeam', () => {
const expected = [
testState.entities.groups.groups[expectedAssociatedGroupID1],
testState.entities.groups.groups[expectedAssociatedGroupID2],
];
assert.deepEqual(Selectors.getGroupsAssociatedToTeam(testState, teamID), expected);
});
it('getGroupsNotAssociatedToTeam', () => {
const expected = Object.entries(testState.entities.groups.groups).filter(([groupID]) => !teamAssociatedGroupIDs.includes(groupID)).map(([, group]) => group);
assert.deepEqual(Selectors.getGroupsNotAssociatedToTeam(testState, teamID), expected);
});
it('getGroupsAssociatedToChannel', () => {
const expected = [
testState.entities.groups.groups[expectedAssociatedGroupID3],
testState.entities.groups.groups[expectedAssociatedGroupID4],
];
assert.deepEqual(Selectors.getGroupsAssociatedToChannel(testState, channelID), expected);
});
it('getGroupsNotAssociatedToChannel', () => {
const expected = Object.entries(testState.entities.groups.groups).filter(([groupID]) => !channelAssociatedGroupIDs.includes(groupID)).map(([, group]) => group);
assert.deepEqual(Selectors.getGroupsNotAssociatedToChannel(testState, channelID), expected);
});
});