Skip to content

Commit

Permalink
fix(code): fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
skhamvon authored and dpellier committed Aug 25, 2023
1 parent cdb5a14 commit 71a571a
Show file tree
Hide file tree
Showing 53 changed files with 106 additions and 1,954 deletions.
82 changes: 82 additions & 0 deletions packages-new/components/code/documentation/specifications/spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
* [**Interfaces**](#interfaces)
* [**Types**](#types)
* [**Classes**](#classes)
* [**Type alias**](#type-alias)
* [**Variables**](#variables)

## Interfaces

### OdsCodeAttributes
|name | Type | Required | Default | Description|
|---|---|:---:|---|---|
|**`color`** | `OdsThemeColorIntent` | | | main color: see component principles|
|**`contrasted`** | _boolean_ | | | contrasted or not: see component principles|
|**`size`** | `md` | | | size: see component principles|

### OdsCodeBehavior
|name | Type | Required | Default | Description|
|---|---|:---:|---|---|
|**`codeEl`** | `HTMLElement` | ✴️ | | reference to the vanilla code element.|
|**`el`** | `HTMLElement` | ✴️ | | reference to the host element.|
|**`beforeInit`** | _void_ | ✴️ | | before init component function.should be called before component init.should autocomplete the content with an ods-button and an ods-icon|
|**`createCopyIconElement`** | `HTMLElement` | ✴️ | | create an element that is an ods icon.Used when the OdsCodeController need to automatically create an icon.|
|**`emitCopy`** | _void_ | ✴️ | | emit code copy|
|**`onCopyClick`** | _void_ | ✴️ | | on click on the copy button, it should copy the contentby calling `controller.copyCode`|

### OdsCodeEvents
|name | Type | Required | Default | Description|
|---|---|:---:|---|---|
|**`odsCodeCopy`** | _void_ | ✴️ | | Event triggered on code content copy|

## Types

### OdsCodeSize
| |
|:---:|
| `md` |

## Classes

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

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

> **copyCode**() => _unknown_


### OdsCodeMock

## Type alias

### OdsCode

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

> - `OdsComponentGenericMethods`
> - `OdsComponentGenericEvents`
### OdsCodeMethods

### OdsCodeAttributes

> _Based on `OdsComponentAttributes`_
### OdsCodeEvents

> _Based on `OdsComponentEvents`_
## Variables

### odsCodeDefaultAttributes
`OdsCodeAttributes`

### odsCodeDefaultAttributesDoc
`OdsCodeAttributes`
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ class OdsCodeMock extends OsdsCode {
super();
Object.assign(this, attribute)
}
codeEl = document.createElement('code') as HTMLElement;
controller: OdsCodeController = jest.fn() as unknown as OdsCodeController;
beforeRender = jest.fn();
copyCode = jest.fn();
autocompleteCopySlot = jest.fn();
codeEl = document.createElement('code') as HTMLElement;
}

describe('spec:ods-code-controller', () => {
Expand All @@ -29,7 +32,6 @@ describe('spec:ods-code-controller', () => {
}

beforeEach(() => {

const loggerMocked = new OdsLogger('myLoggerMocked');
loggerSpyReferences = OdsInitializeLoggerSpy({
loggerMocked: loggerMocked as never,
Expand All @@ -48,7 +50,17 @@ describe('spec:ods-code-controller', () => {

describe('methods', () => {
describe('methods:copyCode', () => {
it('should copy code content to clipboard', () => {
beforeEach(() => {
Object.assign(navigator, {
clipboard: {
writeText: jest.fn().mockImplementation(() => Promise.resolve()),
},
});
});

// FIXME seems like testing slot text content is not possible for now as assignedNodes function is not available
// (see https://github.com/ionic-team/stencil/issues/2830)
xit('should copy code content to clipboard', () => {
setup();
const textNode = document.createTextNode('Code content');
const slot = document.createElement('slot');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EventEmitter } from '@stencil/core';
import type { EventEmitter } from '@stencil/core';

interface OdsCodeEvent {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
jest.mock('./core/controller'); // keep jest.mock before any import

import type { SpecPage } from '@stencil/core/testing';
import type { OdsCodeAttribute } from './interfaces/attributes';
import { newSpecPage } from '@stencil/core/testing';
Expand Down Expand Up @@ -33,6 +35,8 @@ describe('spec:osds-code', () => {

instance = page.rootInstance;

controller = (OdsCodeController as unknown as jest.SpyInstance<OdsCodeController, unknown[]>).mock.instances[ 0 ];

// note: assigned slot not yet available in HtmlMockedElement of stencil : https://github.com/ionic-team/stencil/issues/2830
mainSlot = page.root?.shadowRoot?.querySelector('slot:not([name])');
copySlot = page.root?.shadowRoot?.querySelector('slot[name="copy"]');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export type { OdsCodeAttribute } from './interfaces/attributes';
export type { OdsCodeEvent } from './interfaces/events';
export { ODS_CODE_SIZE, ODS_CODE_SIZES } from './constants/code-size';
export { OsdsCode } from './osds-code';
35 changes: 0 additions & 35 deletions packages/stencil/components/code/.gitignore

This file was deleted.

4 changes: 0 additions & 4 deletions packages/stencil/components/code/.npmignore

This file was deleted.

Loading

0 comments on commit 71a571a

Please sign in to comment.