Skip to content

Commit

Permalink
Add unit tests for file tooltips
Browse files Browse the repository at this point in the history
  • Loading branch information
dotNomad committed Dec 21, 2024
1 parent 23230eb commit 45632a9
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { describe, it, expect } from "vitest";
import { includedFileTooltip, excludedFileTooltip } from "./tooltips";
import { FileMatchSource } from "../../../../../../src/api";

describe("includedFileTooltip", () => {
it("should return correct tooltip for included file without reason", () => {
const file = { rel: "src/index.ts", reason: null };
const tooltip = includedFileTooltip(file);
expect(tooltip).toBe(
"src/index.ts will be included in the next deployment.",
);
});

it("should return correct tooltip for included file with reason", () => {
const file = {
rel: "src/config.json",
reason: {
fileName: "config.json",
pattern: "*.json",
source: FileMatchSource.FILE,
filePath: "src/config.json",
exclude: false,
},
};
const tooltip = includedFileTooltip(file);
expect(tooltip).toBe(
`src/config.json will be included in the next deployment.\nThe configuration file config.json is including it with the pattern '*.json'`,
);
});

it("should return correct tooltip for entrypoint file", () => {
const file = { rel: "src/index.ts", reason: null };
const tooltip = includedFileTooltip(file, true);
expect(tooltip).toBe(
`src/index.ts will be included in the next deployment.\nsrc/index.ts is the entrypoint. Entrypoints must be included in the configuration 'files' list.`,
);
});
});

describe("excludedFileTooltip", () => {
it("should return correct tooltip for excluded file without reason", () => {
const file = { rel: "src/index.ts", reason: null };
const tooltip = excludedFileTooltip(file);
expect(tooltip).toBe(
`src/index.ts will be excluded in the next deployment.\nIt did not match any pattern in the configuration 'files' list.`,
);
});

it("should return correct tooltip for excluded file with built-in reason", () => {
const file = {
rel: "src/index.ts",
reason: {
source: FileMatchSource.BUILT_IN,
pattern: "*.ts",
fileName: "config.json",
filePath: "src/index.ts",
exclude: true,
},
};
const tooltip = excludedFileTooltip(file);
expect(tooltip).toBe(
`src/index.ts will be excluded in the next deployment.\nThis is a built-in exclusion for the pattern: '*.ts' and cannot be overridden.`,
);
});

it("should return correct tooltip for excluded file with permissions error", () => {
const file = {
rel: "src/index.ts",
reason: {
source: FileMatchSource.PERMISSIONS_ERROR,
pattern: "",
fileName: "",
filePath: "",
exclude: true,
},
};
const tooltip = excludedFileTooltip(file);
expect(tooltip).toBe(
`src/index.ts will be excluded in the next deployment.\nYou don't have permission to access this directory.`,
);
});

it("should return correct tooltip for excluded file with custom reason", () => {
const file = {
rel: "src/index.ts",
reason: {
fileName: "config.json",
pattern: "*.ts",
source: FileMatchSource.FILE,
filePath: "src/index.ts",
exclude: true,
},
};
const tooltip = excludedFileTooltip(file);
expect(tooltip).toBe(
`src/index.ts will be excluded in the next deployment.\nThe configuration file config.json is excluding it with the pattern '*.ts'`,
);
});
});
8 changes: 4 additions & 4 deletions extensions/vscode/webviews/homeView/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ export default defineConfig({
coverage: {
enabled: true,
thresholds: {
functions: 27.77,
lines: 16.06,
branches: 37.97,
statements: 16.06,
functions: 30.13,
lines: 17.48,
branches: 44.82,
statements: 17.48,
autoUpdate: true,
},
},
Expand Down

0 comments on commit 45632a9

Please sign in to comment.