chore(blockTools): Fix test imports.

This commit is contained in:
Gervwyk 2021-10-23 23:29:57 +02:00
parent 96016f5d3c
commit da29ab72f0
9 changed files with 122 additions and 57 deletions

View File

@ -14,8 +14,9 @@
limitations under the License.
*/
import { runRenderTests } from '@lowdefy/block-dev';
import examples from '../../demo/examples/Skeleton.yaml';
import runRenderTests from '../runRenderTests';
import Skeleton from './Skeleton';
runRenderTests({ examples, Block: Skeleton, meta: {} });

View File

@ -14,8 +14,9 @@
limitations under the License.
*/
import { runRenderTests } from '@lowdefy/block-dev';
import examples from '../../demo/examples/SkeletonAvatar.yaml';
import runRenderTests from '../runRenderTests';
import SkeletonAvatar from './SkeletonAvatar';
runRenderTests({ examples, Block: SkeletonAvatar, meta: {} });

View File

@ -13,9 +13,9 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
import { runRenderTests } from '@lowdefy/block-dev';
import examples from '../../demo/examples/SkeletonButton.yaml';
import runRenderTests from '../runRenderTests';
import SkeletonButton from './SkeletonButton';
runRenderTests({ examples, Block: SkeletonButton, meta: {} });

View File

@ -13,9 +13,9 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
import { runRenderTests } from '@lowdefy/block-dev';
import examples from '../../demo/examples/SkeletonInput.yaml';
import runRenderTests from '../runRenderTests';
import SkeletonInput from './SkeletonInput';
runRenderTests({ examples, Block: SkeletonInput, meta: {} });

View File

@ -13,9 +13,9 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
import { runRenderTests } from '@lowdefy/block-dev';
import examples from '../../demo/examples/SkeletonParagraph.yaml';
import runRenderTests from '../runRenderTests';
import SkeletonParagraph from './SkeletonParagraph';
runRenderTests({ examples, Block: SkeletonParagraph, meta: {} });

View File

@ -13,9 +13,9 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
import { runRenderTests } from '@lowdefy/block-dev';
import examples from '../../demo/examples/IconSpinner.yaml';
import runRenderTests from '../runRenderTests';
import IconSpinner from './IconSpinner';
runRenderTests({ examples, Block: IconSpinner, meta: {} });

View File

@ -13,9 +13,9 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
import { runRenderTests } from '@lowdefy/block-dev';
import examples from '../../demo/examples/Spinner.yaml';
import runRenderTests from '../runRenderTests';
import Spinner from './Spinner';
runRenderTests({ examples, Block: Spinner, meta: {} });

View File

@ -15,7 +15,6 @@
*/
import blockDefaultProps from './blockDefaultProps';
import BlockSchemaErrors from './BlockSchemaErrors';
import ErrorBoundary from './ErrorBoundary';
import HtmlComponent from './HtmlComponent';
import IconSpinner from './Spinner/IconSpinner';
@ -23,25 +22,18 @@ import Loading from './Loading';
import loadWebpackFederatedModule from './loadWebpackFederatedModule';
import makeCssClass from './makeCssClass.js';
import mediaToCssObject from './mediaToCssObject.js';
import mockBlock from './mockBlock';
import renderHtml from './renderHtml';
import runBlockSchemaTests from './runBlockSchemaTests';
import runMockMethodTests from './runMockMethodTests';
import runMockRenderTests from './runMockRenderTests';
import runRenderTests from './runRenderTests';
import Skeleton from './Skeleton/Skeleton';
import SkeletonAvatar from './Skeleton/SkeletonAvatar';
import SkeletonButton from './Skeleton/SkeletonButton';
import SkeletonInput from './Skeleton/SkeletonInput';
import SkeletonParagraph from './Skeleton/SkeletonParagraph';
import Spinner from './Spinner/Spinner';
import stubBlockProps from './stubBlockProps';
import useDynamicScript from './useDynamicScript';
import useRunAfterUpdate from './useRunAfterUpdate';
export {
blockDefaultProps,
BlockSchemaErrors,
ErrorBoundary,
HtmlComponent,
IconSpinner,
@ -49,19 +41,13 @@ export {
loadWebpackFederatedModule,
makeCssClass,
mediaToCssObject,
mockBlock,
renderHtml,
runBlockSchemaTests,
runMockMethodTests,
runMockRenderTests,
runRenderTests,
Skeleton,
SkeletonAvatar,
SkeletonButton,
SkeletonInput,
SkeletonParagraph,
Spinner,
stubBlockProps,
useDynamicScript,
useRunAfterUpdate,
};

View File

@ -17,12 +17,12 @@
import mediaToCssObject from '../src/mediaToCssObject';
test('no object', () => {
expect(mediaToCssObject()).toEqual({});
expect(mediaToCssObject()).toEqual([]);
});
test('object with null obj to pass', () => {
const obj = null;
expect(mediaToCssObject(obj)).toEqual({});
expect(mediaToCssObject(obj)).toEqual([]);
});
test('object with no media unchanged', () => {
@ -31,6 +31,36 @@ test('object with no media unchanged', () => {
b: 1,
c: { a: 'b' },
};
expect(mediaToCssObject(obj)).toEqual([obj]);
});
test('array of media objects passed to emotion', () => {
const obj = [
{
a: 'a',
b: 1,
c: { a: 'b' },
},
{
a: 'x',
b: 4,
},
];
expect(mediaToCssObject(obj)).toEqual(obj);
});
test('string style definitions', () => {
const obj = 'background-color: red;';
expect(mediaToCssObject(obj)).toEqual(obj);
});
test('array of string style definitions', () => {
const obj = ['background-color: red;', 'font-size: 12px;'];
expect(mediaToCssObject(obj)).toEqual(obj);
});
test('array of mixed style definitions', () => {
const obj = ['background-color: red;', { value: 'one' }];
expect(mediaToCssObject(obj)).toEqual(obj);
});
@ -45,24 +75,29 @@ test('object with all media', () => {
xxl: { a: 'xxl' },
};
expect(mediaToCssObject(obj)).toMatchInlineSnapshot(`
Object {
"@media screen and (max-width: 576px)": Object {
"a": "xs",
Array [
Object {
"@media screen and (max-width: 576px)": Object {
"a": "xs",
},
"@media screen and (min-width: 1200px)": Object {
"a": "xl",
},
"@media screen and (min-width: 1600px)": Object {
"a": "xxl",
},
"@media screen and (min-width: 576px)": Object {
"a": "sm",
},
"@media screen and (min-width: 768px)": Object {
"a": "md",
},
"@media screen and (min-width: 992px)": Object {
"a": "lg",
},
"a": "a",
},
"@media screen and (min-width: 1200px)": Object {
"a": "xxl",
},
"@media screen and (min-width: 576px)": Object {
"a": "md",
},
"@media screen and (min-width: 768px)": Object {
"a": "lg",
},
"@media screen and (min-width: 992px)": Object {
"a": "xl",
},
"a": "a",
}
]
`);
});
@ -77,23 +112,65 @@ test('object with all media with react option', () => {
xxl: { a: 'xxl' },
};
expect(mediaToCssObject(obj, { react: true })).toMatchInlineSnapshot(`
Object {
"@media screen and (maxWidth: 576px)": Object {
"a": "xs",
Array [
Object {
"@media screen and (maxWidth: 576px)": Object {
"a": "xs",
},
"@media screen and (minWidth: 1200px)": Object {
"a": "xl",
},
"@media screen and (minWidth: 1600px)": Object {
"a": "xxl",
},
"@media screen and (minWidth: 576px)": Object {
"a": "sm",
},
"@media screen and (minWidth: 768px)": Object {
"a": "md",
},
"@media screen and (minWidth: 992px)": Object {
"a": "lg",
},
"a": "a",
},
"@media screen and (minWidth: 1200px)": Object {
"a": "xxl",
},
"@media screen and (minWidth: 576px)": Object {
"a": "md",
},
"@media screen and (minWidth: 768px)": Object {
"a": "lg",
},
"@media screen and (minWidth: 992px)": Object {
"a": "xl",
},
"a": "a",
}
]
`);
});
test('string with all media', () => {
const obj = `{
a: 'a',
@media xs { a: 'xs' }
@media sm { a: 'sm' }
@media md{ a: 'md' }
@media lg { a: 'lg' }
@media xl{ a: 'xl' }
@media xxl { a: 'xxl' }
}`;
expect(mediaToCssObject(obj)).toMatchInlineSnapshot(`
"{
a: 'a',
@media screen and (max-width: 576px) { a: 'xs' }
@media screen and (min-width: 576px) { a: 'sm' }
@media screen and (min-width: 768px) { a: 'md' }
@media screen and (min-width: 992px) { a: 'lg' }
@media screen and (min-width: 1200px) { a: 'xl' }
@media screen and (min-width: 1600px) { a: 'xxl' }
}"
`);
});
test('array of mixed types with all media', () => {
const obj = [`{a: 'a', @media xs { a: 'xs' }}`, 1, true, { xl: { a: 'xl' } }];
expect(mediaToCssObject(obj)).toEqual([
`{a: 'a', @media screen and (max-width: 576px) { a: 'xs' }}`,
{},
{},
{
'@media screen and (min-width: 1200px)': {
a: 'xl',
},
},
]);
});