Skip to content

Commit

Permalink
Fix(analytics): HTML element is not the PascalCase component
Browse files Browse the repository at this point in the history
  • Loading branch information
literat committed Dec 12, 2023
1 parent 343ab51 commit 4ddf584
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
12 changes: 11 additions & 1 deletion packages/analytics/src/scanners/__tests__/twigScanner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ describe('twigScanner', () => {
expect(result).toBe('local_component');
});

it('should return "local_component" if the nodeName is not in the localComponents array but it is a Component', () => {
const nodeName = 'ComponentTest';
const localComponents = ['Component1', 'Component2', 'Component3'];
const baseComponents = ['BaseComponent1', 'BaseComponent2'];

const result = twigScanner.determineModuleNameFromComponents(nodeName, localComponents, baseComponents);

expect(result).toBe('local_component');
});

it('should return "@lmc-eu/spirit-web-twig" if the nodeName is in the baseComponents array', () => {
const nodeName = 'BaseComponent2';
const localComponents = ['Component1', 'Component2', 'Component3'];
Expand All @@ -66,7 +76,7 @@ describe('twigScanner', () => {
});

it('should return "html_element" if the nodeName is not in the localComponents or baseComponents array', () => {
const nodeName = 'UnknownComponent';
const nodeName = 'div';
const localComponents = ['Component1', 'Component2', 'Component3'];
const baseComponents = ['BaseComponent1', 'BaseComponent2'];

Expand Down
9 changes: 5 additions & 4 deletions packages/analytics/src/scanners/twigScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@ export function determineModuleNameFromComponents(
localComponents: Array<string>,
baseComponents: Array<string>,
) {
if (localComponents.includes(nodeName)) {
return 'local_component';
}

if (baseComponents.includes(nodeName)) {
return '@lmc-eu/spirit-web-twig';
}

const pascalCaseRegex = /^([A-Z][a-z0-9]+)+$/;
if (localComponents.includes(nodeName) || nodeName.match(pascalCaseRegex)) {
return 'local_component';
}

return 'html_element';
}

Expand Down

0 comments on commit 4ddf584

Please sign in to comment.