Files
SCM-Manager/scm-ui/src/repos/sources/components/content/SourcecodeViewer.test.js

50 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-10-15 16:45:54 +02:00
//@flow
import fetchMock from "fetch-mock";
2018-10-29 14:53:24 +01:00
import {
getContent,
getLanguage,
getProgrammingLanguage
} from "./SourcecodeViewer";
2018-10-15 16:45:54 +02:00
describe("get content", () => {
2018-10-29 11:50:55 +01:00
const CONTENT_URL = "/repositories/scmadmin/TestRepo/content/testContent";
2018-10-15 16:45:54 +02:00
afterEach(() => {
fetchMock.reset();
fetchMock.restore();
});
it("should return content", done => {
fetchMock.getOnce("/api/v2" + CONTENT_URL, "This is a testContent");
getContent(CONTENT_URL).then(content => {
expect(content).toBe("This is a testContent");
done();
});
});
2018-10-29 14:53:24 +01:00
it("should return language", done => {
let headers = {
2018-10-29 15:27:21 +01:00
"X-Programming-Language": "JAVA"
2018-10-29 14:53:24 +01:00
};
fetchMock.head("/api/v2" + CONTENT_URL, {
headers
});
getProgrammingLanguage(CONTENT_URL).then(content => {
expect(content.language).toBe("JAVA");
done();
});
});
2018-10-15 16:45:54 +02:00
});
2018-10-29 11:50:55 +01:00
describe("get correct language type", () => {
2018-10-29 11:50:55 +01:00
it("should return javascript", () => {
2018-10-29 14:53:24 +01:00
expect(getLanguage("JAVASCRIPT")).toBe("javascript");
});
2018-10-29 14:53:24 +01:00
it("should return nothing for plain text", () => {
expect(getLanguage("")).toBe("");
});
2018-10-29 11:50:55 +01:00
});