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

Allow user to specify initial route via query parameter #275

Merged
merged 1 commit into from
Nov 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion app/gist/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default Ember.Controller.extend({
dependencyResolver: inject.service(),
notify: inject.service('notify'),

queryParams: ['numColumns', 'fullScreen'],
queryParams: ['numColumns', 'fullScreen', 'route'],
numColumns: 2,
fullScreen: false,

Expand Down Expand Up @@ -91,6 +91,7 @@ export default Ember.Controller.extend({

this.set('isBuilding', true);
this.set('buildErrors', []);
this.set('model.initialRoute', this.get('route'));

this.get('emberCli').compileGist(this.get('model')).then(buildOutput => {
this.set('isBuilding', false);
Expand Down
4 changes: 4 additions & 0 deletions app/services/ember-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ export default Ember.Service.extend({
},

buildHtml (gist, appJS, appCSS) {
if (gist.get('initialRoute')) {
appJS += "window.location.hash='" + gist.get('initialRoute') + "';";
}

let index = blueprints['index.html'];
let twiddleJSON = this.getTwiddleJson(gist);
let deps = twiddleJSON.dependencies;
Expand Down
14 changes: 14 additions & 0 deletions tests/acceptance/routing-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,18 @@ test('URL can be changed via the address bar', function(assert) {
});
});

test('URL can be set via route query parameter', function(assert) {
runGist({
files: TWIDDLE_WITH_ROUTES,
initialRoute: "/about"
});

andThen(() => {
this.registerWaiter();
});

andThen(function() {
assert.equal(find(addressBar).val(), "/about", "Correct URL appears when set via query parameter");
assert.equal(outputContents(outletText), 'About Page', 'Initializing the URL to /about leads to the About Page being displayed');
});
});
27 changes: 21 additions & 6 deletions tests/helpers/run-gist.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
export default function(app, files) {
const login = "Gaurav0";
const gist_id = "35de43cb81fc35ddffb2";
const commit = "f354c6698b02fe3243656c8dc5aa0303cc7ae81c";
import Ember from "ember";

const { isArray } = Ember;

export default function(app, options) {
if (isArray(options)) {
options = { files: options };
}

const login = options.login || "Gaurav0";
const gist_id = options.gist_id || "35de43cb81fc35ddffb2";
const commit = options.commit || "f354c6698b02fe3243656c8dc5aa0303cc7ae81c";
const initialRoute = options.initialRoute || "/";
let files = options.files || [];

files.push({
filename: "initializers.setup-test.js",
Expand Down Expand Up @@ -29,7 +39,12 @@ export default function(app, files) {
files: gistFiles
});

visit('/35de43cb81fc35ddffb2');
let url = "/" + gist_id;
if (initialRoute !== "/") {
url += "?route=" + initialRoute;
}

visit(url);

return waitForLoadedIFrame();
return waitForLoadedIFrame(initialRoute);
}
5 changes: 3 additions & 2 deletions tests/helpers/wait-for-loaded-iframe.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Ember from "ember";

export default function() {
export default function(app, url) {
let iframe_window;

andThen(function() {
Expand All @@ -16,6 +16,7 @@ export default function() {
});

return andThen(function() {
iframe_window.visit('/');
url = url || "/";
iframe_window.visit(url);
});
}