Merge branch 'master' of github.com:coralproject/talk into user-status

This commit is contained in:
Belen Curcio
2017-11-08 13:56:48 -03:00
24 changed files with 311 additions and 104 deletions
+7
View File
@@ -8,6 +8,11 @@ module.exports = {
},
getEmbedSection() {
this.waitForElementVisible('@iframe');
// Pause a bit to let iframe initialize in the hope that it'll
// fix https://www.browserstack.com/automate/builds/96419cf46e3d6376a36ae6d3f90934112df1ed91/sessions/224f1a1566c1c8c7859e2e76ece51862200f0173#automate_button
this.api.pause(200);
this.api.frame(iframeId);
this.expect.section('@embed').to.be.present;
return this.section.embed;
@@ -67,11 +72,13 @@ module.exports = {
embed: {
commands: [{
getProfileSection() {
this.waitForElementVisible('@profileTabButton');
this.click('@profileTabButton');
this.expect.section('@profile').to.be.present;
return this.section.profile;
},
getCommentsSection() {
this.waitForElementVisible('@commentsTabButton');
this.click('@commentsTabButton');
this.expect.section('@comments').to.be.present;
return this.section.comments;
+2 -4
View File
@@ -1,9 +1,9 @@
module.exports = {
'@tags': ['admin', 'login'],
beforeEach: (client) => {
client.resizeWindow(1024, 800);
},
},
'Admin logs in': (client) => {
const adminPage = client.page.admin();
const {testData: {admin}} = client.globals;
@@ -17,8 +17,6 @@ module.exports = {
.waitForElementVisible('@signInButton')
.click('@signInButton');
client.pause(3000);
adminPage
.waitForElementVisible('@moderationContainer');
},
+21 -7
View File
@@ -1,3 +1,5 @@
const SortedWindowHandler = require('../utils/SortedWindowHandler');
module.exports = {
'@tags': ['embedStream', 'login'],
'creates a new asset': (client) => {
@@ -18,16 +20,19 @@ module.exports = {
.navigate()
.getEmbedSection();
const windowHandler = new SortedWindowHandler(client);
embed
.waitForElementVisible('@signInButton')
.click('@signInButton');
client.pause(3000);
// Wait for window to be created
// https://www.browserstack.com/automate/builds/1ceccf4efb4683b7feb890f45a32b5922b40ed3f/sessions/17b1a79682bef2498cb0be86eac317a08c976b0a#automate_button
client.pause(200);
// Focusing on the Login PopUp
client.windowHandles((result) => {
const handle = result.value[1];
client.switchWindow(handle);
windowHandler.windowHandles((handles) => {
client.switchWindow(handles[1]);
});
const login = client.page.login();
@@ -45,10 +50,19 @@ module.exports = {
.waitForElementVisible('@loginButton')
.click('@loginButton');
// Give a tiny bit of time to let popup close.
client.pause(50);
if (client.capabilities.browserName === 'MicrosoftEdge') {
// More time for edge.
// https://www.browserstack.com/automate/builds/1ceccf4efb4683b7feb890f45a32b5922b40ed3f/sessions/7393dbfda8387e43b6d5851f359b0c07db414973
client.pause(1000);
}
// Focusing on the Embed Window
client.windowHandles((result) => {
const handle = result.value[0];
client.switchWindow(handle);
windowHandler.windowHandles((handles) => {
client.switchWindow(handles[0]);
});
},
'user posts a comment': (client) => {
+41
View File
@@ -0,0 +1,41 @@
/**
* SortedWindowHandler assists in making e2e tests more robust by returning
* deterministic window handles. An instance must be created before new windows
* are created and windowHandles must be called each time a window was created or
* closed.
*/
class SortedWindowHandler {
/**
* Constructor, must be called before new windows were created.
*/
constructor(client) {
this.client = client;
this.client.windowHandles((result) => {
this.handles = result.value;
if (this.handles.length > 2) {
throw new Error('SortedWindowHandler must be created before new windows were created.');
}
});
}
/**
* windowHandles will call given `callback` with an array of window handles.
*/
windowHandles(callback) {
this.client.windowHandles((result) => {
this.handles = this.handles.filter((handle) => result.value.includes(handle));
const remaining = result.value.filter((handle) => !this.handles.includes(handle));
if (remaining.length === 1) {
this.handles.push(remaining[0]);
}
if (remaining.length > 1) {
throw new Error('Cannot detect new window handle, because more than one windows was created.');
}
callback(this.handles);
});
}
}
module.exports = SortedWindowHandler;
+20 -1
View File
@@ -1,8 +1,11 @@
const UsersService = require('../../../services/users');
const SettingsService = require('../../../services/settings');
const MailerService = require('../../../services/mailer');
const chai = require('chai');
chai.use(require('chai-as-promised'));
const sinon = require('sinon');
chai.use(require('sinon-chai'));
const expect = chai.expect;
describe('services.UsersService', () => {
@@ -15,7 +18,7 @@ describe('services.UsersService', () => {
mockUsers = await UsersService.createLocalUsers([{
email: 'stampi@gmail.com',
username: 'Stampi',
password: '1Coral!-'
password: '1Coral!-',
}, {
email: 'sockmonster@gmail.com',
username: 'Sockmonster',
@@ -25,6 +28,12 @@ describe('services.UsersService', () => {
username: 'Marvel',
password: '3Coral!3'
}]);
sinon.spy(MailerService, 'sendSimple');
});
afterEach(() => {
MailerService.sendSimple.restore();
});
describe('#findById()', () => {
@@ -149,7 +158,11 @@ describe('services.UsersService', () => {
.then(() => UsersService.findById(mockUsers[0].id))
.then((user) => {
expect(user).to.have.property('status', 'ACTIVE');
})
.then(() => {
expect(MailerService.sendSimple).to.not.have.been.called;
});
});
});
@@ -188,6 +201,12 @@ describe('services.UsersService', () => {
.then(() => UsersService.findById(mockUsers[0].id))
.then((user) => {
expect(user).to.have.property('status', 'BANNED');
})
.then(() => {
expect(MailerService.sendSimple).to.have.been.calledWithMatch({
template: 'banned',
to: mockUsers[0].profiles[0].id
});
});
});