forked from hazza/dspace-angular

The following cases are covered: - ThemedComponent wrapper selectors must not start with ds-themed- - Base component selectors must start with ds-base- - Themed component selectors must start with ds-themed- - The ThemedComponent wrapper must always be used in HTML - The ThemedComponent wrapper must be used in TypeScript _where appropriate_: - Required - Explicit usages (e.g. modal instantiation, routing modules, ...) - By.css selector queries (in order to align with the HTML rule) - Unchecked - Non-routing modules (to ensure the components can be declared) - ViewChild hooks (since they need to attach to the underlying component) All rules work with --fix to automatically migrate to the new convention This covers most of the codebase, but minor manual adjustment are needed afterwards
141 lines
3.0 KiB
TypeScript
141 lines
3.0 KiB
TypeScript
/**
|
|
* The contents of this file are subject to the license and copyright
|
|
* detailed in the LICENSE and NOTICE files at the root of the source
|
|
* tree and available online at
|
|
*
|
|
* http://www.dspace.org/license/
|
|
*/
|
|
|
|
|
|
import {
|
|
fixture,
|
|
tsRuleTester,
|
|
} from '../testing';
|
|
import rule from '../../src/rules/ts/themed-component-selectors';
|
|
|
|
describe('themed-component-selectors', () => {
|
|
tsRuleTester.run('themed-component-selectors', rule as any, {
|
|
valid: [
|
|
{
|
|
name: 'Regular non-themeable component selector',
|
|
code: `
|
|
@Component({
|
|
selector: 'ds-something',
|
|
})
|
|
class Something {
|
|
}
|
|
`,
|
|
},
|
|
{
|
|
name: 'Themeable component selector should replace the original version, unthemed version should be changed to ds-base-',
|
|
code: `
|
|
@Component({
|
|
selector: 'ds-base-something',
|
|
})
|
|
class Something {
|
|
}
|
|
|
|
@Component({
|
|
selector: 'ds-something',
|
|
})
|
|
class ThemedSomething extends ThemedComponent<Something> {
|
|
}
|
|
|
|
@Component({
|
|
selector: 'ds-themed-something',
|
|
})
|
|
class OverrideSomething extends Something {
|
|
}
|
|
`,
|
|
},
|
|
{
|
|
name: 'Other themed component wrappers should not interfere',
|
|
code: `
|
|
@Component({
|
|
selector: 'ds-something',
|
|
})
|
|
class Something {
|
|
}
|
|
|
|
@Component({
|
|
selector: 'ds-something-else',
|
|
})
|
|
class ThemedSomethingElse extends ThemedComponent<SomethingElse> {
|
|
}
|
|
`,
|
|
},
|
|
],
|
|
invalid: [
|
|
{
|
|
name: 'Wrong selector for base component',
|
|
filename: fixture('src/app/test/test-themeable.component.ts'),
|
|
code: `
|
|
@Component({
|
|
selector: 'ds-something',
|
|
})
|
|
class TestThemeableComponent {
|
|
}
|
|
`,
|
|
errors: [
|
|
{
|
|
messageId: 'wrongSelectorUnthemedComponent',
|
|
},
|
|
],
|
|
output: `
|
|
@Component({
|
|
selector: 'ds-base-something',
|
|
})
|
|
class TestThemeableComponent {
|
|
}
|
|
`,
|
|
},
|
|
{
|
|
name: 'Wrong selector for wrapper component',
|
|
filename: fixture('src/app/test/themed-test-themeable.component.ts'),
|
|
code: `
|
|
@Component({
|
|
selector: 'ds-themed-something',
|
|
})
|
|
class ThemedTestThemeableComponent extends ThemedComponent<TestThemeableComponent> {
|
|
}
|
|
`,
|
|
errors: [
|
|
{
|
|
messageId: 'wrongSelectorThemedComponentWrapper',
|
|
},
|
|
],
|
|
output: `
|
|
@Component({
|
|
selector: 'ds-something',
|
|
})
|
|
class ThemedTestThemeableComponent extends ThemedComponent<TestThemeableComponent> {
|
|
}
|
|
`,
|
|
},
|
|
{
|
|
name: 'Wrong selector for theme override',
|
|
filename: fixture('src/themes/test/app/test/test-themeable.component.ts'),
|
|
code: `
|
|
@Component({
|
|
selector: 'ds-something',
|
|
})
|
|
class TestThememeableComponent extends BaseComponent {
|
|
}
|
|
`,
|
|
errors: [
|
|
{
|
|
messageId: 'wrongSelectorThemedComponentOverride',
|
|
},
|
|
],
|
|
output: `
|
|
@Component({
|
|
selector: 'ds-themed-something',
|
|
})
|
|
class TestThememeableComponent extends BaseComponent {
|
|
}
|
|
`,
|
|
},
|
|
],
|
|
} as any);
|
|
});
|