mirror of
https://github.com/gethomepage/homepage.git
synced 2026-02-09 09:20:59 +08:00
Chore: homepage tests (#6278)
This commit is contained in:
45
src/__tests__/pages/robots.txt.test.js
Normal file
45
src/__tests__/pages/robots.txt.test.js
Normal file
@@ -0,0 +1,45 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
const { getSettings } = vi.hoisted(() => ({
|
||||
getSettings: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("utils/config/config", () => ({
|
||||
getSettings,
|
||||
}));
|
||||
|
||||
import RobotsTxt, { getServerSideProps } from "pages/robots.txt.js";
|
||||
|
||||
function createMockRes() {
|
||||
return {
|
||||
setHeader: vi.fn(),
|
||||
write: vi.fn(),
|
||||
end: vi.fn(),
|
||||
};
|
||||
}
|
||||
|
||||
describe("pages/robots.txt", () => {
|
||||
it("allows indexing when disableIndexing is falsey", async () => {
|
||||
getSettings.mockReturnValueOnce({ disableIndexing: false });
|
||||
const res = createMockRes();
|
||||
|
||||
await getServerSideProps({ res });
|
||||
|
||||
expect(res.setHeader).toHaveBeenCalledWith("Content-Type", "text/plain");
|
||||
expect(res.write).toHaveBeenCalledWith("User-agent: *\nAllow: /");
|
||||
expect(res.end).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("disallows indexing when disableIndexing is truthy", async () => {
|
||||
getSettings.mockReturnValueOnce({ disableIndexing: true });
|
||||
const res = createMockRes();
|
||||
|
||||
await getServerSideProps({ res });
|
||||
|
||||
expect(res.write).toHaveBeenCalledWith("User-agent: *\nDisallow: /");
|
||||
});
|
||||
|
||||
it("exports a placeholder component", () => {
|
||||
expect(RobotsTxt()).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user