Skip to content

Commit

Permalink
refactor(actions): make PHRASE_SUGGESTIONS_UPDATED an FSA
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmason committed Sep 25, 2017
1 parent 4b462c2 commit 120719b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 56 deletions.
Expand Up @@ -12,7 +12,7 @@ export const PHRASE_SUGGESTION_FINISHED_COPYING =
'PHRASE_SUGGESTION_FINISHED_COPYING'
export const TEXT_SUGGESTIONS_UPDATED = 'TEXT_SUGGESTIONS_UPDATED'
export const SUGGESTION_SEARCH_TEXT_CHANGE = 'SUGGESTION_SEARCH_TEXT_CHANGE'
export const PHRASE_SUGGESTIONS_UPDATED = Symbol('PHRASE_SUGGESTIONS_UPDATED')
export const PHRASE_SUGGESTIONS_UPDATED = 'PHRASE_SUGGESTIONS_UPDATED'
export const SUGGESTION_PANEL_HEIGHT_CHANGE =
Symbol('SUGGESTION_PANEL_HEIGHT_CHANGE')
export const SHOW_DETAIL_FOR_SUGGESTION_BY_INDEX =
Expand Down
Expand Up @@ -235,6 +235,8 @@ export function findPhraseSuggestionsById (phraseId) {

const PHRASE_SEARCH_STALE_AGE_MILLIS = 60000

const phraseSuggestionsUpdated = createAction(PHRASE_SUGGESTIONS_UPDATED)

export function findPhraseSuggestions (phrase) {
return (dispatch, getState) => {
const phraseId = phrase.id
Expand Down Expand Up @@ -282,18 +284,6 @@ export function findPhraseSuggestions (phrase) {
}
}

export function phraseSuggestionsUpdated (
{phraseId, loading, searchStrings, suggestions, timestamp}) {
return {
type: PHRASE_SUGGESTIONS_UPDATED,
phraseId,
loading,
searchStrings,
suggestions,
timestamp
}
}

export function saveSuggestionPanelHeight (percentageHeight) {
return {
type: SUGGESTION_PANEL_HEIGHT_CHANGE,
Expand Down
Expand Up @@ -69,11 +69,11 @@ const suggestions = (state = defaultState, action) => {
return update({
searchByPhrase: {
// must $set a new object because the key may not yet be defined
[action.phraseId]: {$set: {
loading: action.loading,
searchStrings: action.searchStrings,
suggestions: action.suggestions,
timestamp: action.timestamp
[action.payload.phraseId]: {$set: {
loading: action.payload.loading,
searchStrings: action.payload.searchStrings,
suggestions: action.payload.suggestions,
timestamp: action.payload.timestamp
}}
}
})
Expand Down
Expand Up @@ -48,25 +48,27 @@ describe('suggestions-reducer test', () => {
it('can begin and end phrase copying', () => {
const withPhraseSuggestions = suggestionsReducer(undefined, {
type: PHRASE_SUGGESTIONS_UPDATED,
phraseId: 'p01',
loading: false,
searchStrings: [ 'source', 'sources' ],
suggestions: [
{
sourceContents: [ 'source', 'sources' ],
targetContents: [ 'target', 'targets' ],
copying: false,
relevanceScore: 2,
similarityPercent: 100
}, {
sourceContents: [ 'horse', 'horses' ],
targetContents: [ 'Pferd', 'Pferde' ],
copying: false,
relevanceScore: 1.5,
similarityPercent: 80
}
],
timestamp: 12345
payload: {
phraseId: 'p01',
loading: false,
searchStrings: [ 'source', 'sources' ],
suggestions: [
{
sourceContents: [ 'source', 'sources' ],
targetContents: [ 'target', 'targets' ],
copying: false,
relevanceScore: 2,
similarityPercent: 100
}, {
sourceContents: [ 'horse', 'horses' ],
targetContents: [ 'Pferd', 'Pferde' ],
copying: false,
relevanceScore: 1.5,
similarityPercent: 80
}
],
timestamp: 12345
}
})
const copying = suggestionsReducer(withPhraseSuggestions, {
type: PHRASE_SUGGESTION_STARTED_COPYING,
Expand All @@ -90,25 +92,27 @@ describe('suggestions-reducer test', () => {
it('can receive phrase suggestions', () => {
const withPhraseSuggestions = suggestionsReducer(undefined, {
type: PHRASE_SUGGESTIONS_UPDATED,
phraseId: 'p01',
loading: false,
searchStrings: [ 'source', 'sources' ],
suggestions: [
{
sourceContents: [ 'source', 'sources' ],
targetContents: [ 'target', 'targets' ],
copying: false,
relevanceScore: 2,
similarityPercent: 100
}, {
sourceContents: [ 'horse', 'horses' ],
targetContents: [ 'Pferd', 'Pferde' ],
copying: false,
relevanceScore: 1.5,
similarityPercent: 80
}
],
timestamp: 12345
payload: {
phraseId: 'p01',
loading: false,
searchStrings: [ 'source', 'sources' ],
suggestions: [
{
sourceContents: [ 'source', 'sources' ],
targetContents: [ 'target', 'targets' ],
copying: false,
relevanceScore: 2,
similarityPercent: 100
}, {
sourceContents: [ 'horse', 'horses' ],
targetContents: [ 'Pferd', 'Pferde' ],
copying: false,
relevanceScore: 1.5,
similarityPercent: 80
}
],
timestamp: 12345
}
})
expect(withPhraseSuggestions.searchByPhrase['p01']).toEqual({
loading: false,
Expand Down

0 comments on commit 120719b

Please sign in to comment.