Commit 20052150 by Johannes Schill

tests: Move tests from Permissions to AddPermissions #10676

parent 1b9e02e4
import React from 'react';
import AddPermissions from './AddPermissions';
import { RootStore } from 'app/stores/RootStore/RootStore';
import { backendSrv } from 'test/mocks/common';
import { shallow } from 'enzyme';
describe('AddPermissions', () => {
let wrapper;
beforeAll(() => {
backendSrv.get.mockReturnValue(
Promise.resolve([
{ id: 2, dashboardId: 1, role: 'Viewer', permission: 1, permissionName: 'View' },
{ id: 3, dashboardId: 1, role: 'Editor', permission: 1, permissionName: 'Edit' },
{
id: 4,
dashboardId: 1,
userId: 2,
userLogin: 'danlimerick',
userEmail: 'dan.limerick@gmail.com',
permission: 4,
permissionName: 'Admin',
},
])
);
backendSrv.post = jest.fn();
const store = RootStore.create(
{},
{
backendSrv: backendSrv,
}
);
// wrapper = shallow(<Permissions backendSrv={backendSrv} isFolder={true} dashboardId={1} {...store} />);
wrapper = shallow(<AddPermissions permissions={store.permissions} backendSrv={backendSrv} dashboardId={1} />);
//<AddPermissions permissions={permissions} backendSrv={backendSrv} dashboardId={dashboardId} />
// return wrapper.instance().loadStore(1, true);
});
describe('when permission for a user is added', () => {
it('should save permission to db', async () => {
const evt = {
target: {
value: 'User',
},
};
const userItem = {
id: 2,
login: 'user2',
};
const instance = wrapper.instance();
instance.typeChanged(evt);
instance.userPicked(userItem);
wrapper.find('[data-save-permission]').simulate('click');
expect(backendSrv.post.mock.calls.length).toBe(1);
expect(backendSrv.post.mock.calls[0][0]).toBe('/api/dashboards/id/1/acl');
});
});
// describe('when permission for team is added', () => {
// it('should save permission to db', () => {
// const teamItem = {
// id: 2,
// name: 'ug1',
// };
// wrapper
// .instance()
// .teamPicked(teamItem)
// .then(() => {
// expect(backendSrv.post.mock.calls.length).toBe(1);
// expect(backendSrv.post.mock.calls[0][0]).toBe('/api/dashboards/id/1/acl');
// });
// });
// });
});
......@@ -124,7 +124,7 @@ class AddPermissions extends Component<IProps, any> {
</div>
<div className="gf-form">
<button className="btn btn-success" type="submit" disabled={!newItem.isValid()}>
<button data-save-permission className="btn btn-success" type="submit" disabled={!newItem.isValid()}>
Save
</button>
</div>
......
......@@ -55,7 +55,6 @@ class UserPicker extends Component<IProps, any> {
render() {
const AsyncComponent = this.state.creatable ? Select.AsyncCreatable : Select.Async;
const { isLoading, handlePicked, value } = this.props;
console.log('value', value);
return (
<div className="user-picker">
<AsyncComponent
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment