82 lines
3.2 KiB
JavaScript
82 lines
3.2 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
var merge_styles_1 = require("@fluentui/merge-styles");
|
|
var classNamesFunction_1 = require("./classNamesFunction");
|
|
var rtl_1 = require("./rtl");
|
|
describe('classNamesFunction', function () {
|
|
beforeEach(function () {
|
|
merge_styles_1.Stylesheet.getInstance().reset();
|
|
merge_styles_1.Stylesheet.getInstance().setConfig({
|
|
onInsertRule: function () {
|
|
/*no-op*/
|
|
},
|
|
});
|
|
});
|
|
afterEach(function () {
|
|
merge_styles_1.Stylesheet.getInstance().setConfig({
|
|
onInsertRule: undefined,
|
|
});
|
|
});
|
|
it('can cache rules', function () {
|
|
var styleFunction1Called = false;
|
|
var styleFunction2Called = false;
|
|
var getClassNames = (0, classNamesFunction_1.classNamesFunction)();
|
|
var getStyles1 = function (props) {
|
|
styleFunction1Called = true;
|
|
return {
|
|
root: { width: props.a },
|
|
};
|
|
};
|
|
var getStyles2 = function (props) {
|
|
styleFunction2Called = true;
|
|
return {
|
|
root: { height: props.a },
|
|
};
|
|
};
|
|
var classNames1 = getClassNames(getStyles1, { a: 1, b: 'test' });
|
|
var classNames2 = getClassNames(getStyles2, { a: 1, b: 'test' });
|
|
expect(styleFunction1Called).toEqual(true);
|
|
expect(styleFunction2Called).toEqual(true);
|
|
styleFunction1Called = false;
|
|
styleFunction2Called = false;
|
|
expect(getClassNames(getStyles1, { a: 1, b: 'test' })).toEqual(classNames1);
|
|
expect(styleFunction1Called).toEqual(false);
|
|
expect(getClassNames(getStyles2, { a: 1, b: 'test' })).toEqual(classNames2);
|
|
expect(styleFunction2Called).toEqual(false);
|
|
expect(getClassNames(getStyles1, { a: 2, b: 'test' })).not.toEqual(classNames1);
|
|
expect(styleFunction1Called).toEqual(true);
|
|
styleFunction1Called = false;
|
|
getClassNames(getStyles1, { a: 2, b: 'test' });
|
|
expect(styleFunction1Called).toEqual(false);
|
|
});
|
|
describe('ltr/rtl from theme', function () {
|
|
var originalRtl;
|
|
var setRule;
|
|
beforeEach(function () {
|
|
merge_styles_1.Stylesheet.getInstance().setConfig({
|
|
onInsertRule: function (rule) {
|
|
setRule = rule;
|
|
},
|
|
});
|
|
});
|
|
beforeEach(function () { return (originalRtl = (0, rtl_1.getRTL)()); });
|
|
afterEach(function () { return (0, rtl_1.setRTL)(originalRtl); });
|
|
var getClassNames = (0, classNamesFunction_1.classNamesFunction)();
|
|
var getStyles = function () {
|
|
return {
|
|
root: { left: 1 },
|
|
};
|
|
};
|
|
it('renders rtl if specified in theme', function () {
|
|
(0, rtl_1.setRTL)(false);
|
|
getClassNames(getStyles, { theme: { rtl: true } });
|
|
expect(setRule).toEqual('.root-0{right:1px;}');
|
|
});
|
|
it('renders ltr if specified in theme', function () {
|
|
(0, rtl_1.setRTL)(true);
|
|
getClassNames(getStyles, { theme: { rtl: false } });
|
|
expect(setRule).toEqual('.root-0{left:1px;}');
|
|
});
|
|
});
|
|
});
|
|
//# sourceMappingURL=classNamesFunction.test.js.map
|