This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* MM-21584 Add initial reducers and actions for channel categories * MM-21584 Add initial selectors for channel categories * Add channelCategories to the base reducer * Remove collapsedById * Fix typo in test name
- Loading branch information
Showing
16 changed files
with
1,199 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
import keyMirror from 'utils/key_mirror'; | ||
|
||
export default keyMirror({ | ||
RECEIVED_CATEGORY: null, | ||
RECEIVED_CATEGORIES: null, | ||
RECEIVED_CATEGORY_ORDER: null, | ||
|
||
CATEGORY_COLLAPSED: null, | ||
CATEGORY_EXPANDED: null, | ||
|
||
CATEGORY_DELETED: null, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
import {ChannelCategoryTypes} from 'action_types'; | ||
|
||
export function expandCategory(categoryId: string) { | ||
return { | ||
type: ChannelCategoryTypes.CATEGORY_EXPANDED, | ||
data: categoryId, | ||
}; | ||
} | ||
|
||
export function collapseCategory(categoryId: string) { | ||
return { | ||
type: ChannelCategoryTypes.CATEGORY_COLLAPSED, | ||
data: categoryId, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
import {ChannelCategoryType} from 'types/channel_categories'; | ||
|
||
export const CategoryTypes: {[name: string]: ChannelCategoryType} = { | ||
FAVORITES: 'favorites', | ||
PUBLIC: 'public', | ||
PRIVATE: 'private', | ||
DIRECT_MESSAGES: 'direct_messages', | ||
CUSTOM: 'custom', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
import {CategoryTypes} from '../../constants/channel_categories'; | ||
|
||
import {ChannelCategoryTypes, TeamTypes} from 'action_types'; | ||
|
||
import * as Reducers from './channel_categories'; | ||
|
||
describe('byId', () => { | ||
test('default categories should be added when a member is received', () => { | ||
const initialState = {}; | ||
|
||
const state = Reducers.byId( | ||
initialState, | ||
{ | ||
type: TeamTypes.RECEIVED_MY_TEAM_MEMBER, | ||
data: { | ||
team_id: 'team1', | ||
}, | ||
} | ||
); | ||
|
||
expect(state['team1-favorites']).toBeDefined(); | ||
expect(state['team1-public']).toBeDefined(); | ||
expect(state['team1-private']).toBeDefined(); | ||
expect(state['team1-direct_messages']).toBeDefined(); | ||
}); | ||
|
||
test('default categories should be added when multiple members are received', () => { | ||
const initialState = {}; | ||
|
||
const state = Reducers.byId( | ||
initialState, | ||
{ | ||
type: TeamTypes.RECEIVED_MY_TEAM_MEMBERS, | ||
data: [ | ||
{team_id: 'team1'}, | ||
{team_id: 'team2'}, | ||
], | ||
} | ||
); | ||
|
||
expect(state['team1-favorites']).toBeDefined(); | ||
expect(state['team1-public']).toBeDefined(); | ||
expect(state['team1-private']).toBeDefined(); | ||
expect(state['team1-direct_messages']).toBeDefined(); | ||
expect(state['team2-favorites']).toBeDefined(); | ||
expect(state['team2-public']).toBeDefined(); | ||
expect(state['team2-private']).toBeDefined(); | ||
expect(state['team2-direct_messages']).toBeDefined(); | ||
}); | ||
|
||
test('should remove corresponding categories when leaving a team', () => { | ||
const initialState = { | ||
category1: {id: 'category1', team_id: 'team1', type: CategoryTypes.CUSTOM}, | ||
category2: {id: 'category2', team_id: 'team1', type: CategoryTypes.CUSTOM}, | ||
dmCategory1: {id: 'dmCategory1', team_id: 'team1', type: CategoryTypes.DIRECT_MESSAGES}, | ||
category3: {id: 'category3', team_id: 'team2', type: CategoryTypes.CUSTOM}, | ||
category4: {id: 'category4', team_id: 'team2', type: CategoryTypes.CUSTOM}, | ||
dmCategory2: {id: 'dmCategory1', team_id: 'team2', type: CategoryTypes.DIRECT_MESSAGES}, | ||
}; | ||
|
||
const state = Reducers.byId( | ||
initialState, | ||
{ | ||
type: TeamTypes.LEAVE_TEAM, | ||
data: { | ||
id: 'team1', | ||
}, | ||
} | ||
); | ||
|
||
expect(state).toEqual({ | ||
category3: state.category3, | ||
category4: state.category4, | ||
dmCategory2: state.dmCategory2, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('orderByTeam', () => { | ||
test('default category order should be added when a member is received', () => { | ||
const initialState = {}; | ||
|
||
const state = Reducers.orderByTeam( | ||
initialState, | ||
{ | ||
type: TeamTypes.RECEIVED_MY_TEAM_MEMBER, | ||
data: { | ||
team_id: 'team1', | ||
}, | ||
} | ||
); | ||
|
||
expect(state).toEqual({ | ||
team1: [ | ||
'team1-favorites', | ||
'team1-public', | ||
'team1-private', | ||
'team1-direct_messages', | ||
], | ||
}); | ||
}); | ||
|
||
test('default category order should be added when multiple members are received', () => { | ||
const initialState = {}; | ||
|
||
const state = Reducers.orderByTeam( | ||
initialState, | ||
{ | ||
type: TeamTypes.RECEIVED_MY_TEAM_MEMBERS, | ||
data: [ | ||
{team_id: 'team1'}, | ||
{team_id: 'team2'}, | ||
], | ||
} | ||
); | ||
|
||
expect(state).toEqual({ | ||
team1: [ | ||
'team1-favorites', | ||
'team1-public', | ||
'team1-private', | ||
'team1-direct_messages', | ||
], | ||
team2: [ | ||
'team2-favorites', | ||
'team2-public', | ||
'team2-private', | ||
'team2-direct_messages', | ||
], | ||
}); | ||
}); | ||
|
||
test('should remove correspoding order when leaving a team', () => { | ||
const initialState = { | ||
team1: ['category1', 'category2', 'dmCategory1'], | ||
team2: ['category3', 'category4', 'dmCategory2'], | ||
}; | ||
|
||
const state = Reducers.orderByTeam( | ||
initialState, | ||
{ | ||
type: TeamTypes.LEAVE_TEAM, | ||
data: { | ||
id: 'team1', | ||
}, | ||
} | ||
); | ||
|
||
expect(state).toEqual({ | ||
team2: initialState.team2, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.