<commit_before>import RequestContext from "../../../context/RequestContext";
import History from "../../../components/History";
import ExpressServerRequest from "../../../ExpressServerRequest";
import NavigatorRoutes from "./NavigatorRoutes";

describe("Navigator", () => {
	let requestContext;
	const options = {
		routes: NavigatorRoutes,
	};

	beforeEach(() => {
		requestContext = new RequestContext(options);
	});
	afterEach(() => {
		requestContext = null;
	});

	it("routes to a basic page using an unspecified method get", (done) => {
		const req = {
			method: "get",
			protocol: "http",
			secure: false,
			hostname: "localhost",
			url: "/basicPage",
		};
		const expressRequest = new ExpressServerRequest(req);

		requestContext.navigator.on('page', () => {
			expect(expressRequest.getRouteName() === 'BasicPage');
			done();
		});

		requestContext.navigate(expressRequest, History.events.PAGELOAD);
	});


	it("routes to a page using a method GET (caps)", (done) => {
		const req = {
			method: "get",
			protocol: "http",
			secure: false,
			hostname: "localhost",
			url: "/basicPageCaps",
		};
		const expressRequest = new ExpressServerRequest(req);

		requestContext.navigator.on('page', () => {
			expect(expressRequest.getRouteName() === 'BasicPageCaps');
			done();
		});

		requestContext.navigate(expressRequest, History.events.PAGELOAD);
	});

	it("routes to a page using a method POST", (done) => {
		const req = {
			method: "post",
			protocol: "http",
			secure: false,
			hostname: "localhost",
			url: "/postPage",
		};
		const expressRequest = new ExpressServerRequest(req);

		requestContext.navigator.on('page', () => {
			expect(expressRequest.getRouteName() === 'PostPage');<commit_msg>Convert the test to use a RequestContext() stub instead of the whole thing.<commit_after>import Navigator from "../../../context/Navigator";
import History from "../../../components/History";
import ExpressServerRequest from "../../../ExpressServerRequest";
import NavigatorRoutes from "./NavigatorRoutes";

class RequestContextStub {
	constructor(options) {
		this.navigator = new Navigator(this, options);
	}
	navigate (request, type) {
		this.navigator.navigate(request, type);
	}
	framebackControllerWillHandle() { return false; }
	getMobileDetect() { return null; }
}


describe("Navigator", () => {
	let requestContext;
	const options = {
		routes: NavigatorRoutes,
	};

	beforeEach(() => {
		//requestContext = new RequestContext(options);
		requestContext = new RequestContextStub(options);
	});
	afterEach(() => {
		requestContext = null;
	});

	it("routes to a basic page using an unspecified method get", (done) => {
		const req = {
			method: "get",
			protocol: "http",
			secure: false,
			hostname: "localhost",
			url: "/basicPage",
		};
		const expressRequest = new ExpressServerRequest(req);

		requestContext.navigator.on('page', () => {
			expect(expressRequest.getRouteName() === 'BasicPage');
			done();
		});

		requestContext.navigate(expressRequest, History.events.PAGELOAD);
	});

	it("routes to a basic page using an unspecified method HEAD", (done) => {
		const req = {
			method: "head",
			protocol: "http",
			secure: false,
			hostname: "localhost",
			url: "/basicPage",
		};
		const expressRequest = new ExpressServerRequest(req);

		requestContext.navigator.on('page', () => {
			expect(expressRequest.getRouteName() === 'BasicPage');
			done();
		});

		requestContext.navigate(expressRequest, History.events.PAGELOAD);
	});

	it("routes to a page using a method GET (caps)", (done) => {
		const req = {
			method: "get",
			protocol: "http",
			secure: false,
			hostname: "localhost",
			url: "/basicPageCaps",
		};
		const expressRequest = new ExpressServerRequest(req);

		requestContext.navigator.on('page', () => {
			expect(expressRequest.getRouteName() === 'BasicPageCaps');
			done();
		});

		requestContext.navigate(expressRequest, History.events.PAGELOAD);
	});

	it("routes to a page using a method POST", (done) => {
		const req = {
			method: "post",
			protocol: "http",
			secure: false,
			hostname: "localhost",
			url: "/postPage",
		};
		const expressRequest = new ExpressServerRequest(req);

		requestContext.navigator.on('page', () => {
			expect(expressRequest.getRouteName() === 'PostPage');
{'fraction_non_alphanumeric': 0.1646013560907178, 'fraction_numerical': 0.0, 'mean_word_length': 4.123353293413174, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7152074', 'n_tokens_mistral': 1441, 'n_tokens_neox': 1303, 'n_words': 311}