This file contains hidden or 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
/* testing/src/__tests__/helpers/index.test.js */ | |
import { /* ... */ , setTraysForId, getTraysForId } from '../../helpers'; | |
describe('Trays', () => { | |
beforeEach(() => { | |
window.localStorage.clear(); | |
}); | |
test('are stored locally on setting them via the id', () => { |
This file contains hidden or 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
/* testing/src/helpers/index.js */ | |
// ... | |
const setTraysForId = (id, trays) => { | |
window.localStorage.setItem(`${id}`, JSON.stringify(trays)); | |
} | |
const getTraysForId = (id) => { | |
return JSON.parse(window.localStorage.getItem(`${id}`)); |
This file contains hidden or 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
/* src/__tests__/helpers/index.test.js */ | |
import { isEarlierThanNow, fetchFakeAPIData } from '../../helpers'; | |
// ... | |
test('fetchFakeAPIData, when requesting an animal, responds with a dog', (done) => { | |
// Arrange | |
const testRequest = { animal: true }; | |
// Act |
This file contains hidden or 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
/* src/__tests__/helpers/index.test.js */ | |
import { isEarlierThanNow, fetchFakeAPIData } from '../../helpers'; | |
//... | |
test('fetchFakeAPIData, when requesting an animal, responds with a dog', async () => { | |
// Arrange | |
const testRequest = { animal: true }; | |
// Act |
This file contains hidden or 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
/* src/__tests__/helpers/index.test.js */ | |
import { isEarlierThanNow, fetchFakeAPIData } from '../../helpers'; | |
//... | |
test('fetchFakeAPIData, when requesting an animal, responds with a dog', () => { | |
// Arrange | |
const testRequest = { animal: true }; | |
// Act |
This file contains hidden or 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
/* /src/helpers/index.js */ | |
// ... | |
const fetchFakeAPIData = (request) => new Promise((resolve, reject) => { | |
if (request.animal) { | |
resolve({ | |
animal: 'Dog', | |
name: 'Charlie' | |
}); | |
} |
This file contains hidden or 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
/* src/__tests__/helpers/index.test.js: */ | |
import { isEarlierThanNow } from '../../helpers'; | |
test('isEarlierThanNow, given a timestamp earlier than now, retruns true', () => { | |
// Arrange | |
const date = new Date('1/1/2000'); | |
// Act | |
const actualIsEarlierDateThanNow = isEarlierThanNow(date); |
This file contains hidden or 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
/* src/helpers/index.js: */ | |
const isEarlierThanNow = (timestamp) => timestamp < Date.now(); | |
export { isEarlierThanNow }; |
This file contains hidden or 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
<ProductSearchFilter | |
products={["t-shirt", "shorts", "jeans"]} | |
colors={["red", "white", "black"]} | |
onSearch={(...args) => console.log(args)} | |
reducer={(state, action) => { | |
// 1. Run the default reducer: | |
const newState = productSearchFilterReducer(state, action); | |
// 2. Override its behaviour to fit your needs as a consumer: | |
if ( | |
newState.product === "t-shirt" && |
This file contains hidden or 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
import React, { useReducer } from "react"; | |
// 1. REDUCER + HOOK: | |
const initialProductSearchFilterState = { | |
product: "", | |
colors: [] | |
}; | |
const productSearchFilterReducer = (state, action) => { | |
switch (action.type) { |
NewerOlder