tw-themes
Version:
powerful tailwind color themes (dynamically selectable at run-time)
246 lines (243 loc) • 10.1 kB
JavaScript
;
var _initTwThemes = _interopRequireDefault(require("../initTwThemes"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
describe('initTwThemes() ERRORS', () => {
describe('initTwThemes() Schema Issues', () => {
test('schema required', () => {
expect(() => (0, _initTwThemes.default)()).toThrow(/schema is required/);
});
test('basic schema type', () => {
expect(() => (0, _initTwThemes.default)("bad schema type")).toThrow(/schema must be an array of strings/);
});
test('Empty schema', () => {
expect(() => (0, _initTwThemes.default)([], {})).toThrow(/schema must contain at least one context color/);
});
test('bad schema element', () => {
expect(() => (0, _initTwThemes.default)([123], {})).toThrow(/invalid schema element.*expecting a string.*string wrapped/);
});
test('bad schema shaded ContextColor', () => {
expect(() => (0, _initTwThemes.default)(['context1', ['context2', '2nd elm bad']], {})).toThrow(/shaded contextColor must be a single element/);
});
test('bad schema shaded ContextColor type', () => {
expect(() => (0, _initTwThemes.default)(['context1', [123]], {})).toThrow(/shaded contextColor must be a single element.*array of type string/);
});
test('duplicate schema ContextColor', () => {
expect(() => (0, _initTwThemes.default)(['context1', 'context1'], {
myTheme: {
contextColors: {
context1: 'red-100'
}
}
})).toThrow(/schema contains duplicate contextColor.*context1/);
});
test('duplicate schema ContextColor multi-color', () => {
expect(() => (0, _initTwThemes.default)(['context1', ['context1']], {
myTheme: {
contextColors: {
context1: 'red-100'
}
}
})).toThrow(/schema contains duplicate contextColor.*context1/);
});
});
describe('initTwThemes() Themes Issues', () => {
test('themes required', () => {
expect(() => (0, _initTwThemes.default)(['primary'])).toThrow(/themes is required/);
});
test('basic themes type', () => {
expect(() => (0, _initTwThemes.default)(['primary'], 'bad themes type')).toThrow(/themes must be a JSON structure/);
});
test('empty themes', () => {
expect(() => (0, _initTwThemes.default)(['primary'], {})).toThrow(/themes must contain at least one theme/);
});
});
describe('initTwThemes() Individual Theme Issues', () => {
test('basic theme type', () => {
expect(() => (0, _initTwThemes.default)(['primary'], {
myTheme: 'bad theme type'
})).toThrow(/theme:.*myTheme.*must reference a JSON structure/);
});
test('theme missing contextColors', () => {
expect(() => (0, _initTwThemes.default)(['primary'], {
myTheme: {}
})).toThrow(/theme:.*myTheme.*must contain a contextColors property/);
});
test('themes contextColors bad type', () => {
expect(() => (0, _initTwThemes.default)(['primary'], {
myTheme: {
contextColors: 'not a JSON struct'
}
})).toThrow(/theme:.*myTheme.*contextColors field must reference a JSON structure/);
});
test('themes contextColors bad realColor type', () => {
expect(() => (0, _initTwThemes.default)(['primary'], {
myTheme: {
contextColors: {
primary: 123
}
}
})).toThrow(/theme:.*myTheme.*contextColor:.*primary.*must reference a string-based realColor/);
});
test('themes contextColor miss-match to schema', () => {
expect(() => (0, _initTwThemes.default)(['primary'], {
myTheme: {
contextColors: {
dillWeed: 'realColor'
}
}
})).toThrow(/theme:.*myTheme.*contextColor:.*dillWeed.*realColor:.*realColor.*the contextColor is NOT defined in the schema/);
});
test('themes realColor too many dashes', () => {
expect(() => (0, _initTwThemes.default)(['primary'], {
myTheme: {
contextColors: {
primary: 'too-many-dashes'
}
}
})).toThrow(/theme:.*myTheme.*contextColor:.*primary.*realColor:.*too-many-dashes.*invalid realColor: only a single suffix dash is supported.*for a color shade/);
});
test('themes realColor should reference multi-color', () => {
expect(() => (0, _initTwThemes.default)([['primary']], {
myTheme: {
contextColors: {
primary: 'red-100'
}
}
})).toThrow(/theme:.*myTheme.*contextColor:.*primary.*realColor:.*red-100.*invalid realColor:.*references a single tailwind shaded color.*schema requires a multi-color/);
});
test('themes realColor references invalid tailwind color', () => {
expect(() => (0, _initTwThemes.default)(['primary'], {
myTheme: {
contextColors: {
primary: 'bad-100'
}
}
})).toThrow(/theme:.*myTheme.*contextColor:.*primary.*realColor:.*bad-100.*invalid realColor:.*references an invalid tailwind color/);
});
test('themes realColor references invalid tailwind color shade', () => {
expect(() => (0, _initTwThemes.default)(['primary'], {
myTheme: {
contextColors: {
primary: 'red-123'
}
}
})).toThrow(/theme:.*myTheme.*contextColor:.*primary.*realColor:.*red-123.*invalid realColor:.*references an invalid tailwind color shade.*123 does NOT exist/);
});
test('themes realColor references single CSS color but requires multi-shaded tailwind color', () => {
expect(() => (0, _initTwThemes.default)([['primary']], {
myTheme: {
contextColors: {
primary: '#ff33b2'
}
}
})).toThrow(/theme:.*myTheme.*contextColor:.*primary.*realColor:.*#ff33b2.*invalid realColor:.*references a single CSS color.*#ff33b2.*schema requires a multi-color shaded context color.*supplied by a tailwind/);
});
test('themes realColor references single tailwind color (black/white) but requires multi-shaded tailwind color', () => {
expect(() => (0, _initTwThemes.default)([['primary']], {
myTheme: {
contextColors: {
primary: 'black'
}
}
})).toThrow(/theme:.*myTheme.*contextColor:.*primary.*realColor:.*black.*invalid realColor:.*references a single tailwind color.*black.*white.*but the schema requires a multi-color shaded context color/);
});
test('themes realColor references multi-shaded tailwind color (without a dash) but requires single-color', () => {
expect(() => (0, _initTwThemes.default)(['primary'], {
myTheme: {
contextColors: {
primary: 'red'
}
}
})).toThrow(/theme:.*myTheme.*contextColor:.*primary.*realColor:.*red.*invalid realColor:.*references multiple tailwind shaded colors.*schema requires a single-color/);
});
test('no content realColor', () => {
expect(() => (0, _initTwThemes.default)(['primary'], {
myTheme: {
contextColors: {
primary: ' '
}
}
})).toThrow(/theme:.*myTheme.*contextColor:.*primary.*realColor:.*the realColor has NO content/);
});
test('missing context colors', () => {
expect(() => (0, _initTwThemes.default)(['primary', 'secondary', 'dillweed'], {
myTheme: {
contextColors: {
primary: 'red-100'
}
}
})).toThrow(/theme:.*myTheme.*missing the following context color definitions.*secondary.*dillweed/);
});
});
describe('initTwThemes() initial param issues', () => {
test('initialThemeName NOT string', () => {
expect(() => (0, _initTwThemes.default)(['primary'], {
myTheme: {
contextColors: {
primary: '#ffb2c3'
}
}
}, 123)).toThrow(/initialThemeName.*when supplied.*must be a string/);
});
test('initialThemeName NOT in themes', () => {
expect(() => (0, _initTwThemes.default)(['primary'], {
myTheme: {
contextColors: {
primary: '#ffb2c3'
}
}
}, 'DillWeed')).toThrow(/initialThemeName.*DillWeed.*IS NOT defined in themes/);
});
test('initialInvertShade NOT boolean', () => {
expect(() => (0, _initTwThemes.default)(['primary'], {
myTheme: {
contextColors: {
primary: '#ffb2c3'
}
}
}, 'myTheme', 123)).toThrow(/initialInvertShade.*when supplied.*must be a boolean/);
});
});
describe('TwThemes.activateTheme() issues', () => {
const TwThemes = (0, _initTwThemes.default)(['primary'], {
myTheme: {
contextColors: {
primary: '#ffb2c3'
}
}
});
test('themeName NOT string', () => {
expect(() => TwThemes.activateTheme({
themeName: 123
})).toThrow(/themeName.*when supplied.*must be a string/);
});
test('themeName NOT in themes', () => {
expect(() => TwThemes.activateTheme({
themeName: 'DillWeed'
})).toThrow(/supplied themeName.*DillWeed.*IS NOT defined in themes/);
});
test('invertShade NOT boolean', () => {
expect(() => TwThemes.activateTheme({
themeName: 'myTheme',
invertShade: 123
})).toThrow(/invertShade.*when supplied.*must be a boolean/);
});
test('unrecognized named parameter', () => {
expect(() => TwThemes.activateTheme({
themeName: 'myTheme',
invertShade: true,
oops: 'bad param',
doodle: 'another bad param'
})).toThrow(/unrecognized named parameter.*oops.*doodle/);
});
test('bad positional parameter', () => {
expect(() => TwThemes.activateTheme({
themeName: 'myTheme',
invertShade: true
}, 123)).toThrow(/unrecognized positional parameter.*only named parameters may be specified.*2 positional parameters were found/);
});
test('bad named parameters', () => {
expect(() => TwThemes.activateTheme(123)).toThrow(/uses named parameters/);
});
});
});