Skip to content

Commit

Permalink
feature(Storybook): updates new test docs to v7 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
arwehrman committed Jul 19, 2023
1 parent 7a847f2 commit 6aa6f64
Show file tree
Hide file tree
Showing 14 changed files with 19,789 additions and 204 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{/* prettier-ignore */}
{/*Copyright 2023 Comcast Cable Communications Management, LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
SPDX-License-Identifier: Apache-2.0\*/}

import { Meta } from '@storybook/blocks';

<Meta title="Documentation / Unit Testing / Overview" />

# @lightningjs/ui-components-test-utils

The `@lightningjs/ui-components-test-utils` package provides 2 artifacts to assist with unit testing Lightning components.

1. **Test Renderer**

- [create](/story/docs-unit-testing-test-renderer-create--page): Generates a `testRenderer` object with built in utilities for unit testing Lightning Components.
- [toJSON](/story/docs-unit-testing-test-renderer-tojson--page): Converts Lightning components to JSON to be used in [Jest Snapshot Tests](https://jestjs.io/docs/snapshot-testing)

2. **Test Utils**

- [makeCreateComponent](/story/docs-unit-testing-test-utils-makecreatecomponent--page): Returns a `createComponent` function which is used to generate an instance of a component to run unit test cases against.
- [completeAnimation](/story/docs-unit-testing-test-utils-completeanimation--page): Returns a Promise that resolves once all animating properties have updated to their target value(s).
- [fastForward](/story/docs-unit-testing-test-utils-fastforward--page): Force all running Lightning Transitions on one or more Lightning Elements to finish and update the transitioning property to its target value immediately.
- [nextTick](/story/docs-unit-testing-test-utils-nexttick--page): Creates a Promise that resolves after a defined amount of time. If no amount of time is specified, the Promise will resolve immediately.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
<!--
Copyright 2023 Comcast Cable Communications Management, LLC
{/* prettier-ignore */}
{/*Copyright 2023 Comcast Cable Communications Management, LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
SPDX-License-Identifier: Apache-2.0\*/}

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
import { Meta } from '@storybook/blocks';

SPDX-License-Identifier: Apache-2.0
-->

import { Meta } from '@storybook/addon-docs';

<Meta title="Docs / Unit Testing / Test Renderer / create" />
<Meta title="Documentation / Unit Testing / Test Renderer / create" />

# create

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{/* prettier-ignore */}
{/*Copyright 2023 Comcast Cable Communications Management, LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
SPDX-License-Identifier: Apache-2.0\*/}

import { Meta } from '@storybook/blocks';

<Meta title="Documentation / Unit Testing / Test Renderer / toJSON" />

# toJSON

Convert Lightning components to JSON to be used in [Jest Snapshot Tests](https://jestjs.io/docs/snapshot-testing).

## Arguments

`toJSON(element, { children } = {})`

| argument | type | default | description |
| -------------- | ----------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------ |
| element | Lightning.Element | - | element to create JSON from |
| \{ children \} | object | \{ children: 100 \} | object with `children` property to define the number of layers deep in the render tree should be converted to JSON |

<br />

##### Example: Snapshot testing using `TestRenderer.toJSON` and Jest's `toMatchSnapshot` matcher

```js
import lng from '@lightningjs/core';
import { TestRenderer } from '@lightningjs/ui-components-test-utils';

class TestComp extends lng.Component {
static _template() {
return {
TextElement: {
text: { text: 'foo' }
}
};
}
}

it('should match the snapshot for the component', () => {
const testRenderer = TestRenderer.create({ Component: { type: TestComp } });
const testCompInstance = testRenderer.getInstance();
const tree = TestRenderer.toJSON(testCompInstance, { children: 1 });
expect(tree).toMatchSnapshot();
});
```

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
<!--
Copyright 2023 Comcast Cable Communications Management, LLC
{/* prettier-ignore */}
{/*Copyright 2023 Comcast Cable Communications Management, LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
SPDX-License-Identifier: Apache-2.0\*/}

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
import { Meta } from '@storybook/blocks';

SPDX-License-Identifier: Apache-2.0
-->

import { Meta } from '@storybook/addon-docs';

<Meta title="Docs / Unit Testing / Test Utils / completeAnimation" />
<Meta title="Documentation / Unit Testing / Test Utils / completeAnimation" />

# completeAnimation

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
<!--
Copyright 2023 Comcast Cable Communications Management, LLC
{/* prettier-ignore */}
{/*Copyright 2023 Comcast Cable Communications Management, LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
SPDX-License-Identifier: Apache-2.0\*/}

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
import { Meta } from '@storybook/blocks';

SPDX-License-Identifier: Apache-2.0
-->

import { Meta } from '@storybook/addon-docs';

<Meta title="Docs / Unit Testing / Test Utils / fastForward" />
<Meta title="Documentation / Unit Testing / Test Utils / fastForward" />

# fastForward

Expand All @@ -30,9 +27,9 @@ This function is similar to [completeAnimation](/story/docs-unit-testing-test-ut

`fastForward(elements)`

| argument | type | default | description |
| -------- | ---------------------------------------------- | ------- | --------------------------------------------- |
| elements | Array<Lightning.Element\> \| Lightning.Element | - | element(s) with transitioning property values |
| argument | type | default | description |
| -------- | ----------------------------------------------- | ------- | --------------------------------------------- |
| elements | Array\<Lightning.Element\> \| Lightning.Element | - | element(s) with transitioning property values |

<br />

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
<!--
Copyright 2023 Comcast Cable Communications Management, LLC
{/* prettier-ignore */}
{/*Copyright 2023 Comcast Cable Communications Management, LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
SPDX-License-Identifier: Apache-2.0\*/}

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
import { Meta } from '@storybook/blocks';

SPDX-License-Identifier: Apache-2.0
-->

import { Meta } from '@storybook/addon-docs';

<Meta title="Docs / Unit Testing / Test Utils / makeCreateComponent " />
<Meta title="Documentation / Unit Testing / Test Utils / makeCreateComponent " />

# makeCreateComponent

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{/* prettier-ignore */}
{/*Copyright 2023 Comcast Cable Communications Management, LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
SPDX-License-Identifier: Apache-2.0\*/}

import { Meta } from '@storybook/blocks';

<Meta title="Documentation / Unit Testing / Test Utils / nextTick" />

# nextTick

Creates a Promise that resolves after a defined amount of time. If no amount of time is specified, the Promise will resolve immediately.

## Arguments

`nextTick(wait = 0)`

| argument | type | default | description |
| -------- | ------ | ------- | --------------------------------------------------------------------- |
| wait | number | 0 | amount of time (in milliseconds) before the returned Promise resolves |
Loading

0 comments on commit 6aa6f64

Please sign in to comment.