Passed
Push — main ( ca0e04...952648 )
by Andrii
02:09
created

readme.spec.tsx ➔ FormButtons   A

Complexity

Conditions 1

Size

Total Lines 17
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 17
rs 9.65
c 0
b 0
f 0
cc 1
1
import React from "react"
2
import expectRender from "../expect-to-same-render"
3
import classNaming from "../src"
4
5
it("Basic usage", () => {
6
  type Props = {
7
    isValid: boolean
8
    readOnly: boolean
9
  }
10
11
  // isValid = false, readOnly = false
12
  function FormButtons({isValid, readOnly}: Props) {
13
    const cssClasses = classNaming()
14
    const buttonClass = cssClasses({"button": true}) // "button"
15
    
16
    return <>
17
      <button {
18
        ...buttonClass // className="button" 
19
      }>Close</button>
20
      <button type="reset" {
21
        ...buttonClass({"button--disabled": readOnly}) // className="button"
22
      }>Reset</button> 
23
      <button type="submit" className={`button_submit ${
24
        buttonClass({"button--disabled": readOnly || !isValid}) // "button button--disabled"
25
      }`}>Submit</button> 
26
    </>
27
  }  
28
29
  expectRender(
30
    <FormButtons isValid={false} readOnly={false} />
31
  ).toSame(<>
32
    <button className="button">Close</button>
33
    <button type="reset" className="button">Reset</button>
34
    <button type="submit" className="button_submit button button--disabled">Submit</button>
35
  </>)
36
})
37