Skip to content

Commit

Permalink
Category fixes (#1008)
Browse files Browse the repository at this point in the history
- Fix an issue where if no members were categorized during lump categorization, they would still be put in the default category instead of not using categories.

- Strip out category tag from comment upon categorizing
  • Loading branch information
jonchardy authored and aciccarello committed May 19, 2019
1 parent bb23e6d commit f781b20
Show file tree
Hide file tree
Showing 4 changed files with 1,270 additions and 44 deletions.
26 changes: 14 additions & 12 deletions src/lib/converter/plugins/CategoryPlugin.ts
Expand Up @@ -113,13 +113,15 @@ export class CategoryPlugin extends ConverterComponent {
}

private lumpCategorize(obj: ContainerReflection) {
if (obj instanceof ContainerReflection) {
if (obj.children && obj.children.length > 0) {
obj.categories = CategoryPlugin.getReflectionCategories(obj.children);
}
if (obj.categories && obj.categories.length > 1) {
obj.categories.sort(CategoryPlugin.sortCatCallback);
}
if (!obj.children || obj.children.length === 0) {
return;
}
obj.categories = CategoryPlugin.getReflectionCategories(obj.children);
if (obj.categories && obj.categories.length > 1) {
obj.categories.sort(CategoryPlugin.sortCatCallback);
} else if (obj.categories.length === 1 && obj.categories[0].title === CategoryPlugin.defaultCategory) {
// no categories if everything is uncategorized
obj.categories = undefined;
}
}

Expand Down Expand Up @@ -167,11 +169,11 @@ export class CategoryPlugin extends ConverterComponent {
function extractCategoryTag(comment: Comment) {
const tags = comment.tags;
if (tags) {
for (let i = 0; i < tags.length; i++) {
if (tags[i].tagName === 'category') {
let tag = tags[i].text;
return tag.trim();
}
const tagIndex = tags.findIndex(tag => tag.tagName === 'category');
if (tagIndex >= 0) {
const tag = tags[tagIndex].text;
tags.splice(tagIndex, 1);
return tag.trim();
}
}
return '';
Expand Down
54 changes: 54 additions & 0 deletions src/test/converter.test.ts
Expand Up @@ -98,6 +98,60 @@ describe('Converter', function() {
});
});

describe('Converter with categorizeByGroup=false', function() {
const base = Path.join(__dirname, 'converter');
const categoryDir = Path.join(base, 'category');
const classDir = Path.join(base, 'class');
let app: Application;

before('constructs', function() {
app = new Application({
mode: 'Modules',
logger: 'none',
target: 'ES5',
module: 'CommonJS',
experimentalDecorators: true,
categorizeByGroup: false,
jsx: 'react'
});
});

let result: ProjectReflection | undefined;

describe('category', () => {
it('converts fixtures', function() {
resetReflectionID();
result = app.convert(app.expandInputFiles([categoryDir]));
Assert(result instanceof ProjectReflection, 'No reflection returned');
});

it('matches specs', function() {
const specs = JSON.parse(FS.readFileSync(Path.join(categoryDir, 'specs-with-lump-categories.json')).toString());
let data = JSON.stringify(result!.toObject(), null, ' ');
data = data.split(normalizePath(base)).join('%BASE%');

compareReflections(JSON.parse(data), specs);
});
});

// verify that no categories are used when not specified during lump categorization
describe('class', () => {
it('converts fixtures', function() {
resetReflectionID();
result = app.convert(app.expandInputFiles([classDir]));
Assert(result instanceof ProjectReflection, 'No reflection returned');
});

it('matches specs', function() {
const specs = JSON.parse(FS.readFileSync(Path.join(classDir, 'specs.json')).toString());
let data = JSON.stringify(result!.toObject(), null, ' ');
data = data.split(normalizePath(base)).join('%BASE%');

compareReflections(JSON.parse(data), specs);
});
});
});

describe('Converter with excludeNotExported=true', function() {
const base = Path.join(__dirname, 'converter');
const exportWithLocalDir = Path.join(base, 'export-with-local');
Expand Down

0 comments on commit f781b20

Please sign in to comment.