Skip to content

Commit

Permalink
Update tests to cover more and Remove redundant transforms in `transl…
Browse files Browse the repository at this point in the history
…ateKeys`
  • Loading branch information
Thomas committed May 28, 2019
1 parent 24f2f65 commit 0fc2c62
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/node_modules
/coverage
58 changes: 58 additions & 0 deletions __tests__/fixtures/outputs/generator/hexColorBoxShadow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
module.exports = {
shadow: {
shadowColor: '#FF0000',
shadowOffset: {width: 0, height: 1},
shadowOpacity: 1,
shadowRadius: 3,
elevation: 1.5,
},
shadowMd: {
shadowColor: '#FFFF00',
shadowOffset: {width: 0, height: 4},
shadowOpacity: 1,
shadowRadius: 6,
elevation: 3,
},
shadowLg: {
shadowColor: '#FFFFFF',
shadowOffset: {width: 0, height: 10},
shadowOpacity: 1,
shadowRadius: 15,
elevation: 7.5,
},
shadowXl: {
shadowColor: '#00FF00',
shadowOffset: {width: 0, height: 20},
shadowOpacity: 1,
shadowRadius: 25,
elevation: 12.5,
},
shadow2xl: {
shadowColor: '#0000FF',
shadowOffset: {width: 0, height: 25},
shadowOpacity: 1,
shadowRadius: 50,
elevation: 25,
},
shadowInner: {
shadowColor: 'rgba(0, 0, 0, 0)',
shadowOffset: {width: 0, height: 0},
shadowOpacity: 0,
shadowRadius: 0,
elevation: 0,
},
shadowOutline: {
shadowColor: '#000FF0',
shadowOffset: {width: 0, height: 0},
shadowOpacity: 1,
shadowRadius: 0,
elevation: 0,
},
shadowNone: {
shadowColor: 'rgba(0, 0, 0, 0)',
shadowOffset: {width: 0, height: 0},
shadowOpacity: 0,
shadowRadius: 0,
elevation: 0,
},
};
42 changes: 42 additions & 0 deletions __tests__/fixtures/outputs/generator/hexColorTextShadow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module.exports = {
textShadow: {
textShadowColor: '#FF0000',
textShadowOffset: {width: 0, height: 1},
textShadowRadius: 3,
},
textShadow2xl: {
textShadowColor: '#0000FF',
textShadowOffset: {width: 0, height: 25},
textShadowRadius: 50,
},
textShadowInner: {
textShadowColor: 'rgba(0, 0, 0, 0)',
textShadowOffset: {width: 0, height: 0},
textShadowRadius: 0,
},
textShadowMd: {
textShadowColor: '#FFFF00',
textShadowOffset: {width: 0, height: 4},
textShadowRadius: 6,
},
textShadowLg: {
textShadowColor: '#FFFFFF',
textShadowOffset: {width: 0, height: 10},
textShadowRadius: 15,
},
textShadowXl: {
textShadowColor: '#00FF00',
textShadowOffset: {width: 0, height: 20},
textShadowRadius: 25,
},
textShadowOutline: {
textShadowColor: '#000FF0',
textShadowOffset: {width: 0, height: 0},
textShadowRadius: 0,
},
textShadowNone: {
textShadowColor: 'rgba(0, 0, 0, 0)',
textShadowOffset: {width: 0, height: 0},
textShadowRadius: 0,
},
};
16 changes: 16 additions & 0 deletions __tests__/fixtures/outputs/generator/zIndex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
z0: {zIndex: 0},
z10: {zIndex: 10},
z20: {zIndex: 20},
z30: {zIndex: 30},
z40: {zIndex: 40},
z50: {zIndex: 50},
zAuto: {zIndex: 0},
zK0: {zIndex: 0},
zK10: {zIndex: 10},
zK20: {zIndex: 20},
zK30: {zIndex: 30},
zK40: {zIndex: 40},
zK50: {zIndex: 50},
zKAuto: {zIndex: 0},
};
42 changes: 42 additions & 0 deletions __tests__/generator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@ test('negative classes', () => {
expect(result).toEqual(require('./fixtures/outputs/generator/negativeMargin'));
});

test('special classes', () => {
const result = generator.generate('z', 'zIndex', {
auto: 'auto',
'0': '0',
'10': '10',
'20': '20',
'30': '30',
'40': '40',
'50': '50',
}, [
['k', 'zIndex'],
]);

expect(result).toEqual(require('./fixtures/outputs/generator/zIndex'));
});

// translators

test('translateKeys', () => {
Expand Down Expand Up @@ -206,3 +222,29 @@ test('toArray', () => {
expect(result).toEqual([['test', 'data']]);
});

test('shadows with hex colors', () => {
const resultBox = generator.generateShadows('shadow', 'shadow', {
default: '0 1px 3px 0 #FF0000, 0 1px 2px 0 rgba(0, 0, 0, 0.06)',
md: '0 4px 6px -1px #FFFF00, 0 2px 4px -1px rgba(0, 0, 0, 0.06)',
lg: '0 10px 15px -3px #FFFFFF, 0 4px 6px -2px rgba(0, 0, 0, 0.05)',
xl: '0 20px 25px -5px #00FF00, 0 10px 10px -5px rgba(0, 0, 0, 0.04)',
'2xl': '0 25px 50px -12px #0000FF',
inner: 'inset 0 2px 4px 0 #F0000F',
outline: '0 0 0 3px #000FF0',
none: 'none',
});

const resultText = generator.generateShadows('text-shadow', 'textShadow', {
default: '0 1px 3px 0 #FF0000, 0 1px 2px 0 rgba(0, 0, 0, 0.06)',
md: '0 4px 6px -1px #FFFF00, 0 2px 4px -1px rgba(0, 0, 0, 0.06)',
lg: '0 10px 15px -3px #FFFFFF, 0 4px 6px -2px rgba(0, 0, 0, 0.05)',
xl: '0 20px 25px -5px #00FF00, 0 10px 10px -5px rgba(0, 0, 0, 0.04)',
'2xl': '0 25px 50px -12px #0000FF',
inner: 'inset 0 2px 4px 0 #F0000F',
outline: '0 0 0 3px #000FF0',
none: 'none',
});

expect(resultBox).toEqual(require('./fixtures/outputs/generator/hexColorBoxShadow'));
expect(resultText).toEqual(require('./fixtures/outputs/generator/hexColorTextShadow'));
});
21 changes: 0 additions & 21 deletions util/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,6 @@ export default {
translateKeys(name, prefix = '') {
let translatedKey = name;

if (typeof name !== 'string') {
return translatedKey;
}

if (translatedKey.search('default') !== -1) {
translatedKey = `${prefix}${translatedKey.replace('-default', '')}`;
}
Expand All @@ -264,27 +260,10 @@ export default {
});
}

if (translatedKey.search(/^[0-9]+$/g) !== -1) {
translatedKey = `${prefix}${translatedKey}`;
}

if (translatedKey.search(/^-[0-9]/) !== -1) {
translatedKey = `${prefix}${translatedKey.replace('-', '_')}`;
}

if (translatedKey.search(/^[a-zA-Z_]+-[0-9]/) !== -1) {
translatedKey = `${prefix}${translatedKey.replace('-', '')}`;
}


if (prefix !== '' && translatedKey.search(prefix) === -1) {
translatedKey = translatedKey.replace(/^([a-z])/g, (result) => {
return result.toUpperCase();
});

translatedKey = `${prefix}${translatedKey}`;
}

return translatedKey;
},

Expand Down

0 comments on commit 0fc2c62

Please sign in to comment.