Translation swap added

This commit is contained in:
David
2021-03-18 23:47:12 +01:00
parent 535f791455
commit 2bc931a4d3
7 changed files with 107 additions and 50 deletions

View File

@@ -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", () => {

View File

@@ -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 () => {