{"size": 1619, "ext": "js", "max_stars_repo_path": "spec/git/rootDir-spec.js", "max_stars_repo_name": "aagerblad/git-menu", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "spec/git/rootDir-spec.js", "max_issues_repo_name": "aagerblad/git-menu", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "spec/git/rootDir-spec.js", "max_forks_repo_name": "aagerblad/git-menu", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.296875, "max_line_length": 90, "alphanum_fraction": 0.6621371217}
/** @babel */

import path from "path";
import gitCmd from "../../lib/git-cmd";
import {getFilePath, removeGitRoot, createGitRoot, files} from "../mocks";

describe("git.rootDir", function () {

	beforeEach(function () {
		spyOn(gitCmd, "cmd").and.returnValue(Promise.resolve("root"));

		this.gitRoot = "root";
	});

	it("should send ['rev-parse', '--show-toplevel'] to cmd", async function () {
		await gitCmd.rootDir(this.gitRoot);

		expect(gitCmd.cmd.calls.mostRecent().args[1]).toEqual(["rev-parse", "--show-toplevel"]);
	});

	it("should return path from cmd", async function () {
		const root = await gitCmd.rootDir("test");

		expect(root).toEqual("root");
	});

	it("should return cwd for smb path", async function () {
		gitCmd.cmd.and.returnValue(Promise.resolve("\\\\root"));
		const root = await gitCmd.rootDir("test");

		expect(root).toEqual("test");
	});

	it("should return cwd for smb:// path", async function () {
		gitCmd.cmd.and.returnValue(Promise.resolve("smb://root"));
		const root = await gitCmd.rootDir("test");

		expect(root).toEqual("test");
	});

	describe("integration tests", function () {

		beforeEach(async function () {
			gitCmd.cmd.and.callThrough();
			await atom.packages.activatePackage("git-menu");
			this.gitRoot = await createGitRoot();

			this.gitPath = getFilePath(this.gitRoot, ".git");
		});

		afterEach(async function () {
			await removeGitRoot(this.gitRoot);
		});

		it("should get root dir", async function () {
			const root = await gitCmd.rootDir(getFilePath(this.gitRoot, path.dirname(files.tt1)));

			expect(root).toContain(this.gitRoot);
		});

	});

});
