Merge pull request #29 from seripap/cleanup-tests

Cleanup tests
This commit is contained in:
Daniel Seripap 2016-02-27 12:06:11 -05:00
commit 5e67fad28f
4 changed files with 90 additions and 133 deletions

View File

@ -28,6 +28,7 @@ export default class Chat {
// Log a message // Log a message
log(message, options) { log(message, options) {
let html = options && options.html === true || false; let html = options && options.html === true || false;
let classNames = options && options.classNames ? options.classNames : '';
let $el; let $el;
let matchedUsernames = this.checkIfUsername(message.split(' ')); let matchedUsernames = this.checkIfUsername(message.split(' '));
@ -45,15 +46,15 @@ export default class Chat {
} }
if (options && options.error) { if (options && options.error) {
$el = $('<li class="log-error">').addClass('log').html('ERROR: ' + message); $el = $('<li class="log-error">').addClass(`log ${classNames}`).html('ERROR: ' + message);
} else if (options && options.warning) { } else if (options && options.warning) {
$el = $('<li class="log-warning">').addClass('log').html('WARNING: ' + message); $el = $('<li class="log-warning">').addClass(`log ${classNames}`).html('WARNING: ' + message);
} else if (options && options.notice) { } else if (options && options.notice) {
$el = $('<li class="log-info">').addClass('log').html('NOTICE: ' + message); $el = $('<li class="log-info">').addClass(`log ${classNames}`).html('NOTICE: ' + message);
} else if (options && options.info) { } else if (options && options.info) {
$el = $('<li class="log-info">').addClass('log').html(message); $el = $('<li class="log-info">').addClass(`log ${classNames}`).html(message);
} else { } else {
$el = $('<li>').addClass('log').html(message); $el = $('<li>').addClass(`log ${classNames}`).html(message);
} }
this.addMessageElement($el, options); this.addMessageElement($el, options);
@ -192,7 +193,11 @@ export default class Chat {
if (!warned) { if (!warned) {
warned = true; warned = true;
return this.log('Changing your username is currently in beta and your new username will be sent over the wire in plain text, unecrypted. This will be fixed in v2.0. If you really want to do this, type the command again.', {warning: true}); return this.log('Changing your username is currently in beta and your new username will be sent over the wire in plain text, unecrypted. This will be fixed in v2.0. If you really want to do this, type the command again.',
{
warning: true,
classNames: 'change-username-warning'
});
} }
this.darkwire.updateUsername(newUsername).then((socketData) => { this.darkwire.updateUsername(newUsername).then((socketData) => {

View File

@ -90,7 +90,10 @@ $(function() {
socket.on('user update', (data) => { socket.on('user update', (data) => {
darkwire.updateUser(data).then((oldUsername) => { darkwire.updateUser(data).then((oldUsername) => {
chat.log(oldUsername + ' <span>changed name to</span> ' + data.username); chat.log(oldUsername + ' <span>changed name to</span> ' + data.username,
{
classNames: 'changed-name'
});
renderParticipantsList(); renderParticipantsList();
}); });
}); });

View File

@ -42,6 +42,8 @@ describe('Darkwire', () => {
describe('Joining chat room', () => { describe('Joining chat room', () => {
before((client, done) => { before((client, done) => {
// Close modal
browser.click('#first-modal .modal-footer button');
browser.url((result) => { browser.url((result) => {
let urlSplit = result.value.split('/'); let urlSplit = result.value.split('/');
testingRoom = urlSplit[urlSplit.length - 1]; testingRoom = urlSplit[urlSplit.length - 1];
@ -52,6 +54,7 @@ describe('Darkwire', () => {
browser.windowHandles((result) => { browser.windowHandles((result) => {
browser.switchWindow(result.value[1], () => { browser.switchWindow(result.value[1], () => {
browser.execute((id) => { browser.execute((id) => {
// Open a new chat room at the same URL so we have 2 participants
window.open('http://localhost:3000/' + id, '_self'); window.open('http://localhost:3000/' + id, '_self');
}, [testingRoom], () => { }, [testingRoom], () => {
done(); done();
@ -69,95 +72,63 @@ describe('Darkwire', () => {
describe('Sending chat message', () => { describe('Sending chat message', () => {
before((client, done) => { before((client, done) => {
browser.waitForElementPresent('ul.users li:nth-child(2)', 5000, () => { browser
browser.setValue('textarea.inputMessage', ['Hello world!', browser.Keys.RETURN], () => { .waitForElementPresent('ul.users li:nth-child(2)', 5000)
.waitForElementPresent('textarea.inputMessage', 5000)
.setValue('textarea.inputMessage', ['Hello world!', browser.Keys.RETURN], () => {
done(); done();
}); });
}); });
});
it('Should send a message', () => { it('Should send a message', (client) => {
browser.windowHandles((result) => { browser.windowHandles((result) => {
browser.switchWindow(result.value[0], () => { browser.switchWindow(result.value[0], () => {
browser.waitForElementPresent('span.messageBody', 5000, () => { browser
browser.pause(2000); .waitForElementVisible('span.messageBody', 5000)
browser.assert.containsText('span.messageBody', 'Hello world!'); .assert.containsText('span.messageBody', 'Hello world!');
}); });
}); });
}); });
});
});
}); });
describe('Slash Commands', () => { describe('Slash Commands', () => {
before((client, done) => {
let url = 'http://localhost:3000/' + testingRoom;
browser.url(url, () => {
browser.windowHandles((result) => {
browser.switchWindow(result.value[0], () => {
browser.execute((id) => {
window.open('http://localhost:3000/' + id, '_self');
}, [testingRoom], () => {
done();
});
});
});
});
});
describe('/me', () => { describe('/me', () => {
before((client, done) => { before((client, done) => {
browser.windowHandles((result) => { browser
browser.switchWindow(result.value[0], () => { .waitForElementPresent('textarea.inputMessage', 5000)
browser.waitForElementPresent('ul.users li:nth-child(2)', 5000, () => { .clearValue('textarea.inputMessage')
browser.setValue('textarea.inputMessage', ['/me is no stranger to love', browser.Keys.RETURN], () => { .setValue('textarea.inputMessage', ['/me is no stranger to love', browser.Keys.RETURN])
.waitForElementVisible('.action span.messageBody', 5000, () => {
done(); done();
}); });
}); });
});
});
});
it('Should express an interactive action', () => { it('Should express an interactive action', () => {
browser.windowHandles((result) => {
browser.switchWindow(result.value[0], () => {
browser.waitForElementPresent('span.messageBody', 5000, () => {
browser.pause(5000);
browser.assert.containsText('.action span.messageBody', 'is no stranger to love'); browser.assert.containsText('.action span.messageBody', 'is no stranger to love');
}); });
});
});
});
}); });
describe('/nick', () => { describe('/nick', () => {
before((client, done) => { before((client, done) => {
browser.url('http://localhost:3000/' + testingRoom, () => { browser
browser.waitForElementPresent('ul.users li:nth-child(2)', 5000, () => { .waitForElementPresent('textarea.inputMessage', 5000)
browser.setValue('textarea.inputMessage', ['/nick rickAnsley', browser.Keys.RETURN], () => { .clearValue('textarea.inputMessage')
browser.waitForElementPresent('.log:last-child', 5000, () => { .setValue('textarea.inputMessage', ['/nick rickAnsley', browser.Keys.RETURN])
browser.setValue('textarea.inputMessage', ['/nick rickAnsley', browser.Keys.RETURN], () => { .waitForElementVisible('.change-username-warning', 5000)
.clearValue('textarea.inputMessage')
.setValue('textarea.inputMessage', ['/nick rickAnsley', browser.Keys.RETURN])
.waitForElementVisible('.log.changed-name', 5000, () => {
done(); done();
}); });
}); });
});
});
});
});
it('Should change username', () => { it('Should change username', () => {
browser.windowHandles((result) => { browser.assert.containsText('.log.changed-name', 'rickAnsley');
browser.switchWindow(result.value[3], () => {
browser.pause(5000);
browser.assert.containsText('.log:last-child', 'rickAnsley');
});
});
}); });
}); });
@ -167,13 +138,6 @@ describe('Darkwire', () => {
describe('Before file transfer: Image: Confirm sending', () => { describe('Before file transfer: Image: Confirm sending', () => {
before((client, done) => { before((client, done) => {
let url = 'http://localhost:3000/' + testingRoom;
browser.url(url, () => {
browser.windowHandles((result) => {
browser.switchWindow(result.value[0], () => {
browser.execute((id) => {
window.open('http://localhost:3000/' + id, '_self');
}, [testingRoom], () => {
browser.waitForElementPresent('#send-file', 5000, () => { browser.waitForElementPresent('#send-file', 5000, () => {
browser.execute(() => { browser.execute(() => {
$('input[name="fileUploader"]').show(); $('input[name="fileUploader"]').show();
@ -187,37 +151,23 @@ describe('Darkwire', () => {
}); });
}); });
}); });
});
});
});
});
it('Should prompt user confirmation', () => { it('Should prompt user confirmation', () => {
browser.windowHandles((result) => { browser
browser.switchWindow(result.value[0], () => { .waitForElementVisible('span.messageBody .file-presend-prompt', 5000)
browser.waitForElementPresent('span.messageBody', 5000, () => { .assert.containsText('span.messageBody .file-presend-prompt', 'You are about to send ricky.jpg to all participants in this chat. Confirm | Cancel');
browser.pause(5000);
browser.assert.containsText('span.messageBody', 'You are about to send ricky.jpg to all participants in this chat. Confirm | Cancel');
});
});
});
}); });
it('Should show sent confirmation message', () => { it('Should show sent confirmation message', () => {
browser.windowHandles((result) => { browser
browser.switchWindow(result.value[0], () => { .waitForElementVisible('a.file-trigger-confirm', 5000)
browser.waitForElementPresent('a.file-trigger-confirm', 5000, () => { .click('a.file-trigger-confirm')
browser.click('a.file-trigger-confirm', () => { .waitForElementNotPresent('a.file-trigger-confirm', 5000)
browser.waitForElementNotPresent('a.file-trigger-confirm', 5000, () => { .assert.containsText('.message .file-presend-prompt', 'Sent ricky.jpg');
browser.assert.containsText('span.messageBody', 'Sent ricky.jpg');
});
});
});
}); });
}); });
}); });
}); });
});
}); });

View File

@ -1 +0,0 @@
($('#fileInput').show)();