George Kalpakas d7ca263cc4 test(docs-infra): run tests in random order (and make them pass) (#31527)
This commit updates the necessary config files to run the angular.io and
docs tooling unit tests in random order (and fixes the tests that were
failing due to their dependence on the previous ordered execution).

Besides being a good idea anyway, running tests in random order is the
new [default behavior in jasmine@3.0.0][1], so this commit is in
preparation of upgrading jasmine to the latest version.

[1]: https://github.com/jasmine/jasmine/blob/v3.0.0/release_notes/3.0.md#breaking-changes

PR Close #31527
2019-07-18 10:17:13 -07:00

76 lines
2.7 KiB
JavaScript

var testPackage = require('../../helpers/test-package');
var Dgeni = require('dgeni');
describe('convertToJson processor', () => {
var dgeni, injector, processor, log;
beforeEach(function() {
dgeni = new Dgeni([testPackage('angular-base-package')]);
injector = dgeni.configureInjector();
processor = injector.get('convertToJsonProcessor');
log = injector.get('log');
processor.docTypes = ['test-doc'];
});
it('should be part of the dgeni package', () => {
expect(processor).toBeDefined();
});
it('should convert the renderedContent to JSON', () => {
const docs = [{
docType: 'test-doc',
title: 'The Title',
name: 'The Name',
path: 'test/doc',
renderedContent: 'Some Content'
}];
processor.$process(docs);
expect(JSON.parse(docs[0].renderedContent).id).toEqual('test/doc');
expect(JSON.parse(docs[0].renderedContent).title).toEqual('The Title');
expect(JSON.parse(docs[0].renderedContent).contents).toEqual('Some Content');
});
it('should get the title from name if no title is specified', () => {
const docs = [{ docType: 'test-doc', name: 'The Name' }];
processor.$process(docs);
expect(JSON.parse(docs[0].renderedContent).title).toEqual('The Name');
});
it('should accept an empty title', () => {
const docs = [{ docType: 'test-doc', title: '' }];
processor.$process(docs);
expect(JSON.parse(docs[0].renderedContent).title).toEqual('');
expect(log.warn).not.toHaveBeenCalled();
});
it('should accept an empty name if title is not provided', () => {
const docs = [{ docType: 'test-doc', name: '' }];
processor.$process(docs);
expect(JSON.parse(docs[0].renderedContent).title).toEqual('');
expect(log.warn).not.toHaveBeenCalled();
});
it('should get the title from the title extracted from the h1 in the rendered content if no title property is specified', () => {
const docs = [{
docType: 'test-doc',
vFile: { title: 'Some title' },
renderedContent: '<div><h1 class="title">Some title</h1><article><h1>Article 1</h1></article></div>'
}];
processor.$process(docs);
expect(JSON.parse(docs[0].renderedContent).contents).toEqual('<div><h1 class="title">Some title</h1><article><h1>Article 1</h1></article></div>');
expect(JSON.parse(docs[0].renderedContent).title).toEqual('Some title');
});
it('should set missing titles to empty', () => {
const docs = [{ docType: 'test-doc' }];
processor.$process(docs);
expect(JSON.parse(docs[0].renderedContent).title).toBe('');
});
it('should log a warning', () => {
const docs = [{ docType: 'test-doc' }];
processor.$process(docs);
expect(log.warn).toHaveBeenCalledWith('Title property expected - doc (test-doc) ');
});
});