Translation swap added
This commit is contained in:
@@ -15,10 +15,13 @@ it("changes a field value", () => {
|
||||
});
|
||||
|
||||
it("changes all fields", () => {
|
||||
const query = faker.random.words();
|
||||
const state = {
|
||||
source: faker.random.locale(),
|
||||
target: faker.random.locale(),
|
||||
query: faker.random.words()
|
||||
query,
|
||||
delayedQuery: query,
|
||||
translation: faker.random.words()
|
||||
};
|
||||
|
||||
const res = langReducer(initialState, {
|
||||
@@ -28,16 +31,23 @@ it("changes all fields", () => {
|
||||
expect(res).toStrictEqual(state);
|
||||
});
|
||||
|
||||
it("switches the languages", () => {
|
||||
it("switches the languages & the translations", () => {
|
||||
const state = {
|
||||
...initialState,
|
||||
source: "es",
|
||||
target: "ca"
|
||||
target: "ca",
|
||||
query: faker.random.words(),
|
||||
translation: faker.random.words()
|
||||
};
|
||||
|
||||
const res = langReducer(state, { type: Actions.SWITCH_LANGS });
|
||||
expect(res.source).toStrictEqual(state.target);
|
||||
expect(res.target).toStrictEqual(state.source);
|
||||
expect(res).toStrictEqual({
|
||||
source: state.target,
|
||||
target: state.source,
|
||||
query: state.translation,
|
||||
delayedQuery: state.translation,
|
||||
translation: ""
|
||||
});
|
||||
});
|
||||
|
||||
it("resets the source while switching if they're the same", () => {
|
||||
|
||||
@@ -12,11 +12,11 @@ describe("googleScrape", () => {
|
||||
});
|
||||
|
||||
it("parses html response correctly", async () => {
|
||||
const translation = faker.random.words();
|
||||
const html = htmlRes(translation);
|
||||
const translationRes = faker.random.words();
|
||||
const html = htmlRes(translationRes);
|
||||
resolveFetchWith(html);
|
||||
|
||||
expect(await googleScrape(source, target, query)).toStrictEqual({ translation });
|
||||
expect(await googleScrape(source, target, query)).toStrictEqual({ translationRes });
|
||||
});
|
||||
|
||||
it("returns status code on request error", async () => {
|
||||
|
||||
Reference in New Issue
Block a user