mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
Basic Alfresco login webcomponent tests
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
<link rel="import" href="../../bower_components/polymer/polymer.html">
|
<link rel="import" href="../polymer/polymer.html">
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
An element providing a solution to the login.
|
An element providing a solution to the login.
|
||||||
@@ -10,8 +10,8 @@ Example:
|
|||||||
@demo
|
@demo
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<link rel="import" href="../../bower_components/paper-input/paper-input.html">
|
<link rel="import" href="../paper-input/paper-input.html">
|
||||||
<link rel="import" href="../../bower_components/paper-button/paper-button.html">
|
<link rel="import" href="../paper-button/paper-button.html">
|
||||||
|
|
||||||
<dom-module id="alfresco-login">
|
<dom-module id="alfresco-login">
|
||||||
|
|
||||||
@@ -72,13 +72,20 @@ Example:
|
|||||||
ready: function(){
|
ready: function(){
|
||||||
},
|
},
|
||||||
|
|
||||||
|
fireSubmit: function(token) {
|
||||||
|
this.fire("submit", {ticket: token});
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Login Alfesco
|
* Login Alfesco
|
||||||
*
|
*
|
||||||
* @param {object}
|
* @param {object}
|
||||||
*/
|
*/
|
||||||
_submit: function() {
|
_submit: function(event) {
|
||||||
|
if(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
@@ -103,6 +110,7 @@ Example:
|
|||||||
}
|
}
|
||||||
|
|
||||||
xhr.onload = function(e) {
|
xhr.onload = function(e) {
|
||||||
|
e.preventDefault();
|
||||||
if (xhr.status === 200) {
|
if (xhr.status === 200) {
|
||||||
var token = '';
|
var token = '';
|
||||||
if (xhr.responseXML) {
|
if (xhr.responseXML) {
|
||||||
@@ -111,7 +119,7 @@ Example:
|
|||||||
token = JSON.parse(xhr.responseText).data.ticket;
|
token = JSON.parse(xhr.responseText).data.ticket;
|
||||||
}
|
}
|
||||||
if (token) {
|
if (token) {
|
||||||
self.fire("submit", {ticket: token});
|
self.fireSubmit(token);
|
||||||
} else {
|
} else {
|
||||||
self.fire("error", {error:'Token error'});
|
self.fire("error", {error:'Token error'});
|
||||||
}
|
}
|
||||||
@@ -120,6 +128,7 @@ Example:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
xhr.send(parameterJson);
|
xhr.send(parameterJson);
|
||||||
|
return xhr;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
32
demo-shell-ng2/webcomponents/alfresco-login/bower.json
Normal file
32
demo-shell-ng2/webcomponents/alfresco-login/bower.json
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
{
|
||||||
|
"name": "alfresco-login",
|
||||||
|
"description": "Provide the Alfresco login .",
|
||||||
|
"keywords": [
|
||||||
|
"web-component",
|
||||||
|
"web-components",
|
||||||
|
"polymer",
|
||||||
|
"alfresco"
|
||||||
|
],
|
||||||
|
"main": "alfresco-login.html",
|
||||||
|
"license": "MIT",
|
||||||
|
"ignore": [
|
||||||
|
"/.*",
|
||||||
|
"/test/",
|
||||||
|
"/demo/",
|
||||||
|
"/bower_components/"
|
||||||
|
],
|
||||||
|
"dependencies": {
|
||||||
|
"polymer": "Polymer/polymer#^1.0.0",
|
||||||
|
"paper-input": "~1.1.10"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"iron-component-page": "polymerelements/iron-component-page#^1.0.0",
|
||||||
|
"iron-image": "polymerelements/iron-image#^1.0.0",
|
||||||
|
"paper-styles": "polymerelements/paper-styles#^1.0.0",
|
||||||
|
"test-fixture": "polymerelements/test-fixture#^1.0.0",
|
||||||
|
"web-component-tester": "^4.0.0",
|
||||||
|
"webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0"
|
||||||
|
},
|
||||||
|
"_originalSource": "alfresco-login",
|
||||||
|
"_direct": true
|
||||||
|
}
|
@@ -5,7 +5,7 @@
|
|||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
|
||||||
<script src="bower_components/webcomponentsjs/webcomponents-lite.js"></script>
|
<script src="../webcomponentsjs/webcomponents-lite.js"></script>
|
||||||
<link rel="import" href="alfresco-login.html">
|
<link rel="import" href="alfresco-login.html">
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
79
demo-shell-ng2/webcomponents/alfresco-login/test/index.html
Normal file
79
demo-shell-ng2/webcomponents/alfresco-login/test/index.html
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<script src="../bower_components/webcomponentsjs/webcomponents-lite.js"></script>
|
||||||
|
<script src="../bower_components/web-component-tester/browser.js"></script>
|
||||||
|
<!-- import the element to test -->
|
||||||
|
<link rel="import" href="../alfresco-login.html">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<!-- use the document as a place to set up your fixtures -->
|
||||||
|
<test-fixture id="alfresco-login-fixture">
|
||||||
|
<template>
|
||||||
|
<alfresco-login>
|
||||||
|
</alfresco-login>
|
||||||
|
</template>
|
||||||
|
</test-fixture>
|
||||||
|
<script>
|
||||||
|
suite('<alfresco-login>', function() {
|
||||||
|
var myEl;
|
||||||
|
setup(function() {
|
||||||
|
myEl = fixture('alfresco-login-fixture');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('defines the "method" property', function() {
|
||||||
|
assert.equal(myEl.method, 'GET');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('fires submit', function(done) {
|
||||||
|
myEl.addEventListener('submit', function(event) {
|
||||||
|
assert.equal(event.detail.ticket, 'TICKET_mock');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
myEl.fireSubmit('TICKET_mock');
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
suite('<alfresco-login-submit>', function() {
|
||||||
|
var ajax;
|
||||||
|
var request;
|
||||||
|
var server;
|
||||||
|
var responseHeaders = {
|
||||||
|
json: { 'Content-Type': 'application/json' }
|
||||||
|
};
|
||||||
|
setup(function() {
|
||||||
|
server = sinon.fakeServer.create();
|
||||||
|
server.respondWith(
|
||||||
|
'GET',
|
||||||
|
/\/alfresco.*/, [
|
||||||
|
200,
|
||||||
|
responseHeaders.json,
|
||||||
|
'{ "data": { "ticket":"TICKET_mock" } }'
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
teardown(function() {
|
||||||
|
server.restore();
|
||||||
|
});
|
||||||
|
suite('when making simple GET requests for JSON', function() {
|
||||||
|
setup(function() {
|
||||||
|
// get fresh instance of iron-ajax before every test
|
||||||
|
ajax = fixture('alfresco-login-fixture');
|
||||||
|
});
|
||||||
|
test('has sane defaults that love you', function() {
|
||||||
|
request = ajax._submit();
|
||||||
|
server.respond();
|
||||||
|
expect(request.response).to.be.ok;
|
||||||
|
expect(request.response).to.be.equal('{ "data": { "ticket":"TICKET_mock" } }');
|
||||||
|
});
|
||||||
|
test('has the correct xhr method', function() {
|
||||||
|
request = ajax._submit();
|
||||||
|
expect(request.method).to.be.equal('GET');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Reference in New Issue
Block a user