mirror of
https://github.com/sechan100/daily-routine-2.git
synced 2026-07-22 05:37:51 +00:00
테스트 환경 구축
This commit is contained in:
parent
b108531130
commit
6bd8f646c6
7 changed files with 12880 additions and 9528 deletions
59
__mocks__/obsidian.ts
Normal file
59
__mocks__/obsidian.ts
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
import EventEmitter from "events";
|
||||
import _moment from "moment";
|
||||
|
||||
/** Basic obsidian abstraction for any file or folder in a vault. */
|
||||
export abstract class TAbstractFile {
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
vault: Vault;
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
path: string;
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
parent: TFolder;
|
||||
}
|
||||
|
||||
/** Tracks file created/modified time as well as file system size. */
|
||||
export interface FileStats {
|
||||
/** @public */
|
||||
ctime: number;
|
||||
/** @public */
|
||||
mtime: number;
|
||||
/** @public */
|
||||
size: number;
|
||||
}
|
||||
|
||||
/** A regular file in the vault. */
|
||||
export class TFile extends TAbstractFile {
|
||||
stat: FileStats;
|
||||
basename: string;
|
||||
extension: string;
|
||||
}
|
||||
|
||||
/** A folder in the vault. */
|
||||
export class TFolder extends TAbstractFile {
|
||||
children: TAbstractFile[];
|
||||
|
||||
isRoot(): boolean {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export class Vault extends EventEmitter {
|
||||
getFiles() {
|
||||
return [];
|
||||
}
|
||||
trigger(name: string, ...data: any[]): void {
|
||||
this.emit(name, ...data);
|
||||
}
|
||||
}
|
||||
|
||||
export const moment = _moment;
|
||||
5
jest.config.js
Normal file
5
jest.config.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
module.exports = {
|
||||
preset: "ts-jest",
|
||||
testEnvironment: "jsdom",
|
||||
moduleDirectories: ["node_modules", "src"],
|
||||
};
|
||||
22190
package-lock.json
generated
22190
package-lock.json
generated
File diff suppressed because it is too large
Load diff
112
package.json
112
package.json
|
|
@ -1,54 +1,60 @@
|
|||
{
|
||||
"name": "daily-routine-obsidian-plugin",
|
||||
"version": "1.0.1",
|
||||
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
"dev": "node esbuild.config.mjs dev",
|
||||
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
|
||||
"local": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs local",
|
||||
"version": "node version-bump.mjs && git add manifest.json versions.json"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/lodash": "^4.17.7",
|
||||
"@types/node": "^16.11.6",
|
||||
"@types/react": "^18.3.8",
|
||||
"@types/react-dom": "^18.3.0",
|
||||
"@typescript-eslint/eslint-plugin": "5.29.0",
|
||||
"@typescript-eslint/parser": "5.29.0",
|
||||
"builtin-modules": "3.3.0",
|
||||
"esbuild": "^0.24.0",
|
||||
"eslint-plugin-fsd-import": "^0.0.13",
|
||||
"obsidian": "latest",
|
||||
"tslib": "2.4.0",
|
||||
"typescript": "4.7.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@emotion/react": "^11.13.3",
|
||||
"@emotion/styled": "^11.13.0",
|
||||
"@mui/material": "^6.1.6",
|
||||
"@popperjs/core": "^2.11.8",
|
||||
"clsx": "^2.1.1",
|
||||
"esbuild-sass-plugin": "^3.3.1",
|
||||
"eslint-plugin-react": "^7.37.1",
|
||||
"eslint-plugin-react-hooks": "^4.6.2",
|
||||
"lodash": "^4.17.21",
|
||||
"mitt": "^3.0.1",
|
||||
"npm": "^10.8.3",
|
||||
"react": "^18.3.1",
|
||||
"react-bem-helper": "^1.4.1",
|
||||
"react-calendar": "^5.0.0",
|
||||
"react-devtools": "^6.0.1",
|
||||
"react-dnd": "^16.0.1",
|
||||
"react-dnd-html5-backend": "^16.0.1",
|
||||
"react-dnd-multi-backend": "^8.0.3",
|
||||
"react-dnd-touch-backend": "^16.0.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"sass": "^1.79.4",
|
||||
"swiper": "^11.1.14",
|
||||
"zustand": "^5.0.0-rc.2"
|
||||
}
|
||||
}
|
||||
"name": "daily-routine-obsidian-plugin",
|
||||
"version": "1.0.1",
|
||||
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
"dev": "node esbuild.config.mjs dev",
|
||||
"test": "jest",
|
||||
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
|
||||
"local": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs local",
|
||||
"version": "node version-bump.mjs && git add manifest.json versions.json"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/jest": "^29.5.14",
|
||||
"@types/lodash": "^4.17.7",
|
||||
"@types/node": "^16.11.6",
|
||||
"@types/react": "^18.3.8",
|
||||
"@types/react-dom": "^18.3.0",
|
||||
"@typescript-eslint/eslint-plugin": "5.29.0",
|
||||
"@typescript-eslint/parser": "5.29.0",
|
||||
"babel-jest": "^29.7.0",
|
||||
"builtin-modules": "3.3.0",
|
||||
"esbuild": "^0.24.0",
|
||||
"eslint-plugin-fsd-import": "^0.0.13",
|
||||
"jest": "^29.7.0",
|
||||
"jest-environment-jsdom": "^29.7.0",
|
||||
"obsidian": "latest",
|
||||
"ts-jest": "^29.2.5",
|
||||
"tslib": "2.4.0",
|
||||
"typescript": "4.7.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@emotion/react": "^11.13.3",
|
||||
"@emotion/styled": "^11.13.0",
|
||||
"@mui/material": "^6.1.6",
|
||||
"@popperjs/core": "^2.11.8",
|
||||
"clsx": "^2.1.1",
|
||||
"esbuild-sass-plugin": "^3.3.1",
|
||||
"eslint-plugin-react": "^7.37.1",
|
||||
"eslint-plugin-react-hooks": "^4.6.2",
|
||||
"lodash": "^4.17.21",
|
||||
"mitt": "^3.0.1",
|
||||
"npm": "^10.8.3",
|
||||
"react": "^18.3.1",
|
||||
"react-bem-helper": "^1.4.1",
|
||||
"react-calendar": "^5.0.0",
|
||||
"react-devtools": "^6.0.1",
|
||||
"react-dnd": "^16.0.1",
|
||||
"react-dnd-html5-backend": "^16.0.1",
|
||||
"react-dnd-multi-backend": "^8.0.3",
|
||||
"react-dnd-touch-backend": "^16.0.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"sass": "^1.79.4",
|
||||
"swiper": "^11.1.14",
|
||||
"zustand": "^5.0.0-rc.2"
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,6 @@ import { fileAccessor } from "shared/file/file-accessor";
|
|||
import { plugin } from "shared/plugin-service-locator";
|
||||
import { TAbstractFile, TFile } from "obsidian";
|
||||
import { Day } from "shared/day";
|
||||
import moment from "moment";
|
||||
import { FileNotFoundError } from "shared/file/errors";
|
||||
import { openConfirmModal } from "shared/components/modal/confirm-modal";
|
||||
|
||||
|
|
@ -60,13 +59,11 @@ export const routineNoteArchiver: RoutineNoteArchiver = {
|
|||
|
||||
async loadBetween(start: Day, end: Day): Promise<RoutineNote[]> {
|
||||
const notes: RoutineNote[] = [];
|
||||
const s = start.moment;
|
||||
const e = end.moment;
|
||||
const routineNoteFiles: TAbstractFile[] = fileAccessor.getFolder(plugin().settings.routineArchiveFolderPath).children.filter(file => file instanceof TFile);
|
||||
for(const file of routineNoteFiles){
|
||||
if(!(file instanceof TFile)) continue;
|
||||
const day = moment(file.basename);
|
||||
if(day.isBetween(s, e, 'day', '[]')){
|
||||
const day = Day.fromString(file.basename);
|
||||
if(day.isBetween(start, end, 'day', '[]')){
|
||||
notes.push(await parseFile(file));
|
||||
}
|
||||
}
|
||||
|
|
@ -160,7 +157,7 @@ const getRoutineNoteFile = (day: Day): TFile | null => {
|
|||
const parseFile = async (file: TFile): Promise<RoutineNote> => {
|
||||
const content = await fileAccessor.readFileAsReadonly(file);
|
||||
if(!content) throw new Error('RoutineNote file is empty.');
|
||||
return routineNoteService.deserialize(new Day(moment(file.basename)), content);
|
||||
return routineNoteService.deserialize(Day.fromString(file.basename), content);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ export class Day {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
static now(): Day{
|
||||
return new Day(moment());
|
||||
}
|
||||
|
|
@ -37,6 +36,10 @@ export class Day {
|
|||
return new Day(moment('9999-12-31T23:59:59.999Z'));
|
||||
}
|
||||
|
||||
static fromString(str: string){
|
||||
return new Day(moment(str));
|
||||
}
|
||||
|
||||
format(format: string){
|
||||
return this.#moment.format(format);
|
||||
}
|
||||
|
|
@ -58,6 +61,10 @@ export class Day {
|
|||
return this;
|
||||
}
|
||||
|
||||
isBetween(start: Day, end: Day, unit?: moment.unitOfTime.StartOf, inclusivity?: "()" | "[)" | "(]" | "[]"){
|
||||
return this.#moment.isBetween(start.#moment, end.#moment, unit, inclusivity);
|
||||
}
|
||||
|
||||
addOnClone(amount: number, unit: moment.unitOfTime.DurationConstructor){
|
||||
return new Day(this.#moment.clone().add(amount, unit));
|
||||
}
|
||||
|
|
|
|||
24
test/entities/execute-routine-sync.test.ts
Normal file
24
test/entities/execute-routine-sync.test.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import { Routine } from "entities/routine";
|
||||
import { moment } from "obsidian";
|
||||
import { DAYS_OF_WEEK } from "shared/day";
|
||||
import { plugin } from "shared/plugin-service-locator";
|
||||
|
||||
|
||||
|
||||
describe('executeRoutineSync', () => {
|
||||
const routine: Routine = {
|
||||
name: "test routine 1",
|
||||
properties: {
|
||||
order: 10,
|
||||
activeCriteria: "week",
|
||||
daysOfWeek: DAYS_OF_WEEK,
|
||||
daysOfMonth: [],
|
||||
}
|
||||
}
|
||||
|
||||
test('should execute a routine synchronously', () => {
|
||||
console.log(moment().format("YYYY-MM-DD"));
|
||||
expect(routine.name).toBe("test routine 1");
|
||||
});
|
||||
|
||||
});
|
||||
Loading…
Reference in a new issue