Skip to content

Commit

Permalink
DEV: remove qunit rails fork and add a couple of async tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SamSaffron committed Apr 23, 2018
1 parent 0a44297 commit 54d1530
Show file tree
Hide file tree
Showing 9 changed files with 489 additions and 22 deletions.
1 change: 0 additions & 1 deletion Gemfile
Expand Up @@ -116,7 +116,6 @@ group :test, :development do
gem 'certified', require: false
# later appears to break Fabricate(:topic, category: category)
gem 'fabrication', '2.9.8', require: false
gem 'discourse-qunit-rails', require: 'qunit-rails'
gem 'mocha', require: false
gem 'rb-fsevent', require: RUBY_PLATFORM =~ /darwin/i ? 'rb-fsevent' : false
gem 'rb-inotify', '~> 0.9', require: RUBY_PLATFORM =~ /linux/i ? 'rb-inotify' : false
Expand Down
9 changes: 9 additions & 0 deletions app/controllers/qunit_controller.rb
@@ -0,0 +1,9 @@
class QunitController < ApplicationController
skip_before_action :check_xhr, :preload_json
layout false

# only used in test / dev
def index
raise Discourse::InvalidAccess.new if Rails.env.production?
end
end
15 changes: 15 additions & 0 deletions app/views/qunit/index.html.erb
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>QUnit Test Runner</title>
<%= stylesheet_link_tag "qunit" %>
<%= stylesheet_link_tag "test_helper" %>
<%= javascript_include_tag "qunit" %>
<%= javascript_include_tag "test_helper" %>
<%= csrf_meta_tags %>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
</body>
</html>
5 changes: 5 additions & 0 deletions config/application.rb
Expand Up @@ -75,6 +75,11 @@ def config.database_configuration

config.assets.paths += %W(#{config.root}/config/locales #{config.root}/public/javascripts)

if Rails.env == "development" || Rails.env == "test"
config.assets.paths << "#{config.root}/test/javascripts"
config.assets.paths << "#{config.root}/test/stylesheets"
end

# Allows us to skip minifincation on some files
config.assets.skip_minification = []

Expand Down
4 changes: 4 additions & 0 deletions config/routes.rb
Expand Up @@ -797,6 +797,10 @@

get "/themes/assets/:key" => "themes#assets"

if Rails.env == "test" || Rails.env == "development"
get "/qunit" => "qunit#index"
end

get "*url", to: 'permalinks#show', constraints: PermalinkConstraint.new

end
17 changes: 8 additions & 9 deletions test/javascripts/acceptance/composer-actions-test.js.es6
Expand Up @@ -7,21 +7,20 @@ acceptance('Composer Actions', {
}
});

QUnit.test('replying to post', assert => {
QUnit.test('replying to post', async assert => {
const composerActions = selectKit('.composer-actions');

visit('/t/internationalization-localization/280');
click('article#post_3 button.reply');

composerActions.expand();
await composerActions.expandAwait();

assert.equal(composerActions.rowByIndex(0).value(), 'reply_as_new_topic');
assert.equal(composerActions.rowByIndex(1).value(), 'reply_as_private_message');
assert.equal(composerActions.rowByIndex(2).value(), 'reply_to_topic');
assert.equal(composerActions.rowByIndex(3).value(), 'toggle_whisper');
assert.equal(composerActions.rowByIndex(4).value(), undefined);

andThen(() => {
assert.equal(composerActions.rowByIndex(0).value(), 'reply_as_new_topic');
assert.equal(composerActions.rowByIndex(1).value(), 'reply_as_private_message');
assert.equal(composerActions.rowByIndex(2).value(), 'reply_to_topic');
assert.equal(composerActions.rowByIndex(3).value(), 'toggle_whisper');
assert.equal(composerActions.rowByIndex(4).value(), undefined);
});
});

QUnit.test('replying to post - reply_as_private_message', assert => {
Expand Down
20 changes: 8 additions & 12 deletions test/javascripts/acceptance/users-test.js.es6
@@ -1,17 +1,13 @@
import { acceptance } from "helpers/qunit-helpers";
acceptance("User Directory");

QUnit.test("Visit Page", assert => {
visit("/users");
andThen(() => {
assert.ok($('body.users-page').length, "has the body class");
assert.ok(exists('.directory table tr'), "has a list of users");
});
QUnit.test("Visit Page", async assert => {
await visit("/users");
assert.ok($('body.users-page').length, "has the body class");
assert.ok(exists('.directory table tr'), "has a list of users");
});

QUnit.test("Visit All Time", assert => {
visit("/users?period=all");
andThen(() => {
assert.ok(exists('.time-read'), "has time read column");
});
});
QUnit.test("Visit All Time", async assert => {
await visit("/users?period=all");
assert.ok(exists('.time-read'), "has time read column");
});
4 changes: 4 additions & 0 deletions test/javascripts/helpers/select-kit-helper.js
Expand Up @@ -105,6 +105,10 @@ function selectKit(selector) { // eslint-disable-line no-unused-vars
};

return {
expandAwait: function() {
return expandSelectKit(selector);
},

expand: function() {
expandSelectKit(selector);
return selectKit(selector);
Expand Down

0 comments on commit 54d1530

Please sign in to comment.