Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing jasmine tests to teaspoon-mocha #2997

Merged
merged 27 commits into from
Jul 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
acc6670
Changed jasmine tests to teaspoon-mocha
Souravirus Jul 6, 2018
ecd50a2
Few corrections
Souravirus Jul 7, 2018
c4dd5af
Corrected inline_grids_spec.js
Souravirus Jul 7, 2018
fdd9939
Some changes in first test of plots2_spec.js
Souravirus Jul 8, 2018
d785ab3
Made the first expect work
Souravirus Jul 8, 2018
a9cce9c
made the click function above the jquery function in plots_spec
Souravirus Jul 8, 2018
f6731ed
Corrected the wikis_spec.js
Souravirus Jul 8, 2018
b763330
Corrected all tests in plots2_spec.js
Souravirus Jul 10, 2018
8ea25c6
Corrected the Gemfile
Souravirus Jul 10, 2018
e39a726
Running the rake test:all in Rakefile
Souravirus Jul 10, 2018
45b31a6
Corrected the rubocop offenses
Souravirus Jul 10, 2018
a394862
Corrected some identation problem in .travis.yml
Souravirus Jul 10, 2018
9b913b6
Passing the reports to dangerbot
Souravirus Jul 12, 2018
dc323c9
removed jasmine tasks from Rakefile and other modifications
Souravirus Jul 12, 2018
129eaaa
Modified the Dangerfile
Souravirus Jul 12, 2018
667d78a
Modified the travis.yml
Souravirus Jul 12, 2018
c1efddc
Changed the Dangerfile
Souravirus Jul 12, 2018
6935388
Shortened test for js failure
Souravirus Jul 12, 2018
b2342bd
Some mistake while updation
Souravirus Jul 12, 2018
0163625
Some changes in .travis.yml
Souravirus Jul 13, 2018
a12226b
Added junit-danger to Gemfile
Souravirus Jul 13, 2018
a0226f1
Modified the Dangerfile
Souravirus Jul 13, 2018
a1aca65
modification in Dangerfile
Souravirus Jul 14, 2018
d1ccec6
Modified Dangerfile
Souravirus Jul 14, 2018
9a93e4e
Modified the Dangerfile
Souravirus Jul 14, 2018
20da9c0
Written only junit.failures
Souravirus Jul 14, 2018
5593eff
Reverted the changes required for Dangerbot reporting
Souravirus Jul 20, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ test/reports/
node_modules
.byebug_history
vendor/bundle
spec/TEST-Teaspoon-Result.xml
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,13 @@ group :test, :development do
gem 'json_expressions'
gem 'minitest-reporters', '~> 1.1.19'
gem 'openssl', '~> 2.0.0.beta.1'
gem 'phantomjs'
gem 'rails-perftest'
gem 'rake', '~> 12.3.1'
gem 'rest-client'
gem 'rspec'
gem 'test-unit'
gem 'teaspoon-mocha'
gem 'timecop'
end

Expand Down
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,10 @@ GEM
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.3.13)
teaspoon (1.1.5)
railties (>= 3.2.5, < 6)
teaspoon-mocha (2.3.3)
teaspoon (>= 1.0.0)
term-ansicolor (1.6.0)
tins (~> 1.0)
test-unit (3.2.8)
Expand Down Expand Up @@ -501,6 +505,7 @@ DEPENDENCIES
openssl (~> 2.0.0.beta.1)
paperclip (~> 5.2.0)
passenger
phantomjs
php-serialize
progress_bar
rack-cors
Expand All @@ -526,6 +531,7 @@ DEPENDENCIES
scrypt (~> 3)
sidekiq
sqlite3
teaspoon-mocha
test-unit
therubyracer
timecop
Expand Down
13 changes: 3 additions & 10 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,16 @@ namespace :test do
t.test_files = FileList['test/**/*_test.rb']
end

desc "Run rails and jasmine tests"
desc "Run rails and teaspoon tests"
task :all => :environment do
require 'coveralls/rake/task'
Coveralls::RakeTask.new
if ENV['GENERATE_REPORT'] == 'true'
require 'ci/reporter/rake/test_unit'
Rake::Task["ci:setup:testunit"].execute
end
puts "Running jasmine tests headlessly"
Rake::Task["spec:javascript"].execute
puts "Running teaspoon tests headlessly"
Rake::Task["teaspoon"].execute
Rake::Task["coveralls:push"].execute
end

desc "Run rails and jasmine tests"
task :javascript do
puts "Running jasmine tests headlessly"
Rake::Task["spec:javascript"].execute
end

end
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>
20 changes: 6 additions & 14 deletions spec/javascripts/inline_grids_spec.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,31 @@
//= require application
//= require jasmine-jquery
//= require comment_expand

var editor;

fixture.preload("inline_grid.html");

describe("Inline grids", function() {

beforeEach(function() {

// for phantomjs running
jasmine.getFixtures().fixturesPath="../../spec/javascripts/fixtures";

// for in-browser running... still doesn't work
//jasmine.getFixtures().fixturesPath = 'assets/fixtures';
// preloadFixtures('inline_grids.html');
this.fixtures = fixture.load("inline_grid.html");

});


it("sends a like request when like button is clicked", function() {

loadFixtures('inline_grid.html');

expect($($('.notes-grid tr')[1]).find('td:first a').html()).toEqual('First post');
expect($($('.notes-grid tr')[1]).find('td:first a').html()).to.eql('First post');

$('table:first th:first a').trigger('click');

setTimeout(0, function() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jywarren, can I know why we used setTimeout here. Can't we test this without it?


expect($($('.notes-grid tr')[1]).find('td:first a').html()).toEqual('Third post');
expect($($('.notes-grid tr')[1]).find('td:first a').html()).to.eql('Third post');

setTimeout(0, function() {

$('table:first th:first a').trigger('click');
expect($($('.notes-grid tr')[1]).find('td:first a').html()).toEqual('First post');
expect($($('.notes-grid tr')[1]).find('td:first a').html()).to.eql('First post');

});

Expand Down
119 changes: 60 additions & 59 deletions spec/javascripts/plots2_spec.js
Original file line number Diff line number Diff line change
@@ -1,105 +1,106 @@
//= require application
//= require jasmine-jquery
//= require comment_expand

//= require like
var editor;

describe("Plots2", function() {

beforeEach(function() {

// for phantomjs running
jasmine.getFixtures().fixturesPath="../../spec/javascripts/fixtures";

// for in-browser running... still doesn't work
//jasmine.getFixtures().fixturesPath = 'assets/fixtures';
preloadFixtures('index.html', 'unlike.html', 'comment_expand.html');

jasmine.Ajax.install();
fixture.preload('index.html', 'unlike.html', 'comment_expand.html');

});

it("sends a like request when like button is clicked", function() {

afterEach(function(){

jasmine.Ajax.uninstall();

});
fixture.load('index.html');

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

it("sends a like request when like button is clicked", function() {
if (object.url == '/likes/node/1/create') response = '4';
else response = 'none';

loadFixtures('index.html');
// check this if you have trouble faking a server response:
if (response == '4'){
console.log('Faked response to:', object.url);
}
else console.log('Failed to fake response to:', object.url);

ajaxSpy = spyOn($, "ajax").and.callFake(function(object) {
var d = $.Deferred();
if(response == '4'){
d.resolve(response);
}
else{
d.reject(response);
}

if (object.url == '/likes/node/1/create') response = "4";
else response = 'none';
return d.promise();

// check this if you have trouble faking a server response:
if (response != 'none'){
console.log('Faked response to:', object.url);
console.log(response);
}
else console.log('Failed to fake response to:', object.url);

// http://stackoverflow.com/questions/13148356/how-to-properly-unit-test-jquerys-ajax-promises-using-jasmine-and-or-sinon
var d = $.Deferred();
d.resolve(response);
d.reject(response);
return d.promise();
});

$(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":
// jQuery.getJSON("/likes/node/1/create", {}, function() { ...
// then triggering like.js code
/*var response;
jQuery.getJSON("/likes/node/1/create").done(function(data){
response = data;
});*/

expect(response).toEqual('4');
expect($('#like-count-1').html()).toEqual('4'); // passing
expect($('#like-star-1')[0].className).toEqual('fa fa-star');
// then triggering like.js code

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


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);
}

return d.promise();

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

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();
});

it("shows expand comment button with remaining comment count", function(){
loadFixtures('comment_expand.html');
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');
});

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

});
41 changes: 41 additions & 0 deletions spec/javascripts/spec_helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Teaspoon includes some support files, but you can use anything from your own support path too.
//= require support/expect
//= require support/sinon
//= require support/chai
//= require jquery
// require support/chai-jq-0.0.7
// require support/your-support-file
//
// PhantomJS (Teaspoons default driver) doesn't have support for Function.prototype.bind, which has caused confusion.
// Use this polyfill to avoid the confusion.
//= require support/phantomjs-shims
//
// You can require your own javascript files here. By default this will include everything in application, however you
// may get better load performance if you require the specific files that are being used in the spec that tests them.
//= require application
//
// Deferring execution
// If you're using CommonJS, RequireJS or some other asynchronous library you can defer execution. Call
// Teaspoon.execute() after everything has been loaded. Simple example of a timeout:
//
// Teaspoon.defer = true
// setTimeout(Teaspoon.execute, 1000)
//
// Matching files
// By default Teaspoon will look for files that match _spec.{js,js.coffee,.coffee}. Add a filename_spec.js file in your
// spec path and it'll be included in the default suite automatically. If you want to customize suites, check out the
// configuration in teaspoon_env.rb
//
// Manifest
// If you'd rather require your spec files manually (to control order for instance) you can disable the suite matcher in
// the configuration and use this file as a manifest.
//
// For more information: http://github.com/modeset/teaspoon
//
// Chai
// If you're using Chai, you'll probably want to initialize your preferred assertion style. You can read more about Chai
// at: http://chaijs.com/guide/styles
//
window.assert = chai.assert;
window.expect = chai.expect;
window.should = chai.should();
1 change: 0 additions & 1 deletion spec/javascripts/tagging_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
//= require application
//= require jasmine-jquery
//= require tagging

var editor;
Expand Down
Loading