11import TestLinterPlugin , { IntegrationTestCase } from './main.test' ;
2- import { Editor } from 'obsidian' ;
2+ import { Editor , TFile } from 'obsidian' ;
3+ import moment from 'moment' ;
34
45function addBlankLineAfterSetup ( plugin : TestLinterPlugin , _ : Editor ) : Promise < void > {
56 plugin . plugin . settings . ruleConfigs [ 'add-blank-line-after-yaml' ] = {
@@ -9,6 +10,53 @@ function addBlankLineAfterSetup(plugin: TestLinterPlugin, _: Editor): Promise<vo
910 return ;
1011}
1112
13+ function addBlankLineAfterYAMLConflictWithYAMLTimestampInsert ( plugin : TestLinterPlugin ) : Promise < void > {
14+ plugin . plugin . settings . ruleConfigs [ 'add-blank-line-after-yaml' ] = {
15+ 'enabled' : true ,
16+ } ;
17+ plugin . plugin . settings . ruleConfigs [ 'yaml-timestamp' ] = {
18+ 'enabled' : true ,
19+ 'date-created' : true ,
20+ 'date-created-key' : 'created' ,
21+ 'date-created-source-of-truth' : 'file system' ,
22+ 'date-modified' : true ,
23+ 'date-modified-key' : 'last_modified' ,
24+ 'format' : 'YYYY-MM-DD' ,
25+ } ;
26+
27+ return ;
28+ }
29+
30+ function addBlankLineAfterYAMLConflictWithYAMLTimestampInsertExpectedTextModifications ( text : string , file : TFile ) :string {
31+ text = text . replace ( '{{created_date}}' , moment ( file . stat . ctime ?? '' ) . format ( 'YYYY-MM-DD' ) ) ;
32+ text = text . replace ( '{{modified_date}}' , moment ( ) . format ( 'YYYY-MM-DD' ) ) ;
33+
34+ return text ;
35+ }
36+
37+ function addBlankLineAfterYAMLConflictWithYAMLTimestampUpdate ( plugin : TestLinterPlugin ) : Promise < void > {
38+ plugin . plugin . settings . ruleConfigs [ 'add-blank-line-after-yaml' ] = {
39+ 'enabled' : true ,
40+ } ;
41+ plugin . plugin . settings . ruleConfigs [ 'yaml-timestamp' ] = {
42+ 'enabled' : true ,
43+ 'date-created' : false ,
44+ 'date-modified' : true ,
45+ 'date-modified-key' : 'last_modified' ,
46+ 'date-modified-source-of-truth' : 'user or Linter edits' ,
47+ 'format' : 'YYYY-MM-DD' ,
48+ } ;
49+
50+ return ;
51+ }
52+
53+ function addBlankLineAfterYAMLConflictWithYAMLTimestampUpdateExpectedTextModifications ( text : string ) :string {
54+ text = text . replace ( '{{modified_date}}' , moment ( ) . format ( 'YYYY-MM-DD' ) ) ;
55+
56+ return text ;
57+ }
58+
59+
1260export const obsidianYAMLRuleTestCases : IntegrationTestCase [ ] = [
1361 {
1462 name : 'Updating a file with no yaml for adding blank lines after yaml should do nothing' ,
@@ -20,4 +68,16 @@ export const obsidianYAMLRuleTestCases: IntegrationTestCase[] = [
2068 filePath : 'yaml-rules/add-blank-line-after-yaml/yaml.md' ,
2169 setup : addBlankLineAfterSetup ,
2270 } ,
71+ {
72+ name : 'Updating a file with no yaml where YAML Timestamp Adds a Date Created, should properly update the YAML with a blank line after the frontmatter' ,
73+ filePath : 'yaml-rules/add-blank-line-after-yaml/no-yaml-timestamp-addition.md' ,
74+ setup : addBlankLineAfterYAMLConflictWithYAMLTimestampInsert ,
75+ modifyExpected : addBlankLineAfterYAMLConflictWithYAMLTimestampInsertExpectedTextModifications ,
76+ } ,
77+ {
78+ name : 'Updating a file with yaml where YAML Timestamp will only be updated if a change is made to the file, should properly add the missing blank line and update the date modified timestamp' ,
79+ filePath : 'yaml-rules/add-blank-line-after-yaml/yaml-timestamp-update.md' ,
80+ setup : addBlankLineAfterYAMLConflictWithYAMLTimestampUpdate ,
81+ modifyExpected : addBlankLineAfterYAMLConflictWithYAMLTimestampUpdateExpectedTextModifications ,
82+ } ,
2383] ;
0 commit comments