Text to Speech (#2)

* Initial TTS scrapping implemented

* Audio & copy buttons added

* TTS langs mapping fix

* Webkit audio api fix

* Added TTS-related testing

* Last tweaks
This commit is contained in:
David
2021-03-25 16:48:46 +01:00
committed by GitHub
parent 034355b640
commit 7288e9ace7
11 changed files with 302 additions and 49 deletions

View File

@@ -1,6 +1,6 @@
import { htmlRes, resolveFetchWith } from "../commonUtils";
import faker from "faker";
import { googleScrape, extractSlug } from "../../utils/translate";
import { googleScrape, extractSlug, textToSpeechScrape } from "../../utils/translate";
const source = faker.random.locale();
const target = faker.random.locale();
@@ -65,3 +65,21 @@ describe("extractSlug", () => {
expect(extractSlug(array)).toStrictEqual({});
});
});
describe("textToSpeechScrape", () => {
it("returns an array on successful request", async () => {
resolveFetchWith({ status: 200 });
expect(await textToSpeechScrape(target, query)).toEqual(expect.any(Array));
});
it("returns 'null' on request error", async () => {
const status = faker.random.number({ min: 400, max: 499 });
resolveFetchWith({ status });
expect(await textToSpeechScrape(target, query)).toBeNull();
});
it("returns 'null' on network error", async () => {
fetchMock.mockRejectOnce();
expect(await textToSpeechScrape(target, query)).toBeNull();
});
});