Skip to content
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
6 changes: 0 additions & 6 deletions server/lib/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ exports.test = {
};

exports.testPageContext = {
home: true,
showAtom: {
slug: 'browse'
},
jsClass: true,
mainJS: true,
mediumTextLength: MEDIUM_TEXT_LENGTH,
Copy link
Member Author

Choose a reason for hiding this comment

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

decided to separate these template logic vars from the test defaults. not DRY but easier to reason about

titleError: null,
slugError: null,
Expand Down
2 changes: 1 addition & 1 deletion server/web/edit/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ This edit will create a new revision.
<h3>Code snippets to compare</h3>
{{#each page.test}}
<fieldset>
<h4>Test {{@index}}</h4>
<h4>Code snippet {{inc @index}}</h4>
<div>
<label for="test[{{@index}}][title]">Title </label>
<input type="text" name="test[{{@index}}][title]" id="test[{{@index}}][title]" value="{{title}}">
Expand Down
9 changes: 8 additions & 1 deletion server/web/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ exports.register = function (server, options, next) {
reply.view('edit/index', {
headTitle: page.title,
benchmark: false,
mainJS: true,
showAtom: {
slug: request.path.slice(1) // remove slash
},
Expand Down Expand Up @@ -66,8 +67,14 @@ exports.register = function (server, options, next) {
Hoek.merge(page, errObj);
reply.view('edit/index', {
headTitle: page.title,
benchmark: false,
mainJS: true,
showAtom: {
slug: request.path.slice(1) // remove slash
},
jsClass: true,
page: page,
authorized: true
authorized: request.auth.isAuthenticated
}).code(400);
};

Expand Down
23 changes: 16 additions & 7 deletions server/web/home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ exports.register = function (server, options, next) {
}
},
handler: function (request, reply) {
var authorized = false;

if (request.auth.isAuthenticated) {
authorized = true;
}
reply.view('home/index', _assign({}, defaults.testPageContext, {
home: true,
showAtom: {
slug: 'browse'
},
jsClass: true,
mainJS: true,
test: [defaults.test, defaults.test],
authorized: authorized
authorized: request.auth.isAuthenticated
}));
}
});
Expand All @@ -39,7 +40,15 @@ exports.register = function (server, options, next) {
if (errObj.message) {
errObj.genError = errObj.message;
}
reply.view('home/index', _assign({}, defaults.testPageContext, request.payload, {authorized: true}, errObj)).code(400);
reply.view('home/index', _assign({}, defaults.testPageContext, request.payload, {
home: true,
showAtom: {
slug: 'browse'
},
jsClass: true,
mainJS: true,
authorized: request.auth.isAuthenticated
}, errObj)).code(400);
};

Joi.validate(request.payload, schema.testPage, function (er, pageWithTests) {
Expand Down
1 change: 1 addition & 0 deletions test/unit/server/web/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ lab.experiment('GET', function () {
server.inject(request, function (response) {
Code.expect(response.statusCode).to.equal(200);
Code.expect(response.payload).to.include('<title>Oh Yea · jsPerf</title>');
Code.expect(response.payload).to.include('<script src="/public/_js/main.');

done();
});
Expand Down
1 change: 1 addition & 0 deletions test/unit/server/web/home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ lab.experiment('home', function () {

server.inject(request, function (response) {
Code.expect(response.result).to.include('Save test case');
Code.expect(response.payload).to.include('<script src="/public/_js/main.');

done();
});
Expand Down