Skip to content

Commit

Permalink
Merge branch 'web-client' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Tale152 committed Jan 12, 2022
2 parents dc3bd87 + 60bc903 commit 6744aaf
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 21 deletions.
7 changes: 0 additions & 7 deletions web-client/src/react/App.test.js

This file was deleted.

32 changes: 32 additions & 0 deletions web-client/src/react/_common/CustomCenteredButton.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'bootstrap/dist/css/bootstrap.min.css'

import React from 'react'
import { Provider } from 'react-redux'
import { createStore } from 'redux'
import { render, screen } from '@testing-library/react'

import allReducers from '../../redux'
import CustomCenteredButton from './CustomCenteredButton'
const store = createStore(allReducers)
const text = "button text"

function renderButton(text, onClick){
render(
<Provider store={store}>
<CustomCenteredButton text = { text } onClick = { onClick }/>
</Provider>
)
}

test("Expecting text to be correct", () => {
renderButton(text, () => {})
expect(screen.getByText(text)).toBeInTheDocument()
})

test("Expecting button to execute on click", () => {
let flag = false
renderButton(text, () => { flag = true })
expect(flag).toBe(false)
screen.getByText(text).click()
expect(flag).toBe(true)
})
32 changes: 32 additions & 0 deletions web-client/src/react/_common/form/FormButton.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'bootstrap/dist/css/bootstrap.min.css'

import React from 'react'
import { Provider } from 'react-redux'
import { createStore } from 'redux'
import { render, screen } from '@testing-library/react'

import allReducers from '../../../redux'
import FormButton from './FormButton'
const store = createStore(allReducers)
const text = "button text"

function renderButton(text, onClick){
render(
<Provider store={store}>
<FormButton text = { text } onClick = { onClick }/>
</Provider>
)
}

test("Expecting text to be correct", () => {
renderButton(text, () => {})
expect(screen.getByText(text)).toBeInTheDocument()
})

test("Expecting button to execute on click", () => {
let flag = false
renderButton(text, () => { flag = true })
expect(flag).toBe(false)
screen.getByText(text).click()
expect(flag).toBe(true)
})
10 changes: 0 additions & 10 deletions web-client/src/react/_common/form/button/FormLogin.js

This file was deleted.

40 changes: 40 additions & 0 deletions web-client/src/react/_common/form/input/FormInput.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'bootstrap/dist/css/bootstrap.min.css'

import React from 'react'
import { Provider } from 'react-redux'
import { createStore } from 'redux'
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'

import allReducers from '../../../../redux'
import FormInput from './FormInput'
const store = createStore(allReducers)
const text = "button text"
const placeholder = "button placeholder"

function renderButton(onChange){
render(
<Provider store={store}>
<FormInput type = { "text" } text = { text } placeholder = { placeholder } onChange = { onChange }/>
</Provider>
)
}

test("Expecting text to be rendered", () => {
renderButton(() => {})
expect(screen.getByText(text)).toBeInTheDocument()
})

test("Expecting placeholder to be rendered", () => {
renderButton(() => {})
expect(screen.getByPlaceholderText(placeholder)).toBeInTheDocument()
})

test("Expecting value to be updated typing", () => {
const stringToType = "hello, test!"
let typed = ""
renderButton(input => { typed = input })
expect(typed).toBe("")
userEvent.type(screen.getByPlaceholderText(placeholder), stringToType)
expect(typed).toBe(stringToType)
})
4 changes: 2 additions & 2 deletions web-client/src/react/farmerLogin/components/LoginPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useAlert } from 'react-alert'

import FormText from '../../_common/form/input/FormText'
import FormPassword from '../../_common/form/input/FormPassword'
import FormLogin from '../../_common/form/button/FormLogin'
import FormButton from '../../_common/form/FormButton'
import RedirectButton from '../../_common/navigation/RedirectButton'

import farmerLogin from '../../../js/farmer/farmerLogin'
Expand Down Expand Up @@ -41,7 +41,7 @@ export default function LoginPage() {
onEnter = { tryLogin }
/>
<div className="mt-lg-3">
<FormLogin text={ "Login" } onClick = { tryLogin } />
<FormButton text={ "Login" } onClick = { tryLogin } />
<RedirectButton text = { "Register" } destination = { "register" } />
</div>
</Form>
Expand Down
4 changes: 2 additions & 2 deletions web-client/src/react/register/components/RegisterPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useAlert } from 'react-alert'
import FormText from '../../_common/form/input/FormText'
import FormPassword from '../../_common/form/input/FormPassword'
import FormDatePicker from '../../_common/form/FormDatePicker'
import FormLogin from '../../_common/form/button/FormLogin'
import FormButton from '../../_common/form/FormButton'
import RedirectButton from '../../_common/navigation/RedirectButton'

import organizationRegister from '../../../js/organization/organizationRegister'
Expand Down Expand Up @@ -76,7 +76,7 @@ export default function RegisterPage() {
onEnter = { tryRegister }
/>
<div className="mt-lg-3">
<FormLogin text={ "Register" } onClick = { tryRegister } />
<FormButton text={ "Register" } onClick = { tryRegister } />
<RedirectButton text = { "Login" } destination = { "" } />
</div>
</Form>
Expand Down

0 comments on commit 6744aaf

Please sign in to comment.