Minimal styling, powered by Goober.
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.

144 lines
3.1 KiB

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