mirror of https://github.com/grafana/grafana
parent
7e340b7aa5
commit
f68ac20218
@ -0,0 +1,32 @@ |
||||
import { Team } from '../../../types'; |
||||
|
||||
export const getMultipleMockTeams = (numberOfTeams: number): Team[] => { |
||||
let teams: Team[] = []; |
||||
for (let i = 1; i <= numberOfTeams; i++) { |
||||
teams.push({ |
||||
id: i, |
||||
name: `test-${i}`, |
||||
avatarUrl: 'some/url/', |
||||
email: `test-${i}@test.com`, |
||||
memberCount: i, |
||||
search: '', |
||||
members: [], |
||||
groups: [], |
||||
}); |
||||
} |
||||
|
||||
return teams; |
||||
}; |
||||
|
||||
export const getMockTeam = (): Team => { |
||||
return { |
||||
id: 1, |
||||
name: 'test', |
||||
avatarUrl: 'some/url/', |
||||
email: 'test@test.com', |
||||
memberCount: 1, |
||||
search: '', |
||||
members: [], |
||||
groups: [], |
||||
}; |
||||
}; |
@ -0,0 +1,41 @@ |
||||
import { Action, ActionTypes } from './actions'; |
||||
import { initialState, teamsReducer } from './reducers'; |
||||
|
||||
describe('teams reducer', () => { |
||||
it('should set teams', () => { |
||||
const payload = [ |
||||
{ |
||||
id: 1, |
||||
name: 'test', |
||||
avatarUrl: 'some/url/', |
||||
email: 'test@test.com', |
||||
memberCount: 1, |
||||
search: '', |
||||
members: [], |
||||
groups: [], |
||||
}, |
||||
]; |
||||
|
||||
const action: Action = { |
||||
type: ActionTypes.LoadTeams, |
||||
payload, |
||||
}; |
||||
|
||||
const result = teamsReducer(initialState, action); |
||||
|
||||
expect(result.teams).toEqual(payload); |
||||
}); |
||||
|
||||
it('should set search query', () => { |
||||
const payload = 'test'; |
||||
|
||||
const action: Action = { |
||||
type: ActionTypes.SetSearchQuery, |
||||
payload, |
||||
}; |
||||
|
||||
const result = teamsReducer(initialState, action); |
||||
|
||||
expect(result.searchQuery).toEqual('test'); |
||||
}); |
||||
}); |
@ -0,0 +1,25 @@ |
||||
import { getTeams } from './selectors'; |
||||
import { getMultipleMockTeams } from '../__mocks__/teamMocks'; |
||||
import { TeamsState } from '../../../types'; |
||||
|
||||
describe('Team selectors', () => { |
||||
describe('Get teams', () => { |
||||
const mockTeams = getMultipleMockTeams(5); |
||||
|
||||
it('should return teams if no search query', () => { |
||||
const mockState: TeamsState = { teams: mockTeams, searchQuery: '' }; |
||||
|
||||
const teams = getTeams(mockState); |
||||
|
||||
expect(teams).toEqual(mockTeams); |
||||
}); |
||||
|
||||
it('Should filter teams if search query', () => { |
||||
const mockState: TeamsState = { teams: mockTeams, searchQuery: '5' }; |
||||
|
||||
const teams = getTeams(mockState); |
||||
|
||||
expect(teams.length).toEqual(1); |
||||
}); |
||||
}); |
||||
}); |
@ -1 +1,9 @@ |
||||
export const getTeams = state => state.teams; |
||||
export const getSearchQuery = state => state.searchQuery; |
||||
|
||||
export const getTeams = state => { |
||||
const regex = RegExp(state.searchQuery, 'i'); |
||||
|
||||
return state.teams.filter(team => { |
||||
return regex.test(team.name); |
||||
}); |
||||
}; |
||||
|
Loading…
Reference in new issue