Skip to content

Commit

Permalink
Corrected all tests in plots2_spec.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Souravirus committed Jul 10, 2018
1 parent ea48c5f commit 2747ff9
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 50 deletions.
20 changes: 1 addition & 19 deletions spec/javascripts/fixtures/index.html
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
<ul class="btn-group">

<li rel="tooltip" title="Helpful? Like it and get updates!" class="btn btn-default btn-sm btn-like" node-id="1" id="like-button-1"><span id="like-star-1" class="fa fa-star-o"></span> <span id="like-count-1">0</span></li>
<li rel="tooltip" title="Helpful? Like it and get updates!" class="btn btn-default btn-sm btn-like" node-id="1" id="like-button-1"><span id="like-star-1" class="fa fa-star-o"></span> <span id="like-count-1">0</span></li>

</ul>

<script>
jQuery(document).ready(function() {
// 304 cached response yields no data to insert, which is not useful
// jQuery.ajaxSetup({
// cache: false
// });

// grab the like count for this node; "/likes/node/11278/count"
// jQuery.getJSON("<%= like_count_path(node) %>", function (json) {
// // push like count into the Like button placeholder
// $('#like-count-<%= node.id %>').html(json);
// });

// <% if current_user %>
$('#like-button-1').on('click', clicknotliked);
// <% end %>
})
</script>
73 changes: 42 additions & 31 deletions spec/javascripts/plots2_spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//= require comment_expand
//= require like
var editor;

describe("Plots2", function() {
Expand All @@ -14,7 +16,6 @@ describe("Plots2", function() {

ajaxStub = sinon.stub($, 'ajax', function(object) {

var response;
if (object.url == '/likes/node/1/create') response = '4';
else response = 'none';

Expand All @@ -36,60 +37,70 @@ describe("Plots2", function() {

});

$(document).ready(function(){
$("#like-button-1").on('click', clicknotliked);
});

$('#like-button-1').trigger('click');

$("#like-button-1").click();
// should trigger the following and our ajaxSpy should return a fake response of "4":
var response;
/*var response;
jQuery.getJSON("/likes/node/1/create").done(function(data){
response = data;
});
});*/

// then triggering like.js code

expect(response).to.eql('4');
//expect($('#like-count-1').html()).to.eql('4'); // passing
//expect($('#like-star-1')[0].className).to.eql('fa fa-star');

expect($('#like-count-1').html()).to.eql('4'); // passing
expect($('#like-star-1')[0].className).to.eql('fa fa-star');
ajaxStub.restore();
});


xit("unlikes a request if already liked", function() {
it("unlikes a request if already liked", function() {

loadFixtures('unlike.html');
fixture.load('unlike.html');

ajaxSpy = spyOn($, "ajax").and.callFake(function(object) {
ajaxStub = sinon.stub($, 'ajax', function(object) {

if (object.url == '/likes/node/1/delete') response = "-1";
else response = 'none';
if (object.url == '/likes/node/1/delete') response = '-1';
else response = 'none';

var d = $.Deferred();
d.resolve(response);
d.reject(response);
return d.promise();
// check this if you have trouble faking a server response:

});
var d = $.Deferred();
if(response == '-1'){
d.resolve(response);
}
else{
d.reject(response);
}

$('#like-button-1').trigger('click');
return d.promise();

});

expect(response).toEqual('-1');
expect($('#like-count-1').html()).toEqual('0');
expect($('#like-star-1')[0].className).toEqual('fa fa-star-o');
$(document).ready(function(){
$("#like-button-1").on('click', clickliked);
});

$("#like-button-1").trigger('click');
expect($('#like-count-1').html()).to.eql('0');
expect($('#like-star-1')[0].className).to.eql('fa fa-star-o');
ajaxStub.restore();
});

xit("shows expand comment button with remaining comment count", function(){
loadFixtures('comment_expand.html');
it("shows expand comment button with remaining comment count", function(){
fixture.load('comment_expand.html');

$('#answer-0-expand').trigger('click');
expect($('#answer-0-expand').html()).toEqual('View 2 previous comments');
expand_comments(0);
expect($('#answer-0-expand').html()).to.eql('View 2 previous comments');

$('#answer-0-expand').trigger('click');
expect($('#answer-0-expand').css('display')).toEqual('none');
expand_comments(0);
expect($('#answer-0-expand').css('display')).to.eql('none');
});

xit("loads up i18n-js library properly", function() {
expect(I18n.t('js.dashboard.selected_updates')).toBe('Selected updates')
it("loads up i18n-js library properly", function() {
expect(I18n.t('js.dashboard.selected_updates')).to.eql('Selected updates')
});

});
1 change: 1 addition & 0 deletions spec/javascripts/spec_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//= require support/expect
//= require support/sinon
//= require support/chai
//= require jquery
// require support/chai-jq-0.0.7
// require support/your-support-file
//
Expand Down

0 comments on commit 2747ff9

Please sign in to comment.