-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from foobaragency/create-tests
Create tests
- Loading branch information
Showing
27 changed files
with
3,117 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: build | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: 16.x | ||
- name: Install dependencies | ||
run: yarn install --frozen-lockfile | ||
- name: Build | ||
run: yarn build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: test | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: 16.x | ||
- name: Install dependencies | ||
run: yarn install --frozen-lockfile | ||
- name: Build | ||
run: yarn build | ||
- run: yarn test | ||
- name: Coverage badges | ||
uses: jpb06/jest-badges-action@latest | ||
with: | ||
branches: master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
presets: [ | ||
["@babel/preset-env", { targets: { node: "current" } }], | ||
"@babel/preset-react", | ||
], | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from "react" | ||
import ReactDOM from "react-dom" | ||
|
||
import { Counter } from "./Counter" | ||
|
||
ReactDOM.render( | ||
<React.StrictMode> | ||
<Counter /> | ||
</React.StrictMode>, | ||
document.getElementById("root") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React, { useEffect } from "react" | ||
import { createGlobalState } from "@foobar-agency/react-global-state" | ||
|
||
const initialState = 0 | ||
|
||
const { useGlobalState, setGlobalState } = createGlobalState(initialState) | ||
|
||
function setInitialState() { | ||
setTimeout(() => { | ||
setGlobalState(10_000) | ||
}, 2_000) | ||
} | ||
|
||
export const Counter = () => { | ||
const [count, setCount] = useGlobalState() | ||
|
||
useEffect(() => { | ||
setInitialState() | ||
}, []) | ||
|
||
const decrement = () => { | ||
setCount(count - 1) | ||
} | ||
|
||
const increment = () => { | ||
setCount(count + 1) | ||
} | ||
|
||
return ( | ||
<div> | ||
<button onClick={decrement}>-</button> | ||
<span>{count}</span> | ||
<button onClick={increment}>+</button> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from "react" | ||
import { createGlobalState } from "@foobar-agency/react-global-state" | ||
|
||
const initialState = { | ||
firstName: "John", | ||
lastName: "Doe", | ||
age: 43, | ||
} | ||
|
||
const { createPartialState } = createGlobalState(initialState) | ||
|
||
const useAge = createPartialState(state => state.age) | ||
|
||
export const Age = () => { | ||
const age = useAge() | ||
|
||
return <div>{age}</div> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React from "react" | ||
import { createGlobalState } from "@foobar-agency/react-global-state" | ||
|
||
const initialState = { | ||
firstName: "John", | ||
lastName: "Doe", | ||
age: 43, | ||
} | ||
|
||
const { useGlobalState } = createGlobalState(initialState, { | ||
persistence: { | ||
key: "x-storage-key", | ||
// optional, can be either localStorage or sessionStorage, localStorage by default | ||
storage: "localStorage", | ||
}, | ||
}) | ||
|
||
export const Person = () => { | ||
const [person, setPerson] = useGlobalState() | ||
|
||
function onChange(e) { | ||
const { name, value } = e.target | ||
|
||
setPerson({ | ||
...person, | ||
[name]: value, | ||
}) | ||
} | ||
|
||
return ( | ||
<div> | ||
<label> | ||
First Name | ||
<br /> | ||
<input name="firstName" value={person.firstName} onChange={onChange} /> | ||
</label> | ||
<label> | ||
Last Name | ||
<br /> | ||
<input name="lastName" value={person.lastName} onChange={onChange} /> | ||
</label> | ||
<label> | ||
Age | ||
<br /> | ||
<input name="age" value={person.age} onChange={onChange} /> | ||
</label> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from "react" | ||
import { createGlobalState } from "@foobar-agency/react-global-state" | ||
|
||
const initialState = { | ||
firstName: "John", | ||
lastName: "Doe", | ||
age: 43, | ||
} | ||
|
||
const { useGlobalState } = createGlobalState(initialState) | ||
|
||
export const Profile = () => { | ||
const [state, setState] = useGlobalState() | ||
|
||
function invertNames() { | ||
const newState = { | ||
firstName: "Doe", | ||
lastName: "John", | ||
age: 43, | ||
} | ||
setState(newState, { deepCompare: true }) | ||
} | ||
|
||
return ( | ||
<div> | ||
<p>First Name: {state.firstName}</p> | ||
<p>Last Name: {state.lastName}</p> | ||
<p>Age: {state.age}</p> | ||
<button onClick={invertNames}>Click me!</button> | ||
</div> | ||
) | ||
} |
Oops, something went wrong.