Skip to content

Commit

Permalink
adjust jsunit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Schiwon <[email protected]>
  • Loading branch information
blizzz committed Nov 1, 2017
1 parent 25aad12 commit 2b4b3b1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
8 changes: 6 additions & 2 deletions apps/comments/js/commentstabview.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,13 @@

_initAutoComplete: function($target) {
var s = this;
var limit = 10;
if(!_.isUndefined(OC.appConfig.comments)) {
limit = OC.appConfig.comments.maxAutoCompleteResults;
}
$target.atwho({
at: '@',
limit: OC.appConfig.comments.maxAutoCompleteResults,
limit: limit,
callbacks: {
remoteFilter: s._onAutoComplete,
highlighter: function (li) {
Expand Down Expand Up @@ -347,7 +351,7 @@
return;
}

var $form = $('.comment[data-id="' + model.id + '"] form');
var $form = this.$container.find('.comment[data-id="' + model.id + '"] form');
var $row = $form.closest('.comment');
var $target = $row.data('commentEl');
if(_.isUndefined($target)) {
Expand Down
15 changes: 8 additions & 7 deletions apps/comments/tests/js/commentstabviewSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ describe('OCA.Comments.CommentsTabView tests', function() {
expect($comment.find('.avatar[data-user=macbeth] ~ .contactsmenu-popover').length).toEqual(1);

expect($comment.find('.avatar[data-user=banquo]').length).toEqual(1);
expect($comment.find('.avatar-name-wrapper:last-child strong').text()).toEqual('Lord Banquo');
expect($comment.find('.avatar[data-user=banquo] ~ strong').text()).toEqual('Lord Banquo');
expect($comment.find('.avatar[data-user=banquo] ~ .contactsmenu-popover').length).toEqual(1);
});

Expand Down Expand Up @@ -239,7 +239,7 @@ describe('OCA.Comments.CommentsTabView tests', function() {
});

it('creates a new comment when clicking post button', function() {
view.$el.find('.message').val('New message');
view.$el.find('.message').text('New message');
view.$el.find('form').submit();

expect(createStub.calledOnce).toEqual(true);
Expand All @@ -253,7 +253,7 @@ describe('OCA.Comments.CommentsTabView tests', function() {
});
});
it('creates a new comment with mentions when clicking post button', function() {
view.$el.find('.message').val('New message @anotheruser');
view.$el.find('.message').text('New message @anotheruser');
view.$el.find('form').submit();

var createStubExpectedData = {
Expand Down Expand Up @@ -439,7 +439,7 @@ describe('OCA.Comments.CommentsTabView tests', function() {
var $formRow = view.$el.find('.newCommentRow.comment[data-id=1]');
expect($formRow.length).toEqual(1);

$formRow.find('textarea').val('modified message');
$formRow.find('div.message').text('modified message');
$formRow.find('form').submit();

expect(saveStub.calledOnce).toEqual(true);
Expand All @@ -451,8 +451,9 @@ describe('OCA.Comments.CommentsTabView tests', function() {
// simulate the fact that save sets the attribute
model.set('message', 'modified\nmessage');
saveStub.yieldTo('success', model);
view.collection.get(model);

expect(fetchStub.calledOnce).toEqual(true);
expect(fetchStub.called).toEqual(true);
fetchStub.yieldTo('success', model);

// original comment element is visible again
Expand All @@ -472,7 +473,7 @@ describe('OCA.Comments.CommentsTabView tests', function() {
var $formRow = view.$el.find('.newCommentRow.comment[data-id=3]');
expect($formRow.length).toEqual(1);

$formRow.find('textarea').val('modified\nmessage @anotheruser');
$formRow.find('div.message').text('modified\nmessage @anotheruser');
$formRow.find('form').submit();

expect(saveStub.calledOnce).toEqual(true);
Expand All @@ -485,7 +486,7 @@ describe('OCA.Comments.CommentsTabView tests', function() {
model.set('message', 'modified\nmessage @anotheruser');
saveStub.yieldTo('success', model);

expect(fetchStub.calledOnce).toEqual(true);
expect(fetchStub.called).toEqual(true);

// simulate the fact that fetch sets the attribute
model.set('mentions', {
Expand Down
2 changes: 2 additions & 0 deletions tests/karma.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ module.exports = function(config) {
srcFiles: [
// need to enforce loading order...
'apps/comments/js/app.js',
'apps/comments/js/vendor/Caret.js/dist/jquery.caret.min.js',
'apps/comments/js/vendor/At.js/dist/js/jquery.atwho.min.js',
'apps/comments/js/commentmodel.js',
'apps/comments/js/commentcollection.js',
'apps/comments/js/commentsummarymodel.js',
Expand Down

0 comments on commit 2b4b3b1

Please sign in to comment.