mirror of https://github.com/grafana/grafana
parent
8f99276606
commit
94971abd9c
@ -0,0 +1,51 @@ |
||||
import React from 'react'; |
||||
import { shallow } from 'enzyme'; |
||||
import { UsersListPage, Props } from './UsersListPage'; |
||||
import { NavModel, User } from 'app/types'; |
||||
import { getMockUser } from './__mocks__/userMocks'; |
||||
import appEvents from '../../core/app_events'; |
||||
|
||||
jest.mock('../../core/app_events', () => ({ |
||||
emit: jest.fn(), |
||||
})); |
||||
|
||||
const setup = (propOverrides?: object) => { |
||||
const props: Props = { |
||||
navModel: {} as NavModel, |
||||
users: [] as User[], |
||||
searchQuery: '', |
||||
loadUsers: jest.fn(), |
||||
updateUser: jest.fn(), |
||||
removeUser: jest.fn(), |
||||
setUsersSearchQuery: jest.fn(), |
||||
}; |
||||
|
||||
Object.assign(props, propOverrides); |
||||
|
||||
const wrapper = shallow(<UsersListPage {...props} />); |
||||
const instance = wrapper.instance() as UsersListPage; |
||||
|
||||
return { |
||||
wrapper, |
||||
instance, |
||||
}; |
||||
}; |
||||
|
||||
describe('Render', () => { |
||||
it('should render component', () => { |
||||
const { wrapper } = setup(); |
||||
|
||||
expect(wrapper).toMatchSnapshot(); |
||||
}); |
||||
}); |
||||
|
||||
describe('Functions', () => { |
||||
it('should emit show remove user modal', () => { |
||||
const { instance } = setup(); |
||||
const mockUser = getMockUser(); |
||||
|
||||
instance.onRemoveUser(mockUser); |
||||
|
||||
expect(appEvents.emit).toHaveBeenCalled(); |
||||
}); |
||||
}); |
@ -0,0 +1,33 @@ |
||||
import React from 'react'; |
||||
import { shallow } from 'enzyme'; |
||||
import UsersTable, { Props } from './UsersTable'; |
||||
import { User } from 'app/types'; |
||||
import { getMockUsers } from './__mocks__/userMocks'; |
||||
|
||||
const setup = (propOverrides?: object) => { |
||||
const props: Props = { |
||||
users: [] as User[], |
||||
onRoleChange: jest.fn(), |
||||
onRemoveUser: jest.fn(), |
||||
}; |
||||
|
||||
Object.assign(props, propOverrides); |
||||
|
||||
return shallow(<UsersTable {...props} />); |
||||
}; |
||||
|
||||
describe('Render', () => { |
||||
it('should render component', () => { |
||||
const wrapper = setup(); |
||||
|
||||
expect(wrapper).toMatchSnapshot(); |
||||
}); |
||||
|
||||
it('should render users table', () => { |
||||
const wrapper = setup({ |
||||
users: getMockUsers(5), |
||||
}); |
||||
|
||||
expect(wrapper).toMatchSnapshot(); |
||||
}); |
||||
}); |
@ -0,0 +1,31 @@ |
||||
export const getMockUsers = (amount: number) => { |
||||
const users = []; |
||||
|
||||
for (let i = 0; i <= amount; i++) { |
||||
users.push({ |
||||
avatarUrl: 'url/to/avatar', |
||||
email: `user-${i}@test.com`, |
||||
lastSeenAt: '2018-10-01', |
||||
lastSeenAtAge: '', |
||||
login: `user-${i}`, |
||||
orgId: 1, |
||||
role: 'Admin', |
||||
userId: i, |
||||
}); |
||||
} |
||||
|
||||
return users; |
||||
}; |
||||
|
||||
export const getMockUser = () => { |
||||
return { |
||||
avatarUrl: 'url/to/avatar', |
||||
email: `user@test.com`, |
||||
lastSeenAt: '2018-10-01', |
||||
lastSeenAtAge: '', |
||||
login: `user`, |
||||
orgId: 1, |
||||
role: 'Admin', |
||||
userId: 2, |
||||
}; |
||||
}; |
@ -0,0 +1,29 @@ |
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP |
||||
|
||||
exports[`Render should render component 1`] = ` |
||||
<div> |
||||
<PageHeader |
||||
model={Object {}} |
||||
/> |
||||
<div |
||||
className="page-container page-body" |
||||
> |
||||
<OrgActionBar |
||||
linkButton={ |
||||
Object { |
||||
"href": "/org/users/add", |
||||
"title": "Add user", |
||||
} |
||||
} |
||||
searchQuery="" |
||||
setSearchQuery={[MockFunction]} |
||||
showLayoutMode={false} |
||||
/> |
||||
<UsersTable |
||||
onRemoveUser={[Function]} |
||||
onRoleChange={[Function]} |
||||
users={Array []} |
||||
/> |
||||
</div> |
||||
</div> |
||||
`; |
@ -0,0 +1,448 @@ |
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP |
||||
|
||||
exports[`Render should render component 1`] = ` |
||||
<div> |
||||
<table |
||||
className="filter-table form-inline" |
||||
> |
||||
<thead> |
||||
<tr> |
||||
<th /> |
||||
<th> |
||||
Login |
||||
</th> |
||||
<th> |
||||
Email |
||||
</th> |
||||
<th> |
||||
Seen |
||||
</th> |
||||
<th> |
||||
Role |
||||
</th> |
||||
<th |
||||
style={ |
||||
Object { |
||||
"width": "34px", |
||||
} |
||||
} |
||||
/> |
||||
</tr> |
||||
</thead> |
||||
<tbody /> |
||||
</table> |
||||
</div> |
||||
`; |
||||
|
||||
exports[`Render should render users table 1`] = ` |
||||
<div> |
||||
<table |
||||
className="filter-table form-inline" |
||||
> |
||||
<thead> |
||||
<tr> |
||||
<th /> |
||||
<th> |
||||
Login |
||||
</th> |
||||
<th> |
||||
Email |
||||
</th> |
||||
<th> |
||||
Seen |
||||
</th> |
||||
<th> |
||||
Role |
||||
</th> |
||||
<th |
||||
style={ |
||||
Object { |
||||
"width": "34px", |
||||
} |
||||
} |
||||
/> |
||||
</tr> |
||||
</thead> |
||||
<tbody> |
||||
<tr |
||||
key="0-0" |
||||
> |
||||
<td |
||||
className="width-4 text-center" |
||||
> |
||||
<img |
||||
className="filter-table__avatar" |
||||
src="url/to/avatar" |
||||
/> |
||||
</td> |
||||
<td> |
||||
user-0 |
||||
</td> |
||||
<td> |
||||
<span |
||||
className="ellipsis" |
||||
> |
||||
user-0@test.com |
||||
</span> |
||||
</td> |
||||
<td /> |
||||
<td> |
||||
<div |
||||
className="gf-form-select-wrapper width-12" |
||||
> |
||||
<select |
||||
className="gf-form-input" |
||||
onChange={[Function]} |
||||
value="Admin" |
||||
> |
||||
<option |
||||
key="Viewer-0" |
||||
value="Viewer" |
||||
> |
||||
Viewer |
||||
</option> |
||||
<option |
||||
key="Editor-1" |
||||
value="Editor" |
||||
> |
||||
Editor |
||||
</option> |
||||
<option |
||||
key="Admin-2" |
||||
value="Admin" |
||||
> |
||||
Admin |
||||
</option> |
||||
</select> |
||||
</div> |
||||
</td> |
||||
<td> |
||||
<div |
||||
className="btn btn-danger btn-mini" |
||||
onClick={[Function]} |
||||
> |
||||
<i |
||||
className="fa fa-remove" |
||||
/> |
||||
</div> |
||||
</td> |
||||
</tr> |
||||
<tr |
||||
key="1-1" |
||||
> |
||||
<td |
||||
className="width-4 text-center" |
||||
> |
||||
<img |
||||
className="filter-table__avatar" |
||||
src="url/to/avatar" |
||||
/> |
||||
</td> |
||||
<td> |
||||
user-1 |
||||
</td> |
||||
<td> |
||||
<span |
||||
className="ellipsis" |
||||
> |
||||
user-1@test.com |
||||
</span> |
||||
</td> |
||||
<td /> |
||||
<td> |
||||
<div |
||||
className="gf-form-select-wrapper width-12" |
||||
> |
||||
<select |
||||
className="gf-form-input" |
||||
onChange={[Function]} |
||||
value="Admin" |
||||
> |
||||
<option |
||||
key="Viewer-0" |
||||
value="Viewer" |
||||
> |
||||
Viewer |
||||
</option> |
||||
<option |
||||
key="Editor-1" |
||||
value="Editor" |
||||
> |
||||
Editor |
||||
</option> |
||||
<option |
||||
key="Admin-2" |
||||
value="Admin" |
||||
> |
||||
Admin |
||||
</option> |
||||
</select> |
||||
</div> |
||||
</td> |
||||
<td> |
||||
<div |
||||
className="btn btn-danger btn-mini" |
||||
onClick={[Function]} |
||||
> |
||||
<i |
||||
className="fa fa-remove" |
||||
/> |
||||
</div> |
||||
</td> |
||||
</tr> |
||||
<tr |
||||
key="2-2" |
||||
> |
||||
<td |
||||
className="width-4 text-center" |
||||
> |
||||
<img |
||||
className="filter-table__avatar" |
||||
src="url/to/avatar" |
||||
/> |
||||
</td> |
||||
<td> |
||||
user-2 |
||||
</td> |
||||
<td> |
||||
<span |
||||
className="ellipsis" |
||||
> |
||||
user-2@test.com |
||||
</span> |
||||
</td> |
||||
<td /> |
||||
<td> |
||||
<div |
||||
className="gf-form-select-wrapper width-12" |
||||
> |
||||
<select |
||||
className="gf-form-input" |
||||
onChange={[Function]} |
||||
value="Admin" |
||||
> |
||||
<option |
||||
key="Viewer-0" |
||||
value="Viewer" |
||||
> |
||||
Viewer |
||||
</option> |
||||
<option |
||||
key="Editor-1" |
||||
value="Editor" |
||||
> |
||||
Editor |
||||
</option> |
||||
<option |
||||
key="Admin-2" |
||||
value="Admin" |
||||
> |
||||
Admin |
||||
</option> |
||||
</select> |
||||
</div> |
||||
</td> |
||||
<td> |
||||
<div |
||||
className="btn btn-danger btn-mini" |
||||
onClick={[Function]} |
||||
> |
||||
<i |
||||
className="fa fa-remove" |
||||
/> |
||||
</div> |
||||
</td> |
||||
</tr> |
||||
<tr |
||||
key="3-3" |
||||
> |
||||
<td |
||||
className="width-4 text-center" |
||||
> |
||||
<img |
||||
className="filter-table__avatar" |
||||
src="url/to/avatar" |
||||
/> |
||||
</td> |
||||
<td> |
||||
user-3 |
||||
</td> |
||||
<td> |
||||
<span |
||||
className="ellipsis" |
||||
> |
||||
user-3@test.com |
||||
</span> |
||||
</td> |
||||
<td /> |
||||
<td> |
||||
<div |
||||
className="gf-form-select-wrapper width-12" |
||||
> |
||||
<select |
||||
className="gf-form-input" |
||||
onChange={[Function]} |
||||
value="Admin" |
||||
> |
||||
<option |
||||
key="Viewer-0" |
||||
value="Viewer" |
||||
> |
||||
Viewer |
||||
</option> |
||||
<option |
||||
key="Editor-1" |
||||
value="Editor" |
||||
> |
||||
Editor |
||||
</option> |
||||
<option |
||||
key="Admin-2" |
||||
value="Admin" |
||||
> |
||||
Admin |
||||
</option> |
||||
</select> |
||||
</div> |
||||
</td> |
||||
<td> |
||||
<div |
||||
className="btn btn-danger btn-mini" |
||||
onClick={[Function]} |
||||
> |
||||
<i |
||||
className="fa fa-remove" |
||||
/> |
||||
</div> |
||||
</td> |
||||
</tr> |
||||
<tr |
||||
key="4-4" |
||||
> |
||||
<td |
||||
className="width-4 text-center" |
||||
> |
||||
<img |
||||
className="filter-table__avatar" |
||||
src="url/to/avatar" |
||||
/> |
||||
</td> |
||||
<td> |
||||
user-4 |
||||
</td> |
||||
<td> |
||||
<span |
||||
className="ellipsis" |
||||
> |
||||
user-4@test.com |
||||
</span> |
||||
</td> |
||||
<td /> |
||||
<td> |
||||
<div |
||||
className="gf-form-select-wrapper width-12" |
||||
> |
||||
<select |
||||
className="gf-form-input" |
||||
onChange={[Function]} |
||||
value="Admin" |
||||
> |
||||
<option |
||||
key="Viewer-0" |
||||
value="Viewer" |
||||
> |
||||
Viewer |
||||
</option> |
||||
<option |
||||
key="Editor-1" |
||||
value="Editor" |
||||
> |
||||
Editor |
||||
</option> |
||||
<option |
||||
key="Admin-2" |
||||
value="Admin" |
||||
> |
||||
Admin |
||||
</option> |
||||
</select> |
||||
</div> |
||||
</td> |
||||
<td> |
||||
<div |
||||
className="btn btn-danger btn-mini" |
||||
onClick={[Function]} |
||||
> |
||||
<i |
||||
className="fa fa-remove" |
||||
/> |
||||
</div> |
||||
</td> |
||||
</tr> |
||||
<tr |
||||
key="5-5" |
||||
> |
||||
<td |
||||
className="width-4 text-center" |
||||
> |
||||
<img |
||||
className="filter-table__avatar" |
||||
src="url/to/avatar" |
||||
/> |
||||
</td> |
||||
<td> |
||||
user-5 |
||||
</td> |
||||
<td> |
||||
<span |
||||
className="ellipsis" |
||||
> |
||||
user-5@test.com |
||||
</span> |
||||
</td> |
||||
<td /> |
||||
<td> |
||||
<div |
||||
className="gf-form-select-wrapper width-12" |
||||
> |
||||
<select |
||||
className="gf-form-input" |
||||
onChange={[Function]} |
||||
value="Admin" |
||||
> |
||||
<option |
||||
key="Viewer-0" |
||||
value="Viewer" |
||||
> |
||||
Viewer |
||||
</option> |
||||
<option |
||||
key="Editor-1" |
||||
value="Editor" |
||||
> |
||||
Editor |
||||
</option> |
||||
<option |
||||
key="Admin-2" |
||||
value="Admin" |
||||
> |
||||
Admin |
||||
</option> |
||||
</select> |
||||
</div> |
||||
</td> |
||||
<td> |
||||
<div |
||||
className="btn btn-danger btn-mini" |
||||
onClick={[Function]} |
||||
> |
||||
<i |
||||
className="fa fa-remove" |
||||
/> |
||||
</div> |
||||
</td> |
||||
</tr> |
||||
</tbody> |
||||
</table> |
||||
</div> |
||||
`; |
Loading…
Reference in new issue