2021-03-12 19:41:20 +01:00
|
|
|
import faker from "faker";
|
|
|
|
|
import langReducer, { Actions, initialState } from "../../utils/reducer";
|
|
|
|
|
|
|
|
|
|
it("changes a field value", () => {
|
|
|
|
|
const query = faker.random.words();
|
|
|
|
|
|
|
|
|
|
const res = langReducer(initialState, {
|
|
|
|
|
type: Actions.SET_FIELD,
|
|
|
|
|
payload: {
|
|
|
|
|
key: "query",
|
|
|
|
|
value: query
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
expect(res).toStrictEqual({ ...initialState, query });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("changes all fields", () => {
|
2021-03-18 23:47:12 +01:00
|
|
|
const query = faker.random.words();
|
2021-03-12 19:41:20 +01:00
|
|
|
const state = {
|
|
|
|
|
source: faker.random.locale(),
|
|
|
|
|
target: faker.random.locale(),
|
2021-03-18 23:47:12 +01:00
|
|
|
query,
|
|
|
|
|
delayedQuery: query,
|
|
|
|
|
translation: faker.random.words()
|
2021-03-12 19:41:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const res = langReducer(initialState, {
|
|
|
|
|
type: Actions.SET_ALL,
|
|
|
|
|
payload: { state }
|
|
|
|
|
});
|
|
|
|
|
expect(res).toStrictEqual(state);
|
|
|
|
|
});
|
|
|
|
|
|
2021-03-18 23:47:12 +01:00
|
|
|
it("switches the languages & the translations", () => {
|
2021-03-12 19:41:20 +01:00
|
|
|
const state = {
|
|
|
|
|
...initialState,
|
|
|
|
|
source: "es",
|
2021-03-18 23:47:12 +01:00
|
|
|
target: "ca",
|
|
|
|
|
query: faker.random.words(),
|
|
|
|
|
translation: faker.random.words()
|
2021-03-12 19:41:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const res = langReducer(state, { type: Actions.SWITCH_LANGS });
|
2021-03-18 23:47:12 +01:00
|
|
|
expect(res).toStrictEqual({
|
|
|
|
|
source: state.target,
|
|
|
|
|
target: state.source,
|
|
|
|
|
query: state.translation,
|
|
|
|
|
delayedQuery: state.translation,
|
|
|
|
|
translation: ""
|
|
|
|
|
});
|
2021-03-12 19:41:20 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("resets the source while switching if they're the same", () => {
|
|
|
|
|
const state = {
|
|
|
|
|
...initialState,
|
|
|
|
|
source: "eo",
|
|
|
|
|
target: "eo"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const res = langReducer(state, { type: Actions.SWITCH_LANGS });
|
|
|
|
|
expect(res.source).toStrictEqual(initialState.source);
|
|
|
|
|
expect(res.target).toStrictEqual(state.source);
|
|
|
|
|
});
|