import React from 'react' ; import { mount } from 'enzyme' ; import { I18nProvider } from '../../src/i18n/I18nContext' ; import { Provider } from 'react-redux' ; import { store } from '../../src/store' ; import Pref from '../../src/components/screens/Pref' ; it ( 'renders Pref' , ( ) => { const screen = mount ( < Provider store = { store } > < I18nProvider > < Pref /> < /I18nProvider> < /Provider>); const playerName = screen . find ( '#playerName' ) ; expect ( playerName . length ) . toBe ( 1 ) ; playerName . simulate ( 'click' ) ; playerName . simulate ( 'change' , { target : { value : '' } } ) ; playerName . simulate ( 'change' , { target : { value : '😃' } } ) ; playerName . simulate ( 'click' ) ; playerName . simulate ( 'change' , { target : { value : 'My new name' } } ) ; const opponentName = screen . find ( '#opponentName' ) ; expect ( opponentName . length ) . toBe ( 1 ) ; opponentName . simulate ( 'click' ) ; opponentName . simulate ( 'change' , { target : { value : '' } } ) ; opponentName . simulate ( 'change' , { target : { value : '☠️' } } ) ; opponentName . simulate ( 'click' ) ; opponentName . simulate ( 'change' , { target : { value : 'Opponent new name' } } ) ; const selectTavern = screen . find ( '#tavern' ) ; expect ( selectTavern . length ) . toBe ( 1 ) ; selectTavern . simulate ( 'change' , { target : { value : '-2' } } ) ; selectTavern . simulate ( 'change' , { target : { value : '0' } } ) ; selectTavern . simulate ( 'change' , { target : { value : '1' } } ) ; const tower = screen . find ( '#tower' ) ; expect ( tower . length ) . toBe ( 1 ) ; tower . simulate ( 'change' , { target : { value : '-74' } } ) ; tower . simulate ( 'change' , { target : { value : '740' } } ) ; tower . simulate ( 'change' , { target : { value : '74' } } ) ; const wall = screen . find ( '#wall' ) ; expect ( wall . length ) . toBe ( 1 ) ; wall . simulate ( 'change' , { target : { value : '-4' } } ) ; wall . simulate ( 'change' , { target : { value : '500' } } ) ; wall . simulate ( 'change' , { target : { value : '5' } } ) ; const bricks = screen . find ( '#bricks' ) ; expect ( bricks . length ) . toBe ( 1 ) ; bricks . simulate ( 'change' , { target : { value : '' } } ) ; bricks . simulate ( 'change' , { target : { value : '370' } } ) ; bricks . simulate ( 'change' , { target : { value : '37' } } ) ; const gems = screen . find ( '#gems' ) ; expect ( gems . length ) . toBe ( 1 ) ; gems . simulate ( 'change' , { target : { value : '13' } } ) ; const recruits = screen . find ( '#recruits' ) ; expect ( recruits . length ) . toBe ( 1 ) ; recruits . simulate ( 'change' , { target : { value : '42' } } ) ; const brickProd = screen . find ( '#brickProd' ) ; expect ( brickProd . length ) . toBe ( 1 ) ; brickProd . simulate ( 'change' , { target : { value : '0' } } ) ; const gemProd = screen . find ( '#gemProd' ) ; expect ( gemProd . length ) . toBe ( 1 ) ; gemProd . simulate ( 'change' , { target : { value : '-5' } } ) ; gemProd . simulate ( 'change' , { target : { value : '3' } } ) ; const recruitProd = screen . find ( '#recruitProd' ) ; expect ( recruitProd . length ) . toBe ( 1 ) ; recruitProd . simulate ( 'change' , { target : { value : '-5' } } ) ; recruitProd . simulate ( 'change' , { target : { value : '3' } } ) ; const winTower = screen . find ( '#winTower' ) ; expect ( winTower . length ) . toBe ( 1 ) ; winTower . simulate ( 'change' , { target : { value : '-4' } } ) ; winTower . simulate ( 'change' , { target : { value : '4' } } ) ; winTower . simulate ( 'change' , { target : { value : '68' } } ) ; const winResource = screen . find ( '#winResource' ) ; expect ( winResource . length ) . toBe ( 1 ) ; winResource . simulate ( 'change' , { target : { value : '-4' } } ) ; winResource . simulate ( 'change' , { target : { value : '6' } } ) ; winResource . simulate ( 'change' , { target : { value : '66' } } ) ; const cardsInHand = screen . find ( '#cardsInHand' ) ; expect ( cardsInHand . length ) . toBe ( 1 ) ; cardsInHand . simulate ( 'change' , { target : { value : '-8' } } ) ; cardsInHand . simulate ( 'change' , { target : { value : '24' } } ) ; cardsInHand . simulate ( 'change' , { target : { value : '7' } } ) ; const aiLevel = screen . find ( '#aiLevel' ) ; expect ( aiLevel . length ) . toBe ( 1 ) ; aiLevel . simulate ( 'change' , { target : { value : '0' } } ) ; aiLevel . simulate ( 'change' , { target : { value : '2' } } ) ; const isMultiplayer = screen . find ( '#isMultiplayer' ) ; expect ( isMultiplayer . length ) . toBe ( 1 ) ; isMultiplayer . simulate ( 'change' , { target : { checked : true } } ) ; const yourId = screen . find ( '#yourId' ) ; expect ( yourId . length ) . toBe ( 1 ) ; yourId . simulate ( 'click' ) ; const opponentId = screen . find ( '#opponentId' ) ; expect ( opponentId . length ) . toBe ( 1 ) ; opponentId . simulate ( 'change' , { target : { value : '4b0e835d-002f-4478-8d89-e384f19cd999' } , } ) ; const buttonConnect = screen . find ( 'div.multiplayer button' ) ; expect ( buttonConnect . length ) . toBe ( 1 ) ; buttonConnect . simulate ( 'click' ) ; const buttonsResetApply = screen . find ( 'div.button-wrapper button' ) ; expect ( buttonsResetApply . length > 0 ) . toBeTruthy ( ) ; buttonsResetApply . forEach ( ( button ) => { button . simulate ( 'click' ) ; } ) ; } ) ;