-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
162 additions
and
8 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
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 @@ | ||
require( 'jest-localstorage-mock'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,97 @@ | ||
import { | ||
KeyNames, | ||
updateKey, | ||
getKey, | ||
updateMRUList, | ||
} from '../preferences'; | ||
|
||
describe('preferences', () => { | ||
beforeEach(() => { | ||
localStorage.clear(); | ||
}); | ||
|
||
describe('updateKey', () => { | ||
it('should update the value of a key in the app data', () => { | ||
const key = KeyNames.RECENT; | ||
const value = ['recipe1', 'recipe2']; | ||
|
||
updateKey(key, value); | ||
|
||
const updatedValue = getKey(key); | ||
expect(updatedValue).toEqual(value); | ||
}); | ||
}); | ||
|
||
describe('getKey', () => { | ||
it('should return the default value when `key` has not been set', () => { | ||
const key = KeyNames.SEARCH; | ||
const defaultValue = 'default'; | ||
|
||
const value = getKey(key, defaultValue); | ||
expect(value).toEqual(defaultValue); | ||
}); | ||
|
||
it('should return the default value if the key does not exist', () => { | ||
const key = 'nonExistentKey'; | ||
const defaultValue = 'default'; | ||
|
||
const value = getKey(key, defaultValue); | ||
expect(value).toEqual(defaultValue); | ||
}); | ||
}); | ||
|
||
describe('updateMRUList', () => { | ||
it('should add a value to the MRU list', () => { | ||
const key = KeyNames.RECENT; | ||
const maxLength = 3; | ||
const value = 'recipe1'; | ||
|
||
updateMRUList(key, maxLength, value); | ||
|
||
const updatedList = getKey(key); | ||
expect(updatedList).toEqual([value]); | ||
}); | ||
|
||
it('should place new values at top of the MRU list', () => { | ||
const key = KeyNames.RECENT; | ||
const maxLength = 3; | ||
const value1 = 'recipe1'; | ||
const value2 = 'recipe2'; | ||
|
||
updateMRUList(key, maxLength, value1); | ||
updateMRUList(key, maxLength, value2); | ||
|
||
const updatedList = getKey(key); | ||
expect(updatedList).toEqual([value2, value1]); | ||
}); | ||
|
||
it('should move an existing value to the top of the MRU list', () => { | ||
const key = KeyNames.RECENT; | ||
const maxLength = 3; | ||
const value1 = 'recipe1'; | ||
const value2 = 'recipe2'; | ||
|
||
updateMRUList(key, maxLength, value1); | ||
updateMRUList(key, maxLength, value2); | ||
updateMRUList(key, maxLength, value1); | ||
|
||
const updatedList = getKey(key); | ||
expect(updatedList).toEqual([value1, value2]); | ||
}); | ||
|
||
it('should discard the last item if the MRU list exceeds the max length', () => { | ||
const key = KeyNames.RECENT; | ||
const maxLength = 2; | ||
const value1 = 'recipe1'; | ||
const value2 = 'recipe2'; | ||
const value3 = 'recipe3'; | ||
|
||
updateMRUList(key, maxLength, value1); | ||
updateMRUList(key, maxLength, value2); | ||
updateMRUList(key, maxLength, value3); | ||
|
||
const updatedList = getKey(key); | ||
expect(updatedList).toEqual([value3, value2]); | ||
}); | ||
}); | ||
}); |
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 @@ | ||
import { toDisplay } from '../recentlyViewed'; | ||
|
||
describe('recentlyViewed', () => { | ||
describe('toDisplay', () => { | ||
const tests = [ | ||
{ value: 'hello-world', expectedResult: 'Hello World' }, | ||
{ value: 'hello world', expectedResult: 'Hello World' }, | ||
{ value: ' HeLLo WoRLD ', expectedResult: 'Hello World' }, | ||
{ value: '', expectedResult: '' }, | ||
{ value: '---', expectedResult: '' }, | ||
]; | ||
|
||
tests.forEach((test) => { | ||
it(`should convert "${test.value}" to "${test.expectedResult}"`, () => { | ||
const result = toDisplay(test.value); | ||
expect(result).toEqual(test.expectedResult); | ||
}); | ||
}); | ||
}); | ||
}); |
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,21 @@ | ||
import { scrub } from '../searchBox'; | ||
|
||
describe('searchBox', () => { | ||
describe('scrub', () => { | ||
const tests = [ | ||
{ value: 'Hello World!', expectedResult: 'helloworld' }, | ||
{ value: ' A very delicious pumpkin -- pie! From, :Hasbro (99) ', expectedResult: 'averydeliciouspumpkinpiefromhasbro99' }, | ||
{ value: ' Hello World ', expectedResult: 'helloworld' }, | ||
{ value: '12345', expectedResult: '12345' }, | ||
{ value: '', expectedResult: '' }, | ||
{ value: '---', expectedResult: '' }, | ||
]; | ||
|
||
tests.forEach((test) => { | ||
it(`should scrub "${test.value}" to "${test.expectedResult}"`, () => { | ||
const result = scrub(test.value); | ||
expect(result).toEqual(test.expectedResult); | ||
}); | ||
}); | ||
}); | ||
}); |
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
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