-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate localisation platform middleware into bootstrap saga
- Loading branch information
1 parent
86c5eda
commit 4136d9b
Showing
27 changed files
with
764 additions
and
542 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
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,2 @@ | ||
export const I18N_ADD_MESSAGES = "@@bootstrap/I18N_ADD_MESSAGES"; | ||
export const I18N_REMOVE_MESSAGES = "@@bootstrap/I18N_REMOVE_MESSAGES"; |
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,205 @@ | ||
import * as constants from "../../constants"; | ||
import reducer, { initialState } from "../localisation"; | ||
|
||
describe("localisation reducer", () => { | ||
describe("is reducer", () => { | ||
it("has initial state", () => { | ||
const action = { | ||
type: "non-handled", | ||
}; | ||
expect(reducer(undefined, action)).toEqual(initialState); | ||
}); | ||
it("has default case", () => { | ||
const action = { | ||
type: "non-handled", | ||
}; | ||
expect(reducer(initialState, action)).toEqual(initialState); | ||
}); | ||
}); | ||
|
||
describe("I18N_REMOVE_MESSAGES", () => { | ||
it("purges local shared state of module", () => { | ||
const action = { | ||
type: constants.I18N_REMOVE_MESSAGES, | ||
payload: { | ||
module: "my-feature", | ||
}, | ||
}; | ||
const state = { | ||
...initialState, | ||
local: { | ||
"my-feature": { | ||
hair: "yes", | ||
}, | ||
}, | ||
}; | ||
const expectedState = { | ||
...initialState, | ||
}; | ||
|
||
expect(reducer(state, action)).toEqual(expectedState); | ||
}); | ||
|
||
it("purges localisation messages owned by this module", () => { | ||
const state = { | ||
...initialState, | ||
language: "en-US", | ||
}; | ||
|
||
const addMessagesAction = { | ||
type: constants.I18N_ADD_MESSAGES, | ||
payload: { | ||
language: "en-US", | ||
batch: [ | ||
{ | ||
module: "my-feature", | ||
data: { | ||
"message.key": "message.value", | ||
}, | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
const action = { | ||
type: constants.I18N_REMOVE_MESSAGES, | ||
payload: { | ||
module: "my-feature", | ||
}, | ||
}; | ||
const nextState = reducer(state, addMessagesAction); | ||
expect(nextState.messages["en-US"]["message.key"]).toEqual("message.value"); | ||
const expectedState = { | ||
...state, | ||
messages: { | ||
"en-US": {}, | ||
}, | ||
}; | ||
expect(reducer(nextState, action)).toEqual(expectedState); | ||
}); | ||
}); | ||
|
||
describe("I18N_ADD_MESSAGES", () => { | ||
it("empty batch", () => { | ||
const state = { | ||
...initialState, | ||
language: "en-US", | ||
}; | ||
|
||
const action = { | ||
type: constants.I18N_ADD_MESSAGES, | ||
payload: { | ||
batch: [], | ||
language: "en-US", | ||
}, | ||
}; | ||
expect(reducer(state, action)).toEqual(state); | ||
}); | ||
|
||
it("empty batch different language", () => { | ||
const action = { | ||
type: constants.I18N_ADD_MESSAGES, | ||
payload: { | ||
batch: [], | ||
language: "fr-FR", | ||
}, | ||
}; | ||
|
||
const expectedState = { | ||
...initialState, | ||
language: "fr-FR", | ||
}; | ||
|
||
expect(reducer(initialState, action)).toEqual(expectedState); | ||
}); | ||
|
||
it("non empty batch same language", () => { | ||
const action = { | ||
type: constants.I18N_ADD_MESSAGES, | ||
payload: { | ||
batch: [ | ||
{ | ||
module: "my-feature", | ||
data: { | ||
existing: "new", | ||
"message.key": "message.value", | ||
nested: { | ||
localisation: "value", | ||
}, | ||
}, | ||
}, | ||
], | ||
language: "en-US", | ||
}, | ||
}; | ||
const state = { | ||
...initialState, | ||
language: "en-US", | ||
messages: { | ||
"en-US": { | ||
existing: "old", | ||
}, | ||
}, | ||
}; | ||
const expectedState = { | ||
...initialState, | ||
language: "en-US", | ||
messages: { | ||
"en-US": { | ||
existing: "new", | ||
"message.key": "message.value", | ||
"nested.localisation": "value", | ||
}, | ||
}, | ||
}; | ||
|
||
expect(reducer(state, action)).toEqual(expectedState); | ||
}); | ||
|
||
it("non empty batch different language", () => { | ||
const action = { | ||
type: constants.I18N_ADD_MESSAGES, | ||
payload: { | ||
batch: [ | ||
{ | ||
module: "my-feature", | ||
data: { | ||
existing: "new", | ||
"message.key": "message.value", | ||
nested: { | ||
localisation: "value", | ||
}, | ||
}, | ||
}, | ||
], | ||
language: "fr-FR", | ||
}, | ||
}; | ||
const state = { | ||
...initialState, | ||
language: "en-US", | ||
messages: { | ||
"en-US": { | ||
existing: "old", | ||
}, | ||
}, | ||
}; | ||
const expectedState = { | ||
...initialState, | ||
language: "fr-FR", | ||
messages: { | ||
"en-US": { | ||
existing: "old", | ||
}, | ||
"fr-FR": { | ||
existing: "new", | ||
"message.key": "message.value", | ||
"nested.localisation": "value", | ||
}, | ||
}, | ||
}; | ||
|
||
expect(reducer(state, action)).toEqual(expectedState); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/* istanbul ignore file */ | ||
import localisationReducer from "./localisation"; | ||
import runtimeReducer from "./runtime"; | ||
|
||
export { runtimeReducer }; | ||
export { runtimeReducer, localisationReducer }; |
Oops, something went wrong.