import assert from "node:assert/strict";
import { describe, it } from "node:test";
import { readFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

const __dirname = dirname(fileURLToPath(import.meta.url));
const source = readFileSync(join(__dirname, "OrgPermissionTree.vue"), "utf8");

describe("OrgPermissionTree hierarchy lines", () => {
  it("draws connector lines only between each node and its direct children", () => {
    assert.match(source, /\.org-tree-children\s*>\s*\.org-tree-branch::before/);
    assert.match(source, /\.org-tree-children\s*>\s*\.org-tree-branch\s*>\s*\.org-tree-node::before/);
    assert.doesNotMatch(source, /\.org-tree-children::before/);
    assert.doesNotMatch(source, /^\.org-tree-branch::before/m);
    assert.match(source, /--tree-connector-x/);
    assert.match(source, /--tree-node-start/);
    assert.match(source, /--tree-arrow-gap/);
    assert.match(source, /--tree-connector-color/);
    assert.match(source, /--tree-connector-color:\s*rgba\(148,\s*163,\s*184/);
    assert.match(source, /--tree-connector-width:\s*2px/);
    assert.match(source, /border-left:\s*var\(--tree-connector-width\)\s*dashed\s*var\(--tree-connector-color\)/);
    assert.match(source, /border-top:\s*var\(--tree-connector-width\)\s*dashed\s*var\(--tree-connector-color\)/);
    assert.doesNotMatch(source, /background:\s*var\(--tree-connector-color\)/);
  });
});

describe("OrgPermissionTree employee list", () => {
  it("shows each employee organization path with full-value hover text", () => {
    assert.match(source, /<th>组织路径<\/th>/);
    assert.match(source, /employeeOrganizationPath\(employee\)/);
    assert.match(source, /class="org-path-value"\s+:title="employeeOrganizationPath\(employee\)"/);
    assert.match(source, /class="org-path-tail"\s+:title="employeeOrganizationPath\(employee\)"/);
    assert.match(source, /function employeeOrganizationTail\(employee\)/);
    assert.doesNotMatch(source, /org-path-pill/);
    assert.match(source, /<td colspan="7" class="empty-row"/);
  });

  it("keeps row action buttons inside an inner flex container instead of flexing the table cell", () => {
    assert.match(source, /<td class="action-row">\s*<div class="employee-actions">/);
    assert.match(source, /\.employee-actions\s*\{[\s\S]*?display:\s*inline-flex;/);
    assert.doesNotMatch(source, /\.action-row\s*\{[^}]*display:\s*flex;/);
  });
});
