Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
f496a31c
Commit
f496a31c
authored
Mar 01, 2017
by
Robert Knight
Committed by
GitHub
Mar 01, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #263 from hypothesis/login-control-tests
Add tests for login control.
parents
de385bad
1bae76d9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
162 additions
and
0 deletions
+162
-0
login-control-test.js
src/sidebar/directive/test/login-control-test.js
+162
-0
No files found.
src/sidebar/directive/test/login-control-test.js
0 → 100644
View file @
f496a31c
'use strict'
;
var
angular
=
require
(
'angular'
);
var
util
=
require
(
'./util'
);
function
PageObject
(
element
)
{
this
.
unknownLoginText
=
function
()
{
return
element
[
0
].
querySelector
(
'.login-text'
).
textContent
;
};
this
.
loginText
=
function
()
{
return
Array
.
from
(
element
[
0
].
querySelectorAll
(
'.login-text a'
))
.
map
(
function
(
el
)
{
return
el
.
textContent
;
});
};
this
.
menuLinks
=
function
()
{
return
Array
.
from
(
element
[
0
].
querySelectorAll
(
'.login-control-menu .dropdown-menu a'
))
.
map
(
function
(
el
)
{
return
el
.
textContent
;
});
};
this
.
disabledMenuItems
=
function
()
{
return
Array
.
from
(
element
[
0
].
querySelectorAll
(
'.login-control-menu .dropdown-menu__link--disabled'
))
.
map
(
function
(
el
)
{
return
el
.
textContent
.
trim
();
});
};
this
.
menuText
=
function
()
{
return
element
[
0
].
querySelector
(
'span'
).
textContent
;
};
}
describe
(
'loginControl'
,
function
()
{
before
(
function
()
{
angular
.
module
(
'app'
,
[])
.
directive
(
'loginControl'
,
require
(
'../login-control'
));
});
beforeEach
(
function
()
{
var
fakeServiceUrl
=
sinon
.
stub
().
returns
(
'someUrl'
);
var
fakeSettings
=
{
authDomain
:
'fakeDomain'
,
};
angular
.
mock
.
module
(
'app'
,
{
serviceUrl
:
fakeServiceUrl
,
settings
:
fakeSettings
,
});
});
function
createLoginControl
(
inputs
)
{
var
defaultInputs
=
{};
return
util
.
createDirective
(
document
,
'loginControl'
,
Object
.
assign
(
defaultInputs
,
inputs
));
}
context
(
'when user auth status is unknown'
,
function
()
{
it
(
'only shows the help menu option'
,
function
()
{
var
el
=
createLoginControl
({
auth
:
{
status
:
'unknown'
,
},
newStyle
:
true
,
});
var
pageObject
=
new
PageObject
(
el
);
assert
.
equal
(
pageObject
.
unknownLoginText
(),
'⋯'
);
assert
.
deepEqual
(
pageObject
.
menuLinks
(),
[
'Help'
]);
});
});
context
(
'when user is logged out'
,
function
()
{
it
(
'only shows the help menu option'
,
function
()
{
var
el
=
createLoginControl
({
auth
:
{
status
:
'logged-out'
,
},
newStyle
:
true
,
});
var
pageObject
=
new
PageObject
(
el
);
assert
.
deepEqual
(
pageObject
.
loginText
(),
[
'Sign up'
,
'Log in'
]);
assert
.
deepEqual
(
pageObject
.
menuLinks
(),
[
'Help'
]);
});
});
context
(
'when a H user is logged in'
,
function
()
{
it
(
'shows the complete list of menu options'
,
function
()
{
var
el
=
createLoginControl
({
auth
:
{
username
:
'someUsername'
,
status
:
'logged-in'
,
},
newStyle
:
true
,
});
var
pageObject
=
new
PageObject
(
el
);
assert
.
deepEqual
(
pageObject
.
menuLinks
(),
[
'someUsername'
,
'Account settings'
,
'Help'
,
'Log out'
]);
});
});
context
(
'when a third party user is logged in'
,
function
()
{
it
(
'shows the help menu option and the username'
,
function
()
{
var
el
=
createLoginControl
({
auth
:
{
userid
:
'acct:someUsername@anotherFakeDomain'
,
username
:
'someUsername'
,
status
:
'logged-in'
,
},
newStyle
:
true
,
});
var
pageObject
=
new
PageObject
(
el
);
assert
.
deepEqual
(
pageObject
.
menuLinks
(),
[
'Help'
]);
assert
.
deepEqual
(
pageObject
.
disabledMenuItems
(),
[
'someUsername'
]);
});
});
context
(
'old controls when a H user is logged in'
,
function
()
{
it
(
'shows the complete list of menu options'
,
function
()
{
var
el
=
createLoginControl
({
auth
:
{
username
:
'someUsername'
,
status
:
'logged-in'
,
},
newStyle
:
false
,
});
var
pageObject
=
new
PageObject
(
el
);
assert
.
deepEqual
(
pageObject
.
menuLinks
(),
[
'Account'
,
'Help'
,
'My Annotations'
,
'Log out'
]);
assert
.
include
(
pageObject
.
menuText
(),
'someUsername'
);
});
});
context
(
'old controls when user is logged out'
,
function
()
{
it
(
'shows the help and log in menu options'
,
function
()
{
var
el
=
createLoginControl
({
auth
:
{
status
:
'logged-out'
,
},
newStyle
:
false
,
});
var
pageObject
=
new
PageObject
(
el
);
assert
.
include
(
pageObject
.
menuText
(),
'Log in'
);
assert
.
deepEqual
(
pageObject
.
menuLinks
(),
[
'Help'
]);
});
});
context
(
'old controls when auth status is unknown'
,
function
()
{
it
(
'shows the help menu option'
,
function
()
{
var
el
=
createLoginControl
({
auth
:
{
status
:
'unknown'
,
},
newStyle
:
false
,
});
var
pageObject
=
new
PageObject
(
el
);
assert
.
equal
(
pageObject
.
menuText
(),
'⋯'
);
assert
.
deepEqual
(
pageObject
.
menuLinks
(),
[
'Help'
]);
});
});
});
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