Skip to content

Commit

Permalink
Adding tests for Record view, request file, search
Browse files Browse the repository at this point in the history
  • Loading branch information
SarahBA committed Jun 21, 2017
1 parent 03242eb commit 22718b2
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 52 deletions.
6 changes: 4 additions & 2 deletions webui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"test": "jest"
},
"jest": {
"modulePathIgnorePatterns": ["common.js"]
"modulePathIgnorePatterns": [
"common.js"
]
},
"devDependencies": {
"babel-core": "^6.2.1",
Expand All @@ -37,8 +39,8 @@
"moment": "^2.13.0",
"pluralize": "^1.2.1",
"react": "^15.5.0",
"react-dom": "^15.5.0",
"react-addons-shallow-compare": "^15.5.0",
"react-dom": "^15.5.0",
"react-router": "^2.1.1",
"react-toggle": "^2.2.0",
"react-widgets": "^3.2.4",
Expand Down
27 changes: 25 additions & 2 deletions webui/src/__tests__/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,31 @@ export async function assertPageContains(page, text) {

export async function assertElementText(page, selector, text) {
const fn = (selector) => {
document.querySelector(selector).innerText
document.querySelectorAll(selector).innerText
};
let elementText = await page.evaluate(fn, selector);
return expect(elementText == text);
await expect(elementText == text);
}

export async function login(page) {
await page.wait('#header-navbar-collapse > .user > li > a')
.click('#header-navbar-collapse > .user > li > a');

await expect(page.url() == B2ACCESS_AUTH_URL);

await page.wait('#AuthenticationUI\\.username');
await assertPageContains(page, "Login to UNITY OAuth2 Authorization Server");

await page.type('#AuthenticationUI\\.username', USER_NAME)
.type('#WebPasswordRetrieval\\.password', USER_PASS)
.click('#AuthenticationUI\\.authnenticateButton')
.wait('#IdpButtonsBar\\.confirmButton')
.click('#IdpButtonsBar\\.confirmButton');

await expect(await page.title() == 'B2SHARE');

await page.wait('#header-navbar-collapse a');

await assertElementText(page, '#header-navbar-collapse > .user > li > a', USER_EMAIL);
// await page.end();
}
55 changes: 29 additions & 26 deletions webui/src/__tests__/homepage.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
import Nightmare from 'nightmare';
import { B2ACCESS_AUTH_URL, B2SHARE_URL, USER_NAME, USER_PASS, USER_EMAIL,
nightmareConfig, step, print_obj, assertPageContains, assertElementText } from './common';
nightmareConfig, step, print_obj, assertPageContains, assertElementText, login } from './common';


describe('Homepage', function () {
describe('Homepage', function () {
test('well formed homepage', async function () {
let page = Nightmare(nightmareConfig).goto(B2SHARE_URL);
expect(await page.title() == 'B2SHARE');

await expect(await page.title() == 'B2SHARE');
await page.wait('#header-navbar-collapse a');
await page.wait('#page .home-page .record a');
await page.end();
});
});

describe('Login', function () {
test('user can login', async function () {
let page = Nightmare(nightmareConfig).goto(B2SHARE_URL);

await page.wait('#header-navbar-collapse > .user > li > a')
.click('#header-navbar-collapse > .user > li > a');

await expect(page.url() == B2ACCESS_AUTH_URL);

await page.wait('#AuthenticationUI\\.username');
await assertPageContains(page, "Login to UNITY OAuth2 Authorization Server");

await page.type('#AuthenticationUI\\.username', USER_NAME)
.type('#WebPasswordRetrieval\\.password', USER_PASS)
.click('#AuthenticationUI\\.authnenticateButton')
.wait('#IdpButtonsBar\\.confirmButton')
.click('#IdpButtonsBar\\.confirmButton');

expect(await page.title() == 'B2SHARE');

await page.wait('#header-navbar-collapse a');
describe('Login', function () {
test('user can login', async function() {
let page = Nightmare(nightmareConfig).goto(B2SHARE_URL);
try {
await login(page);
// page.end();
} catch(e){
console.error(e);
}
});
});

await assertElementText(page, '#header-navbar-collapse > .user > li > a', USER_EMAIL);
describe('User profile', function () {
test('user can navigate to the profile page', async function() {
let page = Nightmare(nightmareConfig).goto(B2SHARE_URL);
try {
await login(page);
await page.click('#header-navbar-collapse .user .dropdown .dropdown-toggle')
.wait('#header-navbar-collapse .user li a .dropdown-menu li a')
.click('#header-navbar-collapse .user li a .dropdown-menu li a');
// page.end();
} catch(e){
console.error(e);
}
});
});


85 changes: 85 additions & 0 deletions webui/src/__tests__/published_record.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import Nightmare from 'nightmare';
import { B2ACCESS_AUTH_URL, B2SHARE_URL, USER_NAME, USER_PASS, USER_EMAIL,
nightmareConfig, step, print_obj, assertPageContains, assertElementText, login } from './common';

describe('A published record', function () {
test('can be loaded and download the file', async function () {
let page = Nightmare(nightmareConfig).goto(B2SHARE_URL+'/records/47077e3c4b9f4852a40709e338ad4620');
await expect(await page.title() == 'B2SHARE');

await assertElementText(page, '.col-lg-6 .well .fileList .file .row .col-sm-9 ', 'myfile'); //file name exists
await assertElementText(page, '.col-lg-6 .well .fileList .file .row .col-sm-3 ', '9 B'); // file size exists

await page.wait('.col-lg-6 .well .fileList .file .row .col-sm-9 > a')
.click('.col-lg-6 .well .fileList .file .row .col-sm-9 > a')
// .end()
.then(function (result) {
console.log(result)
})
.catch(function (error) {
console.error('Error:', error);
});
});


test('have basic metadata like open access, file size, file name', async function(){
let page = Nightmare(nightmareConfig).goto(B2SHARE_URL+'/records/47077e3c4b9f4852a40709e338ad4620');

await page.wait('.col-lg-6 .well .col-sm-12.list-unstyled li .col-sm-8') //Open Access
.evaluate(function () {
return document.querySelector('.col-lg-6 .well .col-sm-12.list-unstyled li .col-sm-8').innerText
})
.then(function(el) {
expect(el).toEqual('True');
})

await page.wait('.col-lg-6 .well .fileList .file .row .col-sm-9 a') // File Name
.evaluate(function () {
console.log("value = ", document.querySelector('.col-lg-6 .well .fileList .file .row .col-sm-9 a').innerText)
return document.querySelector('.col-lg-6 .well .fileList .file .row .col-sm-9 a').innerText
})
.then(function(el) {
expect(el).toEqual('myfile');
})

await page.wait('.col-lg-6 .well .fileList .file .row .col-sm-9 a') // File size
.evaluate(function () {
console.log("value = ", document.querySelector('.col-lg-6 .well .fileList .file .row .col-sm-3').innerText)
return document.querySelector('.col-lg-6 .well .fileList .file .row .col-sm-3').innerText
})
.then(function(el) {
expect(el.replace( /\s/g, "")).toEqual('9B');
})
});
});

// Should move it after creating a new record with restrict access!
// describe('A restricted published record', function () {
// test('have open access equal to false, have a request file link and send the request file form', async function(){
// let page = Nightmare(nightmareConfig).goto(B2SHARE_URL+'/records/5e025f1af344444498ec555e7732fc7c');
// await page.wait('.col-lg-6 .well .col-sm-12.list-unstyled li .col-sm-8')
// .evaluate(function () {
// return document.querySelector('.col-lg-6 .well .col-sm-12.list-unstyled li .col-sm-8').innerText
// })
// .then(function(el) {
// expect(el).toEqual('False');
// });

// await page.wait('.large-record .row .col-lg-6 .well a')
// .click('.large-record .row .col-lg-6 .well a');

// await expect(page.url() == B2SHARE_URL+'/records/5e025f1af344444498ec555e7732fc7c/accessrequest');

// await page.type(' .form-horizontal .row .col-sm-8 > textarea ', 'message')
// .type(' .form-horizontal .row .col-sm-8 > input#name', 'firstname lastname')
// .type(' .form-horizontal .row .col-sm-8 > input#affiliation', 'affiliation')
// .type(' .form-horizontal .row .col-sm-8 > input#email', '[email protected]')
// .type(' .form-horizontal .row .col-sm-8 > input#address', 'address')
// .type(' .form-horizontal .row .col-sm-8 > input#city', 'Stockholm')
// .type(' .form-horizontal .row .col-sm-8 > select#country', 'Sweden')
// .type(' .form-horizontal .row .col-sm-8 > input#zipcode', '12345')
// .type(' .form-horizontal .row .col-sm-8 > input#phone', '6392615304')
// .click(' .form-horizontal .row .col-sm-offset-2.col-sm-8 .btn.btn-primary.btn-default.btn-block')
// });
// });

36 changes: 36 additions & 0 deletions webui/src/__tests__/search_in_records.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import Nightmare from 'nightmare';
import { B2ACCESS_AUTH_URL, B2SHARE_URL, USER_NAME, USER_PASS, USER_EMAIL,
nightmareConfig, step, print_obj, assertPageContains, assertElementText, login } from './common';

describe('Searching in the records', function () {
test('for a common term', async function() {
let queries = ['paper','ChiP-seq','Daniel Zeman', 'RDA', 'wrong_query'];

for (let query of queries) {
let page = Nightmare(nightmareConfig).goto(B2SHARE_URL);
await page.wait('#header-navbar-collapse form .nav-search .form-control')
.type('#header-navbar-collapse form .nav-search .form-control', query)
.click('#header-navbar-collapse form .nav-search .input-group-btn button.btn.btn-primary')

await expect(page.url() == B2SHARE_URL+'/records/?q='+query+'#');
switch(query){
case 'wrong_query':
await page.evaluate(()=>document.body.textContent)
.then(function(body){
expect(body).toContain('No results');
})
page.end();
break;
default:
await page.wait('.record.col-lg-12')
.evaluate(()=>document.body.textContent)
.then(function(body){
expect(body).toContain('1 - 1 of 1 results');
})
page.end();
}

}
});

});
18 changes: 9 additions & 9 deletions webui/src/components/accessrequest.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const AccessRequest = React.createClass({
<label forHtml='message'>Access request message</label>
</div>
<div className=" col-sm-8" >
<textarea ref={(ref) => this.message = ref} name='message' className="form-control" type='textarea' rows="4" cols="50" required/>
<textarea ref={(ref) => this.message = ref} id="message" name='message' className="form-control" type='textarea' rows="4" cols="50" required/>
</div>
</div>

Expand All @@ -71,7 +71,7 @@ export const AccessRequest = React.createClass({
<label forHtml='name'>Your full name</label>
</div>
<div className=" col-sm-8" >
<input ref={(ref) => this.name = ref} name='name' className="form-control" type='text' required />
<input ref={(ref) => this.name = ref} id='name' name='name' className="form-control" type='text' required />
</div>
</div>

Expand All @@ -80,7 +80,7 @@ export const AccessRequest = React.createClass({
<label forHtml='affiliation'>Your affiliation</label>
</div>
<div className=" col-sm-8" >
<input ref={(ref) => this.affiliation = ref} name='affiliation' className="form-control" type='text' required />
<input ref={(ref) => this.affiliation = ref} id='affiliation' name='affiliation' className="form-control" type='text' required />
</div>
</div>

Expand All @@ -89,7 +89,7 @@ export const AccessRequest = React.createClass({
<label forHtml='email'>Your email</label>
</div>
<div className=" col-sm-8" >
<input ref={(ref) => this.email = ref} name='email' className="form-control" type='email' required />
<input ref={(ref) => this.email = ref} id='email' name='email' className="form-control" type='email' required />
</div>
</div>

Expand All @@ -98,7 +98,7 @@ export const AccessRequest = React.createClass({
<label forHtml='address'>Your address</label>
</div>
<div className=" col-sm-8" >
<input ref={(ref) => this.address = ref} name='address' className="form-control" type='text' required />
<input ref={(ref) => this.address = ref} id='address' name='address' className="form-control" type='text' required />
</div>
</div>

Expand All @@ -107,7 +107,7 @@ export const AccessRequest = React.createClass({
<label forHtml='city'>City</label>
</div>
<div className=" col-sm-8" >
<input ref={(ref) => this.city = ref} name='city' className="form-control" type='text' required />
<input ref={(ref) => this.city = ref} id='city' name='city' className="form-control" type='text' required />
</div>
</div>

Expand All @@ -116,7 +116,7 @@ export const AccessRequest = React.createClass({
<label forHtml='country'>Country</label>
</div>
<div className=" col-sm-8" >
<select ref={(ref) => this.country = ref} name='country' className="form-control" defaultValue="" required >
<select ref={(ref) => this.country = ref} id='country' name='country' className="form-control" defaultValue="" required >
<option value=""> Choose country </option>
<option value="Afghanistan" >Afghanistan</option>
<option value="Albania" >Albania</option>
Expand Down Expand Up @@ -321,7 +321,7 @@ export const AccessRequest = React.createClass({
<label forHtml='zipcode'>Zip code</label>
</div>
<div className=" col-sm-8" >
<input ref={(ref) => this.zipcode = ref} name='zipcode' className="form-control" type='text' required />
<input ref={(ref) => this.zipcode = ref} id='zipcode' name='zipcode' className="form-control" type='text' required />
</div>
</div>

Expand All @@ -330,7 +330,7 @@ export const AccessRequest = React.createClass({
<label forHtml='phone'>Your phone number</label>
</div>
<div className=" col-sm-8" >
<input ref={(ref) => this.phone = ref} name="phone" type='text' pattern="[0-9]*" className="form-control" title= "Numbers Only" required />
<input ref={(ref) => this.phone = ref} id='phone' name="phone" type='text' pattern="[0-9]*" className="form-control" title= "Numbers Only" required />
</div>
</div>

Expand Down
Loading

0 comments on commit 22718b2

Please sign in to comment.