Website for showcasing all features of Tesseract Web.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

138 line
3.0 KiB

  1. import { css, CssIfStringImpl, CssStringImpl } from '.';
  2. jest.mock('goober', () => {
  3. return {
  4. css: () => 'gooberClass',
  5. };
  6. });
  7. describe('css-utils', () => {
  8. describe('css', () => {
  9. it('should return CssString', () => {
  10. const c = css`
  11. background-color: white;
  12. color: black;
  13. `
  14. expect(c).toBeInstanceOf(CssStringImpl);
  15. expect(c.toString()).toBe('background-color:white;color:black;');
  16. })
  17. })
  18. describe('css.if', () => {
  19. it('should return CssString when the condition is true', () => {
  20. const c = css.if(true)(
  21. css`
  22. background-color: white;
  23. `
  24. )
  25. expect(c).toBeInstanceOf(CssIfStringImpl)
  26. expect(c.toString()).toBe('background-color:white;')
  27. })
  28. it('should return empty string when the condition is false', () => {
  29. const c = css.if(false)(
  30. css`
  31. background-color: white;
  32. `
  33. )
  34. expect(c.toString()).toBe('')
  35. })
  36. it('should return CssString with .else when the if condition is false', () => {
  37. const c = css.if(false)(
  38. css`
  39. background-color: white;
  40. `
  41. ).else(
  42. css`
  43. background-color: black;
  44. `
  45. )
  46. expect(c.toString()).toBe('background-color:black;')
  47. })
  48. it('should return CssString with .else when the if condition is true', () => {
  49. const c = css.if(true)(
  50. css`
  51. background-color: white;
  52. `
  53. ).else(
  54. css`
  55. background-color: black;
  56. `
  57. )
  58. expect(c.toString()).toBe('background-color:white;')
  59. })
  60. })
  61. describe('css.nest', () => {
  62. it('should add selector', () => {
  63. const c = css.nest('> div')(
  64. css`
  65. background-color: white;
  66. `
  67. )
  68. expect(c.toString()).toBe('> div{background-color:white;}')
  69. })
  70. })
  71. describe('css.dynamic', () => {
  72. it('should evaluate dynamic object', () => {
  73. const randomNumber = Math.floor(Math.random() * 1000);
  74. const c = css.dynamic({
  75. 'line-height': randomNumber,
  76. })
  77. expect(c.toString()).toBe(`line-height:${randomNumber};`)
  78. })
  79. })
  80. describe('css.media', () => {
  81. it('should accept raw queries', () => {
  82. const c = css.media('only screen and (min-width: 720px)')(
  83. css`
  84. color: black;
  85. background-color: white;
  86. `
  87. )
  88. expect(c.toString()).toBe('@media only screen and (min-width: 720px){color:black;background-color:white;}')
  89. })
  90. })
  91. describe('css.cx', () => {
  92. it('should accept strings as classnames', () => {
  93. expect(css.cx('class1', 'class2')).toBe('class1 class2');
  94. })
  95. it('should accept CSS strings for classname generation', () => {
  96. expect(
  97. css.cx(
  98. css`
  99. color: white;
  100. `
  101. )
  102. ).toBe('gooberClass');
  103. })
  104. it('should accept mixed values', () => {
  105. expect(
  106. css.cx(
  107. 'class1',
  108. 'class2',
  109. css`
  110. color: white;
  111. `
  112. )
  113. ).toBe('class1 class2 gooberClass');
  114. })
  115. })
  116. })