Skip to content

Commit

Permalink
feat(arch): move && simplify component collapsible
Browse files Browse the repository at this point in the history
  • Loading branch information
dpellier committed Aug 2, 2023
1 parent 034064d commit 4c1dfec
Show file tree
Hide file tree
Showing 83 changed files with 993 additions and 294 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
* [**Interfaces**](#interfaces)
* [**Classes**](#classes)
* [**Type alias**](#type-alias)
* [**Variables**](#variables)

## Interfaces

### OdsCollapsibleAttributes
|name | Type | Required | Default | Description|
|---|---|:---:|---|---|
|**`opened`** | _boolean_ | | | opened or not|

### OdsCollapsibleBehavior
|name | Type | Required | Default | Description|
|---|---|:---:|---|---|
|**`el`** | `HTMLElement` | ✴️ | | reference to the host element.|
|**`emitToggle`** | _void_ | ✴️ | | emit collapsible opened status when toggle event is triggered|

### OdsCollapsibleEvents
|name | Type | Required | Default | Description|
|---|---|:---:|---|---|
|**`odsCollapsibleToggle`** | _boolean_ | ✴️ | | Event triggered on collapsible toggle|

## Classes

### OdsCollapsibleController
_common controller logic for cmpnt component used by the different implementations._
_it contains all the glue between framework implementation and the third party service._

#### Methods
> **onToggle**() => _unknown_


## Type alias

### OdsCollapsible

interface description of all implementation of `ods-collapsible`.
each implementation must have defined events, methods, attributes
and one controller for the common behavior logic

> - `OdsComponentGenericMethods`
> - `OdsComponentGenericEvents`
### OdsCollapsibleAttributes

> _Based on `OdsComponentAttributes`_
### OdsCollapsibleEvents

> _Based on `OdsComponentEvents`_
### OdsCollapsibleMethods

> _Based on `OdsComponentMethods`_
## Variables

### odsCollapsibleDefaultAttributes
`OdsCollapsibleAttributes`
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {Description} from '@storybook/addon-docs';
import Specs from './spec.md';

<Description>{Specs}</Description>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Config } from '@jest/types';
import { OdsGetJestConfig } from '@ovhcloud/ods-testing';
import { OdsGetJestConfig } from '@ovhcloud/ods-common-testing';

const args = process.argv.slice(2);

Expand All @@ -15,8 +15,9 @@ const args = process.argv.slice(2);
* };
* ```
*/
// @ts-ignore until dependencies are fixed to one unique version of @jest/types
const config: Config.InitialOptions = OdsGetJestConfig({
basePath: '<rootDir>/../../../..',
basePath: '<rootDir>/../../..',
args
});
export default config;
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
{
"name": "@ovhcloud/ods-stencil-collapsible",
"name": "@ovhcloud/ods-component-collapsible",
"version": "15.0.1",
"private": true,
"description": "Collapsible component",
"description": "ODS Collapsible component",
"author": "OVH SAS",
"license": "Apache-2.0",
"main": "dist/index.cjs.js",
"module": "dist/index.js",
"es2015": "dist/esm/index.js",
"es2017": "dist/esm/index.js",
"types": "dist/types/components.d.ts",
"types": "dist/types/index.d.ts",
"collection": "dist/collection/collection-manifest.json",
"collection:main": "dist/collection/index.js",
"scripts": {
Expand All @@ -35,10 +34,13 @@
"test:e2e:ci:screenshot:update": "stencil test --config stencil.config.ts --e2e --ci --screenshot --update-screenshot --passWithNoTests"
},
"dependencies": {
"@ovhcloud/ods-stencil-component": "^15.0.1"
"@ovhcloud/ods-common-core": "^15.0.1",
"@ovhcloud/ods-common-stencil": "^15.0.1",
"@ovhcloud/ods-theming": "^15.0.1"
},
"devDependencies": {
"@ovhcloud/ods-stencil-component-dev": "^15.0.1"
"@ovhcloud/ods-common-testing": "^15.0.1",
"@ovhcloud/ods-stencil-dev": "^15.0.1"
},
"publishConfig": {
"registry": ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@ovhcloud/ods-stencil-collapsible-react",
"name": "@ovhcloud/ods-component-collapsible-react",
"version": "15.0.1",
"private": true,
"description": "React specific wrapper for ods",
Expand All @@ -20,19 +20,13 @@
"dist/"
],
"dependencies": {
"@ovhcloud/ods-stencil-collapsible": "^15.0.1",
"tslib": "*"
"@ovhcloud/ods-component-collapsible": "^15.0.1"
},
"peerDependencies": {
"react": ">=16.8.6",
"react-dom": ">=16.8.6"
},
"devDependencies": {
"@types/react": "17.0.37",
"@types/react-dom": "17.0.11",
"react": "16.14.0",
"react-dom": "16.14.0",
"rimraf": "^3.0.2",
"typescript": "4.7.4"
"@ovhcloud/ods-react-dev": "^15.0.1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { OdsCollapsibleAttribute } from '../interfaces/attributes';

const DEFAULT_ATTRIBUTE: OdsCollapsibleAttribute = Object.freeze({
opened: false,
});

export {
DEFAULT_ATTRIBUTE,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { EventEmitter } from '@stencil/core';
import { OdsCollapsibleController } from './controller';
import { OsdsCollapsible } from '../osds-collapsible';

class OdsCollapsibleMock extends OsdsCollapsible {
constructor(attribute: Partial<OsdsCollapsible>) {
super();
Object.assign(this, attribute);
}
}

describe('spec:ods-collapsible-controller', () => {
let controller: OdsCollapsibleController;
let component: OsdsCollapsible;

function setup(attributes: Partial<OsdsCollapsible> = {}) {
component = new OdsCollapsibleMock(attributes);
component.odsCollapsibleToggle = { emit: jest.fn() } as unknown as EventEmitter<boolean>;
controller = new OdsCollapsibleController(component);
}

describe('methods:onToggle', () => {
it('should odsCollapsibleToggle emit false', () => {
setup({ opened: true });
const spy = jest.spyOn(component, 'emitToggle');
controller.onToggle();
expect(spy).toHaveBeenCalledWith(true);
});

it('should odsCollapsibleToggle emit true', () => {
setup({ opened: false });
const spy = jest.spyOn(component, 'emitToggle');
controller.onToggle();
expect(spy).toHaveBeenCalledWith(false);
});
});
});
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { OdsCollapsible } from './ods-collapsible';
import { OdsComponentController } from '../ods-component-controller';
import type { OsdsCollapsible } from '../osds-collapsible';

/**
* common controller logic for cmpnt component used by the different implementations.
* it contains all the glue between framework implementation and the third party service.
*/
export class OdsCollapsibleController extends OdsComponentController<OdsCollapsible> {
class OdsCollapsibleController {
private component: OsdsCollapsible;

constructor(component: OdsCollapsible) {
super(component);
constructor(component: OsdsCollapsible) {
this.component = component;
}

onToggle(): void {
this.component.emitToggle(this.component.opened || false);
}
}

export {
OdsCollapsibleController,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
interface OdsCollapsibleAttribute {
/** opened or not */
opened?: boolean;
}

export {
OdsCollapsibleAttribute,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { EventEmitter } from '@stencil/core';

interface OdsCollapsibleEvent {
/**
* Event triggered on collapsible toggle
*/
odsCollapsibleToggle: EventEmitter<boolean>;
}

export {
OdsCollapsibleEvent,
};
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
import { E2EElement, E2EPage, newE2EPage } from '@stencil/core/testing';
import {
OdsCollapsibleAttributes,
OdsComponentAttributes2StringAttributes,
odsCollapsibleDefaultAttributes,
} from '@ovhcloud/ods-core';
import { OdsCreateAttributes, OdsStringAttributes2Str, odsCollapsibleBaseAttributes } from '@ovhcloud/ods-testing';
import type { E2EPage } from '@stencil/core/testing';
import type { OdsCollapsibleAttribute } from './interfaces/attributes';
import { newE2EPage } from '@stencil/core/testing';
import { odsComponentAttributes2StringAttributes, odsStringAttributes2Str } from '@ovhcloud/ods-common-testing';
import { DEFAULT_ATTRIBUTE } from './constants/default-attributes';

describe('e2e:osds-collapsible', () => {
let page: E2EPage;
let el: E2EElement;

async function setup({ attributes = {}, html = `` }: { attributes?: Partial<OdsCollapsibleAttributes>, html?: string } = {}) {
const minimalAttributes: OdsCollapsibleAttributes = OdsCreateAttributes(attributes, odsCollapsibleBaseAttributes);
const stringAttributes = OdsComponentAttributes2StringAttributes<OdsCollapsibleAttributes>(minimalAttributes, odsCollapsibleDefaultAttributes);
async function setup({ attributes = {}, html = `` }: { attributes?: Partial<OdsCollapsibleAttribute>, html?: string } = {}) {
const stringAttributes = odsComponentAttributes2StringAttributes<OdsCollapsibleAttribute>(attributes, DEFAULT_ATTRIBUTE);

page = await newE2EPage();
await page.setContent(`
<osds-collapsible ${OdsStringAttributes2Str(stringAttributes)}>
<osds-collapsible ${odsStringAttributes2Str(stringAttributes)}>
${html}
</osds-collapsible>
`);
await page.evaluate(() => document.body.style.setProperty('margin', '0px'));
el = await page.find('osds-collapsible');
}

describe('screenshots', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { E2EElement, E2EPage, newE2EPage } from '@stencil/core/testing';
import { OdsCollapsibleAttributes, OdsComponentAttributes2StringAttributes, odsCollapsibleDefaultAttributes } from '@ovhcloud/ods-core';
import { OdsCreateAttributes, OdsStringAttributes2Str } from '@ovhcloud/ods-testing';
import type { E2EElement, E2EPage } from '@stencil/core/testing';
import type { OdsCollapsibleAttribute } from './interfaces/attributes';
import { odsComponentAttributes2StringAttributes, odsStringAttributes2Str } from '@ovhcloud/ods-common-testing';
import { newE2EPage } from '@stencil/core/testing';
import { DEFAULT_ATTRIBUTE } from './constants/default-attributes';

describe('e2e:osds-collapsible', () => {
let page: E2EPage;
let el: E2EElement;

async function setup({ attributes, html = '' }: { attributes: Partial<OdsCollapsibleAttributes>, html?: string }) {
const minimalAttributes: OdsCollapsibleAttributes = OdsCreateAttributes(attributes, odsCollapsibleDefaultAttributes);
const stringAttributes = OdsComponentAttributes2StringAttributes<OdsCollapsibleAttributes>(minimalAttributes, odsCollapsibleDefaultAttributes);
async function setup({ attributes = {}, html = '' }: { attributes?: Partial<OdsCollapsibleAttribute>, html?: string } = {}) {
const stringAttributes = odsComponentAttributes2StringAttributes<OdsCollapsibleAttribute>(attributes, DEFAULT_ATTRIBUTE);

page = await newE2EPage();
await page.setContent(`<osds-collapsible ${OdsStringAttributes2Str(stringAttributes)}>${html}</osds-collapsible>`);
await page.setContent(`<osds-collapsible ${odsStringAttributes2Str(stringAttributes)}>${html}</osds-collapsible>`);
await page.evaluate(() => document.body.style.setProperty('margin', '0px'));

el = await page.find('osds-collapsible');
Expand All @@ -38,5 +39,4 @@ describe('e2e:osds-collapsible', () => {
expect(componentOpened).toBe(true);
});
});

});
Loading

0 comments on commit 4c1dfec

Please sign in to comment.