Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
82cfa29c
Commit
82cfa29c
authored
Jun 23, 2017
by
Daniel Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashfolders: tests for permission modal
parent
a4910c7a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
49 deletions
+42
-49
public/app/features/dashboard/acl/acl.ts
+1
-7
public/app/features/dashboard/acl/specs/acl_specs.ts
+41
-42
No files found.
public/app/features/dashboard/acl/acl.ts
View file @
82cfa29c
...
...
@@ -45,9 +45,6 @@ export class AclCtrl {
sortItems
()
{
this
.
items
=
_
.
orderBy
(
this
.
items
,
[
'sortRank'
,
'sortName'
],
[
'desc'
,
'asc'
]);
for
(
let
i
of
this
.
items
)
{
console
.
log
(
i
.
sortRank
);
}
}
prepareViewModel
(
item
:
DashboardAcl
):
DashboardAcl
{
...
...
@@ -70,9 +67,6 @@ export class AclCtrl {
item
.
sortName
=
item
.
role
;
item
.
sortRank
=
30
;
if
(
item
.
role
===
'Viewer'
)
{
item
.
sortRank
+=
2
;
}
if
(
item
.
role
===
'Viewer'
)
{
item
.
sortRank
+=
1
;
}
}
...
...
@@ -100,7 +94,7 @@ export class AclCtrl {
}
return
this
.
backendSrv
.
post
(
`/api/dashboards/id/
${
this
.
dashboard
.
id
}
/acl`
,
{
items
:
updated
}).
then
(()
=>
{
this
.
dismiss
();
return
this
.
dismiss
();
});
}
...
...
public/app/features/dashboard/acl/specs/acl_specs.ts
View file @
82cfa29c
...
...
@@ -2,12 +2,16 @@ import {describe, beforeEach, it, expect, sinon, angularMocks} from 'test/lib/co
import
{
AclCtrl
}
from
'../acl'
;
describe
(
'AclCtrl'
,
()
=>
{
var
ctx
:
any
=
{};
var
backendSrv
=
{
const
ctx
:
any
=
{};
const
backendSrv
=
{
get
:
sinon
.
stub
().
returns
(
Promise
.
resolve
([])),
post
:
sinon
.
stub
().
returns
(
Promise
.
resolve
([]))
};
const
dashboardSrv
=
{
getCurrent
:
sinon
.
stub
().
returns
({
id
:
1
})
};
beforeEach
(
angularMocks
.
module
(
'grafana.core'
));
beforeEach
(
angularMocks
.
module
(
'grafana.controllers'
));
...
...
@@ -18,64 +22,59 @@ describe('AclCtrl', () => {
ctx
.
ctrl
=
$controller
(
AclCtrl
,
{
$scope
:
ctx
.
scope
,
backendSrv
:
backendSrv
,
dashboardSrv
:
dashboardSrv
},
{
d
ashboard
:
{
id
:
1
}
d
ismiss
:
()
=>
{
return
;
}
});
}));
describe
(
'when
user permission is to b
e added'
,
()
=>
{
beforeEach
(
done
=>
{
describe
(
'when
permissions ar
e added'
,
()
=>
{
beforeEach
(
()
=>
{
backendSrv
.
get
.
reset
();
backendSrv
.
post
.
reset
();
ctx
.
ctrl
.
type
=
'User'
;
ctx
.
ctrl
.
userId
=
2
;
ctx
.
ctrl
.
permission
=
1
;
c
tx
.
ctrl
.
addPermission
().
then
(()
=>
{
done
();
});
})
;
c
onst
userItem
=
{
id
:
2
,
login
:
'user2'
,
}
;
it
(
'should parse the result and save to db'
,
()
=>
{
expect
(
backendSrv
.
post
.
getCall
(
0
).
args
[
0
]).
to
.
eql
(
'/api/dashboards/id/1/acl'
);
expect
(
backendSrv
.
post
.
getCall
(
0
).
args
[
1
].
userId
).
to
.
eql
(
2
);
expect
(
backendSrv
.
post
.
getCall
(
0
).
args
[
1
].
permissions
).
to
.
eql
(
1
);
});
ctx
.
ctrl
.
userPicked
(
userItem
);
it
(
'should refresh the list after saving.'
,
()
=>
{
expect
(
backendSrv
.
get
.
getCall
(
0
).
args
[
0
]).
to
.
eql
(
'/api/dashboards/id/1/acl'
);
});
const
userGroupItem
=
{
id
:
2
,
name
:
'ug1'
,
};
it
(
'should reset userId'
,
()
=>
{
expect
(
ctx
.
ctrl
.
userId
).
to
.
eql
(
null
);
});
});
ctx
.
ctrl
.
groupPicked
(
userGroupItem
);
describe
(
'when user group permission is to be added'
,
()
=>
{
beforeEach
(
done
=>
{
backendSrv
.
get
.
reset
();
backendSrv
.
post
.
reset
();
ctx
.
ctrl
.
type
=
'User Group'
;
ctx
.
ctrl
.
userGroupId
=
2
;
ctx
.
ctrl
.
permission
=
1
;
ctx
.
ctrl
.
newType
=
'Editor'
;
ctx
.
ctrl
.
typeChanged
();
ctx
.
ctrl
.
addPermission
().
then
(()
=>
{
done
();
});
ctx
.
ctrl
.
newType
=
'Viewer'
;
ctx
.
ctrl
.
typeChanged
();
});
it
(
'should parse the result and save to db'
,
()
=>
{
expect
(
backendSrv
.
post
.
getCall
(
0
).
args
[
0
]).
to
.
eql
(
'/api/dashboards/id/1/acl'
);
expect
(
backendSrv
.
post
.
getCall
(
0
).
args
[
1
].
userGroupId
).
to
.
eql
(
2
);
expect
(
backendSrv
.
post
.
getCall
(
0
).
args
[
1
].
permissions
).
to
.
eql
(
1
);
it
(
'should sort the result by role, user group and user'
,
()
=>
{
expect
(
ctx
.
ctrl
.
items
[
0
].
role
).
to
.
eql
(
'Viewer'
);
expect
(
ctx
.
ctrl
.
items
[
1
].
role
).
to
.
eql
(
'Editor'
);
expect
(
ctx
.
ctrl
.
items
[
2
].
userGroupId
).
to
.
eql
(
2
);
expect
(
ctx
.
ctrl
.
items
[
3
].
userId
).
to
.
eql
(
2
);
});
it
(
'should refresh the list after saving.'
,
()
=>
{
expect
(
backendSrv
.
get
.
getCall
(
0
).
args
[
0
]).
to
.
eql
(
'/api/dashboards/id/1/acl'
);
it
(
'should save permissions to db'
,
(
done
)
=>
{
ctx
.
ctrl
.
update
().
then
(()
=>
{
done
();
});
it
(
'should reset userGroupId'
,
()
=>
{
expect
(
ctx
.
ctrl
.
userGroupId
).
to
.
eql
(
null
);
expect
(
backendSrv
.
post
.
getCall
(
0
).
args
[
0
]).
to
.
eql
(
'/api/dashboards/id/1/acl'
);
expect
(
backendSrv
.
post
.
getCall
(
0
).
args
[
1
].
items
[
0
].
role
).
to
.
eql
(
'Viewer'
);
expect
(
backendSrv
.
post
.
getCall
(
0
).
args
[
1
].
items
[
0
].
permission
).
to
.
eql
(
1
);
expect
(
backendSrv
.
post
.
getCall
(
0
).
args
[
1
].
items
[
1
].
role
).
to
.
eql
(
'Editor'
);
expect
(
backendSrv
.
post
.
getCall
(
0
).
args
[
1
].
items
[
1
].
permission
).
to
.
eql
(
1
);
expect
(
backendSrv
.
post
.
getCall
(
0
).
args
[
1
].
items
[
2
].
userGroupId
).
to
.
eql
(
2
);
expect
(
backendSrv
.
post
.
getCall
(
0
).
args
[
1
].
items
[
2
].
permission
).
to
.
eql
(
1
);
expect
(
backendSrv
.
post
.
getCall
(
0
).
args
[
1
].
items
[
3
].
userId
).
to
.
eql
(
2
);
expect
(
backendSrv
.
post
.
getCall
(
0
).
args
[
1
].
items
[
3
].
permission
).
to
.
eql
(
1
);
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment