Skip to content

Commit 4bb004a

Browse files
sandbox testing
1 parent 10e4742 commit 4bb004a

7 files changed

Lines changed: 737 additions & 505 deletions

File tree

.yarnrc.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1+
compressionLevel: mixed
2+
3+
enableGlobalCache: false
4+
15
nodeLinker: pnp

esbuild.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
import dotenv from "dotenv"
2-
import esbuild from "esbuild"
1+
import dotenv from "dotenv";
2+
import esbuild from "esbuild";
33

44
dotenv.config();
55

6+
const outputDir = process.argv[2] === "test" ? "sandbox" : "build";
7+
const outfile = `${outputDir}/compiled.js`;
8+
69
const result = await esbuild.build({
710
entryPoints: [`lib/plugin.js`],
811
bundle: true,
912
format: "iife",
10-
outfile: "build/compiled.js",
13+
outfile: outfile,
1114
packages: "external",
1215
platform: "node",
1316
write: true,
1417
});
15-
console.log("Result was", result)
18+
console.log("Result was", result);

lib/plugin.js

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
const plugin = {
22
constants: {},
3-
// https://www.amplenote.com/help/developing_amplenote_plugins#noteOption
43
taskOption: {
5-
"Bulk Actions - Clear Overdue Tasks": {
4+
"Clear Overdue Tasks": {
65
run: async function (app, noteUUID) {
76
try {
87
// Get current time minus 1 hour
@@ -107,7 +106,7 @@ const plugin = {
107106
successCount++;
108107
} else {
109108
console.log(
110-
` ⚠ Task ${task.uuid} has no calendar dates to remove`
109+
` ⚠ Task ${task.uuid} has no calendar dates to remove`,
111110
);
112111
successCount++;
113112
}
@@ -141,10 +140,34 @@ const plugin = {
141140
}
142141
},
143142
},
144-
},
143+
"Hide Lower Priority Tasks": {
144+
run: async function (app, noteUUID) {
145+
try {
146+
const taskDomains = await app.getTaskDomains();
145147

146-
insertText: {},
148+
if (!taskDomains || taskDomains.length === 0) {
149+
await app.alert("No task domains found.");
150+
return;
151+
}
152+
153+
const tasksByDomain = {}; // Track tasks per domain
147154

155+
for (const taskDomain of taskDomains) {
156+
const domainTasks = app.getTaskDomainTasks(taskDomain.uuid);
157+
if (domainTasks.length > 0) {
158+
tasksByDomain[taskDomain.name] = domainTasks;
159+
}
160+
}
161+
162+
await app.alert(JSON.stringify(tasksByDomain));
163+
} catch (error) {
164+
console.error("Error in Bulk Reset Overdue Tasks:", error);
165+
await app.alert(`Error: ${error.message}`);
166+
}
167+
},
168+
},
169+
},
170+
insertText: {},
148171
replaceText: {},
149172
};
150173
export default plugin;

lib/plugin.test.js

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { jest } from "@jest/globals";
22
import { mockPlugin, mockApp } from "./test-helpers.js";
33

4-
// --------------------------------------------------------------------------------------
54
describe("Bulk Task Reset Plugin", () => {
65
const plugin = mockPlugin();
76
plugin.constants.isTestEnvironment = true;
@@ -11,10 +10,7 @@ describe("Bulk Task Reset Plugin", () => {
1110
app.getTaskDomains = jest.fn().mockResolvedValue([]);
1211
app.alert = jest.fn();
1312

14-
await plugin.taskOption["Bulk Actions - Clear Overdue Tasks"].run(
15-
app,
16-
"test-note-uuid"
17-
);
13+
await plugin.taskOption["Clear Overdue Tasks"].run(app, "test-note-uuid");
1814

1915
expect(app.alert).toHaveBeenCalledWith("No task domains found.");
2016
});
@@ -31,15 +27,12 @@ describe("Bulk Task Reset Plugin", () => {
3127
app.getTaskDomainTasks = jest.fn().mockReturnValue(
3228
(async function* () {
3329
yield { uuid: "task1", startAt: thirtyMinutesAgo };
34-
})()
30+
})(),
3531
);
3632

3733
app.alert = jest.fn();
3834

39-
await plugin.taskOption["Bulk Actions - Clear Overdue Tasks"].run(
40-
app,
41-
"test-note-uuid"
42-
);
35+
await plugin.taskOption["Clear Overdue Tasks"].run(app, "test-note-uuid");
4336

4437
expect(app.alert).toHaveBeenCalledWith("No overdue tasks found.");
4538
});
@@ -57,7 +50,7 @@ describe("Bulk Task Reset Plugin", () => {
5750
(async function* () {
5851
yield { uuid: "task1", startAt: yesterday, content: "Buy groceries" };
5952
yield { uuid: "task2", endAt: yesterday, content: "Call dentist" };
60-
})()
53+
})(),
6154
);
6255

6356
app.updateTask = jest.fn().mockResolvedValue(true);
@@ -66,31 +59,28 @@ describe("Bulk Task Reset Plugin", () => {
6659
.mockResolvedValueOnce(1) // User clicks "Reset All"
6760
.mockResolvedValueOnce(undefined); // Success message
6861

69-
await plugin.taskOption["Bulk Actions - Clear Overdue Tasks"].run(
70-
app,
71-
"test-note-uuid"
72-
);
62+
await plugin.taskOption["Clear Overdue Tasks"].run(app, "test-note-uuid");
7363

7464
// Check that confirmation message includes domain name, count, and task names
7565
expect(app.alert).toHaveBeenNthCalledWith(
7666
1,
7767
expect.stringContaining("Found 2 overdue tasks"),
78-
expect.any(Object)
68+
expect.any(Object),
7969
);
8070
expect(app.alert).toHaveBeenNthCalledWith(
8171
1,
8272
expect.stringContaining("My Tasks (2)"),
83-
expect.any(Object)
73+
expect.any(Object),
8474
);
8575
expect(app.alert).toHaveBeenNthCalledWith(
8676
1,
8777
expect.stringContaining("Buy groceries"),
88-
expect.any(Object)
78+
expect.any(Object),
8979
);
9080
expect(app.alert).toHaveBeenNthCalledWith(
9181
1,
9282
expect.stringContaining("Call dentist"),
93-
expect.any(Object)
83+
expect.any(Object),
9484
);
9585

9686
expect(app.updateTask).toHaveBeenCalledTimes(1);
@@ -110,16 +100,13 @@ describe("Bulk Task Reset Plugin", () => {
110100
app.getTaskDomainTasks = jest.fn().mockReturnValue(
111101
(async function* () {
112102
yield { uuid: "task1", startAt: yesterday };
113-
})()
103+
})(),
114104
);
115105

116106
app.updateTask = jest.fn();
117107
app.alert = jest.fn().mockResolvedValue(0); // User clicks "Cancel"
118108

119-
await plugin.taskOption["Bulk Actions - Clear Overdue Tasks"].run(
120-
app,
121-
"test-note-uuid"
122-
);
109+
await plugin.taskOption["Clear Overdue Tasks"].run(app, "test-note-uuid");
123110

124111
expect(app.updateTask).not.toHaveBeenCalled();
125112
});

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
"name": "plugin-template",
1717
"scripts": {
1818
"build": "node esbuild.js",
19+
"build-test": "node esbuild.js test",
1920
"test": "yarn node --experimental-vm-modules $(yarn bin jest)"
2021
},
2122
"testEnvironment": "jsdom",
2223
"type": "module",
23-
"version": "1.0.5"
24+
"version": "1.0.8"
2425
}

0 commit comments

Comments
 (0)