* Added translate and switch auto buttons * Tests updated * Added hotkey & improved buttons visually
84 lines
2.1 KiB
TypeScript
84 lines
2.1 KiB
TypeScript
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", () => {
|
|
const query = faker.random.words();
|
|
const state = {
|
|
source: faker.random.locale(),
|
|
target: faker.random.locale(),
|
|
query,
|
|
delayedQuery: query,
|
|
translation: faker.random.words(),
|
|
isLoading: faker.datatype.boolean()
|
|
};
|
|
|
|
const res = langReducer(initialState, {
|
|
type: Actions.SET_ALL,
|
|
payload: { state }
|
|
});
|
|
expect(res).toStrictEqual(state);
|
|
});
|
|
|
|
it("switches target on source change", () => {
|
|
const state = {
|
|
...initialState,
|
|
source: "es",
|
|
target: "ca"
|
|
};
|
|
|
|
const res = langReducer(state, {
|
|
type: Actions.SET_FIELD,
|
|
payload: {
|
|
key: "source",
|
|
value: state.target
|
|
}
|
|
});
|
|
expect(res.source).toStrictEqual(state.target);
|
|
expect(res.target).toStrictEqual(state.source);
|
|
});
|
|
|
|
it("switches the languages & the translations", () => {
|
|
const state = {
|
|
...initialState,
|
|
source: "es",
|
|
target: "ca",
|
|
query: faker.random.words(),
|
|
translation: faker.random.words()
|
|
};
|
|
|
|
const res = langReducer(state, { type: Actions.SWITCH_LANGS });
|
|
expect(res).toStrictEqual({
|
|
source: state.target,
|
|
target: state.source,
|
|
query: state.translation,
|
|
delayedQuery: state.translation,
|
|
translation: state.query,
|
|
isLoading: initialState.isLoading
|
|
});
|
|
});
|
|
|
|
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);
|
|
});
|