2018-09-14 05:05:57 -04:00
|
|
|
const testPackage = require('../../helpers/test-package');
|
|
|
|
const Dgeni = require('dgeni');
|
|
|
|
|
|
|
|
describe('processCliCommands processor', () => {
|
|
|
|
|
2019-01-22 07:52:04 -05:00
|
|
|
let dgeni, injector, processor, createDocMessage;
|
|
|
|
|
|
|
|
const navigationStub = {
|
|
|
|
docType: 'navigation-json',
|
2020-03-02 12:47:06 -05:00
|
|
|
data: {SideNav: [{children: [{'url': 'cli'}]}]}
|
2019-01-22 07:52:04 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
dgeni = new Dgeni([testPackage('cli-docs-package')]);
|
|
|
|
injector = dgeni.configureInjector();
|
|
|
|
processor = injector.get('processCliCommands');
|
|
|
|
createDocMessage = injector.get('createDocMessage');
|
|
|
|
});
|
|
|
|
|
2020-03-02 12:47:06 -05:00
|
|
|
it('should be available on the injector', () => { expect(processor.$process).toBeDefined(); });
|
2018-09-14 05:05:57 -04:00
|
|
|
|
2020-03-02 12:47:06 -05:00
|
|
|
it('should run after the correct processor',
|
|
|
|
() => { expect(processor.$runAfter).toEqual(['extra-docs-added']); });
|
2018-09-14 05:05:57 -04:00
|
|
|
|
2020-03-02 12:47:06 -05:00
|
|
|
it('should run before the correct processor',
|
|
|
|
() => { expect(processor.$runBefore).toEqual(['rendering-docs']); });
|
2018-09-14 05:05:57 -04:00
|
|
|
|
|
|
|
it('should collect the names (name + aliases)', () => {
|
|
|
|
const doc = {
|
|
|
|
docType: 'cli-command',
|
|
|
|
name: 'name',
|
|
|
|
commandAliases: ['alias1', 'alias2'],
|
|
|
|
options: [],
|
|
|
|
};
|
2019-01-22 07:52:04 -05:00
|
|
|
processor.$process([doc, navigationStub]);
|
2018-09-14 05:05:57 -04:00
|
|
|
expect(doc.names).toEqual(['name', 'alias1', 'alias2']);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('options', () => {
|
|
|
|
it('should remove the hidden options', () => {
|
|
|
|
const doc = {
|
|
|
|
docType: 'cli-command',
|
|
|
|
name: 'name',
|
|
|
|
commandAliases: [],
|
|
|
|
options: [
|
2020-03-02 12:47:06 -05:00
|
|
|
{name: 'option1'},
|
|
|
|
{name: 'option2', hidden: true},
|
|
|
|
{name: 'option3'},
|
|
|
|
{name: 'option4', hidden: true},
|
2018-09-14 05:05:57 -04:00
|
|
|
],
|
|
|
|
};
|
2019-01-22 07:52:04 -05:00
|
|
|
processor.$process([doc, navigationStub]);
|
2018-09-14 05:05:57 -04:00
|
|
|
expect(doc.namedOptions).toEqual([
|
2020-03-02 12:47:06 -05:00
|
|
|
jasmine.objectContaining({name: 'option1'}),
|
|
|
|
jasmine.objectContaining({name: 'option3'}),
|
2018-09-14 05:05:57 -04:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should collect the non-hidden positional and named options', () => {
|
|
|
|
const doc = {
|
|
|
|
docType: 'cli-command',
|
|
|
|
name: 'name',
|
|
|
|
commandAliases: [],
|
|
|
|
options: [
|
2020-03-02 12:47:06 -05:00
|
|
|
{name: 'named1'},
|
|
|
|
{name: 'positional1', positional: 0},
|
|
|
|
{name: 'named2', hidden: true},
|
|
|
|
{name: 'positional2', hidden: true, positional: 1},
|
2018-09-14 05:05:57 -04:00
|
|
|
],
|
|
|
|
};
|
2019-01-22 07:52:04 -05:00
|
|
|
processor.$process([doc, navigationStub]);
|
2018-09-14 05:05:57 -04:00
|
|
|
expect(doc.positionalOptions).toEqual([
|
2020-03-02 12:47:06 -05:00
|
|
|
jasmine.objectContaining({name: 'positional1', positional: 0}),
|
2018-09-14 05:05:57 -04:00
|
|
|
]);
|
|
|
|
expect(doc.namedOptions).toEqual([
|
2020-03-02 12:47:06 -05:00
|
|
|
jasmine.objectContaining({name: 'named1'}),
|
2018-09-14 05:05:57 -04:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should sort the named options into order by name', () => {
|
|
|
|
const doc = {
|
|
|
|
docType: 'cli-command',
|
|
|
|
name: 'name',
|
|
|
|
commandAliases: [],
|
|
|
|
options: [
|
2020-03-02 12:47:06 -05:00
|
|
|
{name: 'c'},
|
|
|
|
{name: 'a'},
|
|
|
|
{name: 'b'},
|
2018-09-14 05:05:57 -04:00
|
|
|
],
|
|
|
|
};
|
2019-01-22 07:52:04 -05:00
|
|
|
processor.$process([doc, navigationStub]);
|
2018-09-14 05:05:57 -04:00
|
|
|
expect(doc.namedOptions).toEqual([
|
2020-03-02 12:47:06 -05:00
|
|
|
jasmine.objectContaining({name: 'a'}),
|
|
|
|
jasmine.objectContaining({name: 'b'}),
|
|
|
|
jasmine.objectContaining({name: 'c'}),
|
2018-09-14 05:05:57 -04:00
|
|
|
]);
|
|
|
|
});
|
2020-03-02 12:49:20 -05:00
|
|
|
|
|
|
|
it('should collect potential search terms from options for indexing', () => {
|
|
|
|
const doc = {
|
|
|
|
docType: 'cli-command',
|
|
|
|
name: 'name',
|
|
|
|
commandAliases: [],
|
|
|
|
options: [
|
|
|
|
{name: 'named1'},
|
|
|
|
{name: 'positional1', positional: 0},
|
|
|
|
{name: 'named2', hidden: true},
|
|
|
|
{name: 'positional2', hidden: true, positional: 1},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
processor.$process([doc, navigationStub]);
|
|
|
|
expect(doc.optionKeywords).toEqual('named1 positional1');
|
|
|
|
});
|
2018-09-14 05:05:57 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('subcommands', () => {
|
|
|
|
it('should convert subcommands hash into a collection', () => {
|
|
|
|
const doc = {
|
|
|
|
docType: 'cli-command',
|
|
|
|
name: 'name',
|
|
|
|
commandAliases: [],
|
|
|
|
options: [{
|
|
|
|
name: 'supercommand',
|
|
|
|
subcommands: {
|
|
|
|
subcommand1: {
|
|
|
|
name: 'subcommand1',
|
|
|
|
options: [
|
2020-03-02 12:47:06 -05:00
|
|
|
{name: 'subcommand1-option1'},
|
|
|
|
{name: 'subcommand1-option2'},
|
2018-09-14 05:05:57 -04:00
|
|
|
],
|
|
|
|
},
|
|
|
|
subcommand2: {
|
|
|
|
name: 'subcommand2',
|
|
|
|
options: [
|
2020-03-02 12:47:06 -05:00
|
|
|
{name: 'subcommand2-option1'},
|
|
|
|
{name: 'subcommand2-option2'},
|
2018-09-14 05:05:57 -04:00
|
|
|
],
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}],
|
|
|
|
};
|
2019-01-22 07:52:04 -05:00
|
|
|
processor.$process([doc, navigationStub]);
|
2018-09-14 05:05:57 -04:00
|
|
|
expect(doc.options[0].subcommands).toEqual([
|
2020-03-02 12:47:06 -05:00
|
|
|
jasmine.objectContaining({name: 'subcommand1'}),
|
|
|
|
jasmine.objectContaining({name: 'subcommand2'}),
|
2018-09-14 05:05:57 -04:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should remove the hidden subcommand options', () => {
|
|
|
|
const doc = {
|
|
|
|
docType: 'cli-command',
|
|
|
|
name: 'name',
|
|
|
|
commandAliases: [],
|
|
|
|
options: [{
|
|
|
|
name: 'supercommand',
|
|
|
|
subcommands: {
|
|
|
|
subcommand1: {
|
|
|
|
name: 'subcommand1',
|
|
|
|
options: [
|
2020-03-02 12:47:06 -05:00
|
|
|
{name: 'subcommand1-option1'},
|
|
|
|
{name: 'subcommand1-option2', hidden: true},
|
2018-09-14 05:05:57 -04:00
|
|
|
],
|
|
|
|
},
|
|
|
|
subcommand2: {
|
|
|
|
name: 'subcommand2',
|
|
|
|
options: [
|
2020-03-02 12:47:06 -05:00
|
|
|
{name: 'subcommand2-option1', hidden: true},
|
|
|
|
{name: 'subcommand2-option2'},
|
2018-09-14 05:05:57 -04:00
|
|
|
],
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}],
|
|
|
|
};
|
2019-01-22 07:52:04 -05:00
|
|
|
processor.$process([doc, navigationStub]);
|
2018-09-14 05:05:57 -04:00
|
|
|
expect(doc.options[0].subcommands[0].namedOptions).toEqual([
|
2020-03-02 12:47:06 -05:00
|
|
|
jasmine.objectContaining({name: 'subcommand1-option1'}),
|
2018-09-14 05:05:57 -04:00
|
|
|
]);
|
|
|
|
expect(doc.options[0].subcommands[1].namedOptions).toEqual([
|
2020-03-02 12:47:06 -05:00
|
|
|
jasmine.objectContaining({name: 'subcommand2-option2'}),
|
2018-09-14 05:05:57 -04:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should collect the non-hidden positional arguments and named options', () => {
|
|
|
|
const doc = {
|
|
|
|
docType: 'cli-command',
|
|
|
|
name: 'name',
|
|
|
|
commandAliases: [],
|
|
|
|
options: [{
|
|
|
|
name: 'supercommand',
|
|
|
|
subcommands: {
|
|
|
|
subcommand1: {
|
|
|
|
name: 'subcommand1',
|
|
|
|
options: [
|
2020-03-02 12:47:06 -05:00
|
|
|
{name: 'subcommand1-option1'},
|
|
|
|
{name: 'subcommand1-option2', positional: 0},
|
2018-09-14 05:05:57 -04:00
|
|
|
],
|
|
|
|
},
|
|
|
|
subcommand2: {
|
|
|
|
name: 'subcommand2',
|
|
|
|
options: [
|
2020-03-02 12:47:06 -05:00
|
|
|
{name: 'subcommand2-option1', hidden: true},
|
|
|
|
{name: 'subcommand2-option2', hidden: true, positional: 1},
|
2018-09-14 05:05:57 -04:00
|
|
|
],
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}],
|
|
|
|
};
|
2019-01-22 07:52:04 -05:00
|
|
|
processor.$process([doc, navigationStub]);
|
2018-09-14 05:05:57 -04:00
|
|
|
expect(doc.options[0].subcommands[0].positionalOptions).toEqual([
|
2020-03-02 12:47:06 -05:00
|
|
|
jasmine.objectContaining({name: 'subcommand1-option2', positional: 0}),
|
2018-09-14 05:05:57 -04:00
|
|
|
]);
|
|
|
|
expect(doc.options[0].subcommands[0].namedOptions).toEqual([
|
2020-03-02 12:47:06 -05:00
|
|
|
jasmine.objectContaining({name: 'subcommand1-option1'}),
|
2018-09-14 05:05:57 -04:00
|
|
|
]);
|
|
|
|
|
|
|
|
expect(doc.options[0].subcommands[1].positionalOptions).toEqual([]);
|
|
|
|
expect(doc.options[0].subcommands[1].namedOptions).toEqual([]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should sort the named subcommand options into order by name', () => {
|
|
|
|
const doc = {
|
|
|
|
docType: 'cli-command',
|
|
|
|
name: 'name',
|
|
|
|
commandAliases: [],
|
|
|
|
options: [{
|
|
|
|
name: 'supercommand',
|
|
|
|
subcommands: {
|
|
|
|
subcommand1: {
|
|
|
|
name: 'subcommand1',
|
|
|
|
options: [
|
2020-03-02 12:47:06 -05:00
|
|
|
{name: 'c'},
|
|
|
|
{name: 'a'},
|
|
|
|
{name: 'b'},
|
2018-09-14 05:05:57 -04:00
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}],
|
|
|
|
};
|
2019-01-22 07:52:04 -05:00
|
|
|
processor.$process([doc, navigationStub]);
|
2018-09-14 05:05:57 -04:00
|
|
|
expect(doc.options[0].subcommands[0].namedOptions).toEqual([
|
2020-03-02 12:47:06 -05:00
|
|
|
jasmine.objectContaining({name: 'a'}),
|
|
|
|
jasmine.objectContaining({name: 'b'}),
|
|
|
|
jasmine.objectContaining({name: 'c'}),
|
2018-09-14 05:05:57 -04:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-03-02 12:47:06 -05:00
|
|
|
it('should add the command to the CLI node in the navigation doc if there is a first child node with a `cli` url',
|
|
|
|
() => {
|
|
|
|
const command = {
|
|
|
|
docType: 'cli-command',
|
|
|
|
name: 'command1',
|
|
|
|
commandAliases: ['alias1', 'alias2'],
|
|
|
|
options: [],
|
|
|
|
path: 'cli/command1',
|
|
|
|
};
|
|
|
|
const navigation = {
|
|
|
|
docType: 'navigation-json',
|
|
|
|
data: {
|
|
|
|
SideNav: [
|
|
|
|
{url: 'some/page', title: 'Some Page'}, {
|
|
|
|
title: 'CLI Commands',
|
|
|
|
tooltip: 'Angular CLI command reference',
|
|
|
|
children: [{'title': 'Overview', 'url': 'cli'}]
|
|
|
|
},
|
|
|
|
{url: 'other/page', title: 'Other Page'}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
processor.$process([command, navigation]);
|
|
|
|
expect(navigation.data.SideNav[1].title).toEqual('CLI Commands');
|
|
|
|
expect(navigation.data.SideNav[1].children).toEqual([
|
|
|
|
{url: 'cli', title: 'Overview'},
|
|
|
|
{url: 'cli/command1', title: 'ng command1'},
|
|
|
|
]);
|
|
|
|
});
|
2019-01-22 07:52:04 -05:00
|
|
|
|
|
|
|
it('should complain if there is no child with `cli` url', () => {
|
|
|
|
const command = {
|
|
|
|
docType: 'cli-command',
|
|
|
|
name: 'command1',
|
|
|
|
commandAliases: ['alias1', 'alias2'],
|
|
|
|
options: [],
|
|
|
|
path: 'cli/command1',
|
|
|
|
};
|
|
|
|
const navigation = {
|
|
|
|
docType: 'navigation-json',
|
|
|
|
data: {
|
|
|
|
SideNav: [
|
2020-03-02 12:47:06 -05:00
|
|
|
{url: 'some/page', title: 'Some Page'}, {
|
2019-01-22 07:52:04 -05:00
|
|
|
title: 'CLI Commands',
|
|
|
|
tooltip: 'Angular CLI command reference',
|
2020-03-02 12:47:06 -05:00
|
|
|
children: [{'title': 'Overview', 'url': 'client'}]
|
2019-01-22 07:52:04 -05:00
|
|
|
},
|
2020-03-02 12:47:06 -05:00
|
|
|
{url: 'other/page', title: 'Other Page'}
|
2019-01-22 07:52:04 -05:00
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
2020-03-02 12:47:06 -05:00
|
|
|
expect(() => processor.$process([command, navigation]))
|
|
|
|
.toThrowError(createDocMessage(
|
|
|
|
'Missing `cli` url - CLI Commands must include a first child node with url set at `cli`',
|
|
|
|
navigation));
|
2019-01-22 07:52:04 -05:00
|
|
|
});
|
2020-03-02 12:49:20 -05:00
|
|
|
|
2020-03-31 06:24:30 -04:00
|
|
|
it('should collect potential search terms from options and its subcommands for indexing', () => {
|
2020-03-02 12:49:20 -05:00
|
|
|
const doc = {
|
|
|
|
docType: 'cli-command',
|
|
|
|
name: 'name',
|
|
|
|
commandAliases: [],
|
|
|
|
options: [{
|
|
|
|
name: 'supercommand',
|
|
|
|
subcommands: {
|
|
|
|
subcommand1: {
|
|
|
|
name: 'subcommand1',
|
|
|
|
options: [
|
|
|
|
{name: 'subcommand1-option1'},
|
|
|
|
{name: 'subcommand1-option2'},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
subcommand2: {
|
|
|
|
name: 'subcommand2',
|
|
|
|
options: [
|
|
|
|
{name: 'subcommand2-option1'},
|
|
|
|
{name: 'subcommand2-option2'},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}],
|
|
|
|
};
|
|
|
|
processor.$process([doc, navigationStub]);
|
|
|
|
expect(doc.optionKeywords)
|
|
|
|
.toEqual(
|
|
|
|
'supercommand subcommand1 subcommand1-option1 subcommand1-option2 subcommand2 subcommand2-option1 subcommand2-option2');
|
|
|
|
});
|
|
|
|
|
2018-09-14 05:05:57 -04:00
|
|
|
});
|