import { createFelaRenderer } from '@fluentui/react-northstar-fela-renderer';
import { ICSSInJSStyle } from '@fluentui/styles';
// @ts-ignore
import { createSnapshot } from 'jest-react-fela';
import * as React from 'react';
import { FelaComponent } from 'react-fela';
const felaRenderer = (createFelaRenderer() as any).getOriginalRenderer();
describe('felaRenderer', () => {
test('basic styles are rendered', () => {
const snapshot = createSnapshot(, {}, felaRenderer);
expect(snapshot).toMatchSnapshot();
});
test('CSS fallback values are rendered', () => {
const snapshot = createSnapshot(, {}, felaRenderer);
expect(snapshot).toMatchSnapshot();
});
test('keyframe colors are rendered', () => {
const styles: ICSSInJSStyle = {
animationName: {
keyframe: ({ fromColor, toColor }) => ({
from: {
color: fromColor,
},
to: {
color: toColor,
},
}),
params: {
fromColor: 'red',
toColor: 'blue',
},
},
animationDuration: '5s',
};
const snapshot = createSnapshot(, {}, felaRenderer);
expect(snapshot).toMatchSnapshot();
});
test('array returned by keyframe results in CSS fallback values', () => {
const styles: ICSSInJSStyle = {
animationName: {
keyframe: ({ steps }) => {
const obj = {};
steps.forEach((step: string) => {
(obj as any)[step] = { color: ['blue', 'red', 'yellow'] };
});
return obj;
},
params: { steps: ['0%', '100%'] },
},
};
const snapshot = createSnapshot(, {}, felaRenderer);
expect(snapshot).toMatchSnapshot();
});
test('animations are not applied if animations are disabled', () => {
const styles: ICSSInJSStyle = {
animationName: {
keyframe: {
from: {
transform: 'rotate(0deg)',
},
to: {
transform: 'rotate(360deg)',
},
},
},
};
const snapshot = createSnapshot(, {}, felaRenderer);
expect(snapshot).toMatchSnapshot();
});
test('marginLeft is rendered into marginRight due to RTL', () => {
const snapshot = createSnapshot(, { rtl: true }, felaRenderer);
expect(snapshot).toMatchSnapshot();
});
test('marginLeft is rendered into marginLeft due to RTL with `noFlip`', () => {
const snapshot = createSnapshot(, {}, felaRenderer);
expect(snapshot).toMatchSnapshot();
});
test('styles are expanded to longhand values', () => {
const snapshot = createSnapshot(
,
{},
felaRenderer,
);
expect(snapshot).toMatchSnapshot();
});
test('prefixes required styles', () => {
const snapshot = createSnapshot(
,
{},
felaRenderer,
);
expect(snapshot).toMatchSnapshot();
});
});