Skip to content

Commit

Permalink
feat(icon): apply lint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
dpellier committed Nov 2, 2023
1 parent f8cf480 commit bdfc2c3
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 51 deletions.
1 change: 1 addition & 0 deletions packages/components/icon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"doc:api": "typedoc",
"generate:licence": "npx generate-license-file --input package.json --output THIRD-PARTY-LICENCES --overwrite",
"lint:scss": "stylelint 'src/components/**/*.scss'",
"lint:ts": "eslint 'src/**/*.{js,ts,tsx}'",
"start": "stencil build --docs --dev --watch --serve",
"test:e2e": "stencil test --e2e --config stencil.config.ts",
"test:e2e:ci": "stencil test --config stencil.config.ts --e2e --ci",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { OdsIconAttribute } from '../interfaces/attributes';

import { ODS_THEME_COLOR_INTENT } from '@ovhcloud/ods-common-theming';

import { ODS_ICON_SIZE } from './icon-size';

const DEFAULT_ATTRIBUTE: OdsIconAttribute = Object.freeze({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import type { OdsLoggerSpyReferences } from '@ovhcloud/ods-common-testing/src';

import { Ods, OdsLogger } from '@ovhcloud/ods-common-core';
import { OdsClearLoggerSpy, OdsInitializeLoggerSpy } from '@ovhcloud/ods-common-testing/src';
import { ODS_THEME_COLOR_INTENT } from '@ovhcloud/ods-common-theming';

import { OdsIconController } from './controller';
import { ODS_ICON_SIZE } from '../constants/icon-size';
import { OsdsIcon } from '../osds-icon';
Expand All @@ -22,7 +20,7 @@ describe('spec:ods-icon-controller', () => {

Ods.instance().logging(false);

function setup(attributes: Partial<OsdsIcon> = {}) {
function setup(attributes: Partial<OsdsIcon> = {}): void {
component = new OsdsIconMock(attributes);
controller = new OdsIconController(component);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import type { OsdsIcon } from '../osds-icon';

import { OdsLogger, OdsWarnComponentAttribute } from '@ovhcloud/ods-common-core';
import { ODS_THEME_COLOR_INTENT } from '@ovhcloud/ods-common-theming';

import { ODS_ICON_SIZE } from '../constants/icon-size';

/**
Expand Down Expand Up @@ -31,16 +29,16 @@ class OdsIconController {
const logger = this.logger;

OdsWarnComponentAttribute<ODS_THEME_COLOR_INTENT, OsdsIcon>({
logger,
attributeValues: ODS_THEME_COLOR_INTENT,
attributeName: 'color',
attribute: this.component.color,
attributeName: 'color',
attributeValues: ODS_THEME_COLOR_INTENT,
logger,
});
OdsWarnComponentAttribute<ODS_ICON_SIZE, OsdsIcon>({
logger,
attributeValues: ODS_ICON_SIZE,
attributeName: 'size',
attribute: this.component.size,
attributeName: 'size',
attributeValues: ODS_ICON_SIZE,
logger,
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ interface OdsIconAttribute {
size?: ODS_ICON_SIZE
}

export {
export type {
OdsIconAttribute,
};
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import type { OdsIconAttribute } from './interfaces/attributes';
import type { E2EPage } from '@stencil/core/testing';

import { odsComponentAttributes2StringAttributes, odsStringAttributes2Str } from '@ovhcloud/ods-common-testing';
import { ODS_THEME_COLOR_INTENTS } from '@ovhcloud/ods-common-theming';
import { newE2EPage } from '@stencil/core/testing';

import { DEFAULT_ATTRIBUTE } from './constants/default-attributes';
import { ODS_ICON_NAMES } from './constants/icon-name';
import { ODS_ICON_SIZES } from './constants/icon-size';


const TIMEOUT = 50000;

describe('e2e:osds-icon', () => {
let page: E2EPage;
let variations: string[] = [];

async function setup(content: string) {
async function setup(content: string): Promise<void> {
page = await newE2EPage();

await page.setContent(content);
Expand All @@ -35,7 +32,7 @@ describe('e2e:osds-icon', () => {
variations.push(`
<osds-icon ${odsStringAttributes2Str(
odsComponentAttributes2StringAttributes<OdsIconAttribute>(
{ color, name, size, ariaName: '' },
{ ariaName: '', color, name, size },
DEFAULT_ATTRIBUTE,
),
)}>
Expand All @@ -57,7 +54,7 @@ describe('e2e:osds-icon', () => {
variations.push(`
<osds-icon ${odsStringAttributes2Str(
odsComponentAttributes2StringAttributes<OdsIconAttribute>(
{ contrasted: true, color, name, size, ariaName: '' },
{ ariaName: '', color, contrasted: true, name, size },
DEFAULT_ATTRIBUTE,
),
)}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import type { OdsIconAttribute } from './interfaces/attributes';
import type { E2EElement, E2EPage } from '@stencil/core/testing';

import { odsComponentAttributes2StringAttributes, odsStringAttributes2Str } from '@ovhcloud/ods-common-testing';
import { ODS_THEME_COLOR_INTENT } from '@ovhcloud/ods-common-theming';
import { newE2EPage } from '@stencil/core/testing';

import { DEFAULT_ATTRIBUTE } from './constants/default-attributes';


describe('e2e:osds-icon', () => {
const baseAttribute = { ariaName: '' };
let page: E2EPage;
let el: E2EElement;

async function setup({ attributes = {} }: { attributes: Partial<OdsIconAttribute> }) {
async function setup({ attributes = {} }: { attributes: Partial<OdsIconAttribute> }): Promise<void> {
const stringAttributes = odsComponentAttributes2StringAttributes<OdsIconAttribute>({ ...baseAttribute, ...attributes }, DEFAULT_ATTRIBUTE);

page = await newE2EPage();
Expand Down
36 changes: 17 additions & 19 deletions packages/components/icon/src/components/osds-icon/osds-icon.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ jest.mock('./core/controller'); // keep jest.mock before any

import type { OdsIconAttribute } from './interfaces/attributes';
import type { SpecPage } from '@stencil/core/testing';

import { odsComponentAttributes2StringAttributes, odsStringAttributes2Str, odsUnitTestAttribute } from '@ovhcloud/ods-common-testing';
import { ODS_THEME_COLOR_INTENT, ODS_THEME_COLOR_INTENTS } from '@ovhcloud/ods-common-theming';
import { newSpecPage } from '@stencil/core/testing';

import { DEFAULT_ATTRIBUTE } from './constants/default-attributes';
import { ODS_ICON_NAME } from './constants/icon-name';
import { ODS_ICON_SIZE, ODS_ICON_SIZES } from './constants/icon-size';
Expand All @@ -20,7 +18,7 @@ describe('spec:osds-icon', () => {
let instance: OsdsIcon;
let controller: OdsIconController;

async function setup({ attributes = {} }: { attributes?: Partial<OdsIconAttribute> } = {}) {
async function setup({ attributes = {} }: { attributes?: Partial<OdsIconAttribute> } = {}): Promise<void> {
const stringAttributes = odsComponentAttributes2StringAttributes<OdsIconAttribute>({ ...baseAttribute, ...attributes }, DEFAULT_ATTRIBUTE);

page = await newSpecPage({
Expand All @@ -41,19 +39,19 @@ describe('spec:osds-icon', () => {

describe('attributes', () => {
const config = {
instance: () => instance,
page: () => page,
root: () => page.root,
wait: () => page.waitForChanges(),
instance: (): OsdsIcon => instance,
page: (): SpecPage => page,
root: (): SpecPage['root'] => page.root,
wait: (): Promise<void> => page.waitForChanges(),
};

describe('aria-name', () => {
odsUnitTestAttribute<OdsIconAttribute, 'ariaName'>({
name: 'ariaName',
defaultValue: DEFAULT_ATTRIBUTE.ariaName,
name: 'ariaName',
newValue: 'An Icon',
value: 'Oles ipsum',
setup: (value) => setup({ attributes: { ['ariaName']: value } }),
value: 'Oles ipsum',
...config,
});

Expand All @@ -65,11 +63,11 @@ describe('spec:osds-icon', () => {

describe('color', () => {
odsUnitTestAttribute<OdsIconAttribute, 'color'>({
name: 'color',
defaultValue: DEFAULT_ATTRIBUTE.color,
name: 'color',
newValue: ODS_THEME_COLOR_INTENT.error,
value: ODS_THEME_COLOR_INTENT.success,
setup: (value) => setup({ attributes: { ['color']: value } }),
value: ODS_THEME_COLOR_INTENT.success,
...config,
});

Expand All @@ -82,11 +80,11 @@ describe('spec:osds-icon', () => {

describe('contrasted', () => {
odsUnitTestAttribute<OdsIconAttribute, 'contrasted'>({
name: 'contrasted',
defaultValue: DEFAULT_ATTRIBUTE.contrasted,
name: 'contrasted',
newValue: false,
value: true,
setup: (value) => setup({ attributes: { ['contrasted']: value } }),
value: true,
...config,
});

Expand All @@ -105,11 +103,11 @@ describe('spec:osds-icon', () => {

describe('name', () => {
odsUnitTestAttribute<OdsIconAttribute, 'name'>({
name: 'name',
defaultValue: DEFAULT_ATTRIBUTE.name,
name: 'name',
newValue: ODS_ICON_NAME.ARROW_DOWN,
value: ODS_ICON_NAME.ARROW_UP,
setup: (value) => setup({ attributes: { ['name']: value } }),
value: ODS_ICON_NAME.ARROW_UP,
...config,
});

Expand All @@ -122,11 +120,11 @@ describe('spec:osds-icon', () => {

describe('size', () => {
odsUnitTestAttribute<OdsIconAttribute, 'size'>({
name: 'size',
defaultValue: DEFAULT_ATTRIBUTE.size,
name: 'size',
newValue: ODS_ICON_SIZE.md,
value: ODS_ICON_SIZE.sm,
setup: (value) => setup({ attributes: { ['size']: value } }),
value: ODS_ICON_SIZE.sm,
...config,
});

Expand All @@ -139,11 +137,11 @@ describe('spec:osds-icon', () => {

describe('hoverable', () => {
odsUnitTestAttribute<OdsIconAttribute, 'hoverable'>({
name: 'hoverable',
defaultValue: DEFAULT_ATTRIBUTE.hoverable,
name: 'hoverable',
newValue: false,
value: true,
setup: (value) => setup({ attributes: { ['hoverable']: value } }),
value: true,
...config,
});

Expand Down
15 changes: 7 additions & 8 deletions packages/components/icon/src/components/osds-icon/osds-icon.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import type { ODS_ICON_NAME } from './constants/icon-name';
import type { ODS_ICON_SIZE } from './constants/icon-size';
import type { OdsIconAttribute } from './interfaces/attributes';

import { ODS_THEME_COLOR_INTENT } from '@ovhcloud/ods-common-theming';
import type { ODS_THEME_COLOR_INTENT } from '@ovhcloud/ods-common-theming';
import type { FunctionalComponent } from '@stencil/core';
import icons from '@ovhcloud/ods-common-theming/icons/icons.data.json';
import { Component, Element, Host, Prop, Watch, h } from '@stencil/core';

import { DEFAULT_ATTRIBUTE } from './constants/default-attributes';
import { ODS_ICON_NAME } from './constants/icon-name';
import { ODS_ICON_SIZE } from './constants/icon-size';
import { OdsIconController } from './core/controller';

@Component({
tag: 'osds-icon',
styleUrl: 'osds-icon.scss',
shadow: true,
styleUrl: 'osds-icon.scss',
tag: 'osds-icon',
})
export class OsdsIcon implements OdsIconAttribute {
controller: OdsIconController = new OdsIconController(this);
Expand Down Expand Up @@ -43,7 +42,7 @@ export class OsdsIcon implements OdsIconAttribute {
this.beforeRender();
}

render() {
render(): FunctionalComponent {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const base64Icon = icons[this.name];
Expand Down

0 comments on commit bdfc2c3

Please sign in to comment.