Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate html should keep id when script-export is set #6276

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/src/code_manager/model/HtmlGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default class HTMLGenerator extends Model {
id &&
id[0] === 'i' && // all autogenerated IDs start with 'i'
!mod.get('script') && // if the component has script, we have to leave the ID
!mod.get('script-export') && // if the component has script, we have to leave the ID
!mod.get('attributes')!.id && // id is not intentionally in attributes
idRules.indexOf(id) < 0 // we shouldn't have any rule with this ID
) {
Expand Down
31 changes: 31 additions & 0 deletions packages/core/test/specs/code_manager/model/CodeModels.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,37 @@ describe('HtmlGenerator', () => {
});
expect(obj.build(m1)).toEqual('<article data-test1="value1" data-test2="value2" class="class1 class2"></article>');
});

test('Build correctly component with id preserved when script is defined', () => {
const m1 = comp.get('components').add({
tagName: 'article',
});
m1.set('script', 'anything');
expect(obj.build(m1, { cleanId: true, em })).toEqual(`<article id="${m1.getId()}"></article>`);
});

test('Build correctly component with id preserved when script-export is defined', () => {
const m1 = comp.get('components').add({
tagName: 'article',
});
m1.set('script-export', 'anything');
expect(obj.build(m1, { cleanId: true, em })).toEqual(`<article id="${m1.getId()}"></article>`);
});

test('Build correctly component with id preserved when id is explicitly set ', () => {
const m1 = comp.get('components').add({
tagName: 'article',
});
m1.setId('i11');
expect(obj.build(m1, { cleanId: true, em })).toEqual(`<article id="i11"></article>`);
});

test('Build correctly component with cleanId is enabled and id is not required ', () => {
const m1 = comp.get('components').add({
tagName: 'article',
});
expect(obj.build(m1, { cleanId: true, em })).toEqual(`<article></article>`);
});
});

describe('CssGenerator', () => {
Expand Down