Skip to content

Commit

Permalink
Resolve #415
Browse files Browse the repository at this point in the history
  • Loading branch information
jth- committed Feb 1, 2016
1 parent feed8b5 commit 772d9a6
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 12 deletions.
1 change: 0 additions & 1 deletion lib/modules/apostrophe-pager/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module.exports = {
alias: 'pager',
construct: function(self, options) {
console.log('PUSH');
self.pushAsset('stylesheet', 'user', { when: 'user' });
self.addHelpers({
// Generate the right range of page numbers to display in the pager.
Expand Down
5 changes: 4 additions & 1 deletion test/locales/en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"Server error, please try again.": "Server error, please try again.",
"Use the Add Content button to get started.": "Use the Add Content button to get started."
"Use the Add Content button to get started.": "Use the Add Content button to get started.",
"Type Here": "Type Here",
"Limit Reached!": "Limit Reached!",
"Example label": "Example label"
}
79 changes: 69 additions & 10 deletions test/pieces-widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,77 @@ describe('pieces-widgets', function() {
});
});

// This code is pulled from express tests in order to properly test POST route
var jar;

function getCsrfToken(jar) {
var csrfCookie = _.find(jar.getCookies('http://localhost:7944/'), { key: 'XSRF-TOKEN' });
if (!csrfCookie) {
return null;
}
var csrfToken = csrfCookie.value;
return csrfToken;
}

it('should be able to autocomplete docs', function(done) {
return request('http://localhost:7944/modules/apostrophe-docs/autocomplete?term=wig', function(err, response, body) {
assert(!err);
// Is our status code good?
// otherwise request does not track cookies
jar = request.jar();
request({
method: 'GET',
url: 'http://localhost:7944/page-with-events',
jar: jar
}, function(err, response, body) {
assert.equal(response.statusCode, 200);
// Is it JSON?
var events = JSON.parse(body);
assert(events);
assert(Array.isArray(events));
assert(events[0].label === 'Event Wiggly');
assert(events.length === 1);
done();
var csrfToken = getCsrfToken(jar);
// Now let's get a modal so we can bless the joins
return request({
method: 'POST',
url: 'http://localhost:7944/modules/events-widgets/modal',
json: {
_id: 'wevent007'
},
jar: jar,
headers: {
'X-XSRF-TOKEN': csrfToken
}
}, function(err, response, body) {
assert(!err);
// Is our status code good?
assert.equal(response.statusCode, 200);
return request({
method: 'POST',
url: 'http://localhost:7944/modules/apostrophe-docs/autocomplete',
json: {
term: 'wig',
field: {
type: 'joinByArray',
name: '_pieces',
label: 'Individually',
idsField: 'pieceIds',
withType: 'event'
}
},
jar: jar,
headers: {
'X-XSRF-TOKEN': csrfToken
}
}, function(err, response, body) {
assert(!err);
// Is our status code good?
assert.equal(response.statusCode, 200);
var events;
if (typeof body === 'string') {
events = JSON.parse(body);
} else {
events = body;
}
assert(events);
assert(Array.isArray(events));
assert(events[0].label === 'Event Wiggly');
assert(events.length === 1);
done();
});
});
});
});
});

0 comments on commit 772d9a6

Please sign in to comment.