From 68622ba613e5683caef46dcab0b48b17f6ed33eb Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Wed, 1 Jan 2020 15:44:23 -0800 Subject: [PATCH 1/2] chore(jest): stub carbon-icons-svelte --- package.json | 3 +++ src/internal/Icon.stub.svelte | 45 +++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 src/internal/Icon.stub.svelte diff --git a/package.json b/package.json index 1205e636..95dc9005 100644 --- a/package.json +++ b/package.json @@ -92,6 +92,9 @@ "js", "svelte" ], + "moduleNameMapper": { + "^carbon-icons-svelte*": "src/internal/Icon.stub.svelte" + }, "setupFilesAfterEnv": [ "regenerator-runtime/runtime", "@testing-library/jest-dom/extend-expect" diff --git a/src/internal/Icon.stub.svelte b/src/internal/Icon.stub.svelte new file mode 100644 index 00000000..8d2e37b9 --- /dev/null +++ b/src/internal/Icon.stub.svelte @@ -0,0 +1,45 @@ + + + + + {#if title} + {title} + {/if} + + From 1077eef283b260604d698dfd4de481b634e435a2 Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Wed, 1 Jan 2020 15:51:22 -0800 Subject: [PATCH 2/2] test(components): add InlineLoading, Loading unit tests --- .../InlineLoading/InlineLoading.test.js | 18 ++++++++++++++++++ src/components/Loading/Loading.test.js | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/components/InlineLoading/InlineLoading.test.js create mode 100644 src/components/Loading/Loading.test.js diff --git a/src/components/InlineLoading/InlineLoading.test.js b/src/components/InlineLoading/InlineLoading.test.js new file mode 100644 index 00000000..12b3b473 --- /dev/null +++ b/src/components/InlineLoading/InlineLoading.test.js @@ -0,0 +1,18 @@ +import { render } from '@testing-library/svelte'; +import Component from './InlineLoading.svelte'; + +test('InlineLoading', () => { + const { container, rerender } = render(Component, { + description: 'description', + iconDescription: 'icon description' + }); + + expect(container.querySelector('.bx--inline-loading')).toHaveTextContent('description'); + expect(container.querySelector('.bx--loading')).toBeInTheDocument(); + + rerender({ props: { status: 'error' } }); + expect(container.querySelector('.bx--inline-loading--error')).toBeInTheDocument(); + + rerender({ props: { status: 'finished' } }); + expect(container.querySelector('.bx--inline-loading__checkmark-container')).toBeInTheDocument(); +}); diff --git a/src/components/Loading/Loading.test.js b/src/components/Loading/Loading.test.js new file mode 100644 index 00000000..72fffb04 --- /dev/null +++ b/src/components/Loading/Loading.test.js @@ -0,0 +1,18 @@ +import { render } from '@testing-library/svelte'; +import Component from './Loading.svelte'; + +test('Loading', () => { + const { container, rerender } = render(Component); + + let element = container.querySelector('.bx--loading-overlay'); + + expect(element).toBeInTheDocument(); + expect(element).not.toHaveClass('bx--loading-overlay--stop'); + expect(element.querySelector('.bx--loading__stroke')).toHaveAttribute('r', '37.5'); + + rerender({ props: { active: false, small: true, withOverlay: false } }); + + element = container.querySelector('.bx--loading'); + expect(element).toHaveClass('bx--loading--small', 'bx--loading--stop'); + expect(element.querySelector('.bx--loading__background')).toHaveAttribute('r', '26.8125'); +});