Scaffold for new Wizard - Rails / Ember / Tests

This commit is contained in:
Robin Ward 2016-08-24 14:35:07 -04:00
parent 6070939daa
commit 0471ad393c
23 changed files with 247 additions and 6 deletions

View File

@ -0,0 +1,2 @@
window.Discourse = {};
Discourse.SiteSettings = {};

View File

@ -1,8 +1,3 @@
window.ENV = { };
window.Discourse = {};
Discourse.SiteSettings = {};
window.EmberENV = window.EmberENV || {};
window.EmberENV['FORCE_JQUERY'] = true;

View File

@ -1,5 +1,6 @@
//= require logster
//= require ./env
//= require ./discourse-objects
//= require probes.js
//= require template_include.js

View File

@ -0,0 +1,6 @@
//= require wizard/resolver
//= require wizard/router
//= require wizard/wizard
//= require_tree ./wizard/templates
//= require_tree ./wizard/routes
//= require_tree ./wizard/controllers

View File

@ -0,0 +1,2 @@
//= require env
//= require template_include.js

View File

@ -0,0 +1,3 @@
export default Ember.Controller.extend({
step: null,
});

View File

@ -0,0 +1,26 @@
function resolveType(parsedName) {
const entries = requirejs.entries;
const named = `wizard/${parsedName.type}s/${parsedName.fullNameWithoutType}`;
if (entries[named]) {
const module = require(named, null, null, true /* force sync */);
return module.default;
}
}
export default Ember.DefaultResolver.extend({
resolveRoute(parsedName) {
return resolveType(parsedName) || this._super(parsedName);
},
resolveController(parsedName) {
return resolveType(parsedName) || this._super(parsedName);
},
resolveTemplate(parsedName) {
const templates = Ember.TEMPLATES;
const withoutType = parsedName.fullNameWithoutType;
return templates[`wizard/templates/${withoutType}`] || this._super(parsedName);
}
});

View File

@ -0,0 +1,7 @@
const Router = Ember.Router.extend();
Router.map(function () {
this.route('step', { path: '/step/:step_id' });
});
export default Router;

View File

@ -0,0 +1,5 @@
export default Ember.Route.extend({
beforeModel() {
this.replaceWith('step', 'welcome');
}
});

View File

@ -0,0 +1,12 @@
export default Ember.Route.extend({
model(params) {
return {
id: params.step_id,
title: "You're a wizard harry!"
};
},
setupController(controller, model) {
controller.set('step', model);
}
});

View File

@ -0,0 +1,7 @@
<div class='wizard-column'>
<div class='wizard-column-contents'>
Discourse!
{{outlet}}
</div>
</div>

View File

@ -0,0 +1,3 @@
<div class='wizard-step'>
{{step.title}}
</div>

View File

@ -0,0 +1,10 @@
module("Acceptance: wizard");
test("Wizard loads", assert => {
visit("/");
andThen(() => {
assert.ok(exists('.wizard-column-contents'));
assert.equal(currentPath(), 'steps');
});
});

View File

@ -0,0 +1,40 @@
/*global document, sinon, QUnit, Logster */
//= require env
//= require jquery.debug
//= require loader
//= require jquery.debug
//= require handlebars
//= require ember.debug
//= require ember-template-compiler
//= require ember-qunit
//= require wizard-application
//= require helpers/assertions
//= require_tree ./acceptance
// Trick JSHint into allow document.write
var d = document;
d.write('<div id="ember-testing-container"><div id="ember-testing"></div></div>');
d.write('<style>#ember-testing-container { position: absolute; background: white; bottom: 0; right: 0; width: 640px; height: 384px; overflow: auto; z-index: 9999; border: 1px solid #ccc; } #ember-testing { zoom: 50%; }</style>');
if (window.Logster) {
Logster.enabled = false;
} else {
window.Logster = { enabled: false };
}
var wizard = require('wizard/wizard').default.create({
rootElement: '#ember-testing'
});
wizard.setupForTesting();
wizard.injectTestHelpers();
QUnit.testDone(function() {
wizard.reset();
});
Object.keys(requirejs.entries).forEach(function(entry) {
if ((/\-test/).test(entry)) {
require(entry, null, null, true);
}
});

View File

@ -0,0 +1,8 @@
import Resolver from 'wizard/resolver';
import Router from 'wizard/router';
export default Ember.Application.extend({
rootElement: '#wizard-main',
Resolver,
Router
});

View File

@ -0,0 +1,31 @@
@import "vendor/normalize";
@import "vendor/font_awesome/font-awesome";
body {
background-color: rgb(231,238,247);
background-image: url('/images/wizard/bubbles.png');
background-repeat: repeat;
background-position: left top;
}
.wizard-column {
background-color: white;
border-radius: 2px;
box-shadow: 0 5px 10px rgba(0,0,0,0.2);
box-sizing: border-box;
margin: 0.75rem auto;
padding: 0;
max-width: 700px;
min-width: 280px;
width: 100%;
border: 1px solid #ccc;
.wizard-column-contents {
padding: 1em;
h1 {
margin: 0;
}
}
}

View File

@ -0,0 +1,16 @@
class Wizard::WizardController < ApplicationController
before_filter :ensure_logged_in
before_filter :ensure_staff
skip_before_filter :check_xhr, :preload_json
layout false
def index
end
def qunit
end
end

View File

@ -0,0 +1,21 @@
<html>
<head>
<%= stylesheet_link_tag 'wizard' %>
<%= javascript_include_tag 'wizard-vendor' %>
<%= javascript_include_tag 'ember_jquery' %>
<%= javascript_include_tag 'wizard-application' %>
</head>
<body>
<div id='wizard-main'>
</div>
<script>
(function() {
require('wizard/wizard').default.create();
})();
</script>
</body>
</html>

View File

@ -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 "wizard/test/test_helper" %>
<%= csrf_meta_tags %>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
</body>
</html>

View File

@ -72,7 +72,8 @@ module Discourse
config.assets.precompile += ['vendor.js', 'common.css', 'desktop.css', 'mobile.css',
'admin.js', 'admin.css', 'shiny/shiny.css', 'preload-store.js.es6',
'browser-update.js', 'embed.css', 'break_string.js', 'ember_jquery.js',
'pretty-text-bundle.js']
'pretty-text-bundle.js', 'wizard.css', 'wizard-application.js',
'wizard-vendor.js']
# Precompile all available locales
Dir.glob("#{config.root}/app/assets/javascripts/locales/*.js.erb").each do |file|

View File

@ -53,6 +53,11 @@ Discourse::Application.routes.draw do
resources :forums
get "srv/status" => "forums#status"
namespace :wizard, constraints: StaffConstraint.new do
get "" => "wizard#index"
get "qunit" => "wizard#qunit"
end
namespace :admin, constraints: StaffConstraint.new do
get "" => "admin#index"

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

View File

@ -0,0 +1,25 @@
require 'rails_helper'
describe Wizard::WizardController do
context 'index' do
render_views
it 'needs you to be logged in' do
expect { xhr :get, :index }.to raise_error(Discourse::NotLoggedIn)
end
it "raises an error if you aren't an admin" do
log_in
xhr :get, :index
expect(response).to be_forbidden
end
it "renders the wizard if you are an admin" do
log_in(:admin)
xhr :get, :index
expect(response).to be_success
end
end
end