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.
 
 

125 rivejä
3.0 KiB

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