| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- const chai = require('chai');
- const should = chai.should();
- const httpMocks = require('node-mocks-http');
- const cheerio = require('cheerio');
- const ExampleStore = require('../../lib/ExampleStore');
- const exStore = new ExampleStore(__dirname + '/test-examples');
- const indexHandlers = require('../../lib/indexHandlers')(exStore);
- function invokeHandler(url, handler, options) {
- options = options || {};
- method = options.method || 'GET';
- // Prepare request&response
- var request = httpMocks.createRequest({
- method: 'GET',
- url: '/'
- });
- var response = httpMocks.createResponse();
- // Invoke route handler, get returned html and load it with cheerio
- handler(request, response);
- var html = response._getData();
- return cheerio.load(html);
- }
- describe('render index', () => {
- before(() => exStore.init());
- it('without selected repo or example', () => {
- const $ = invokeHandler('/', indexHandlers.getIndexBare);
- const inlineJsData = "let window = {};" +
- $('#inline-js-data').html();
- try {
- eval(inlineJsData);
- } catch(e) {
- throw new Error('injected script in #inline-js-data throws an error: "' + e.message + '');
- }
- const $menuRepoItems = $('#menu-repo li');
- $menuRepoItems.length.should.equal(2);
- const repo1Link = $($menuRepoItems[0]).html();
- const repo2Link = $($menuRepoItems[1]).html();
- repo1Link.should.equal('<a href="/example-repo1">Example Repo 1</a>');
- repo2Link.should.equal('<a href="/example-repo2">Example Repo 2</a>');
- });
- });
|