more tests

This commit is contained in:
Tykayn 2023-07-19 11:11:43 +02:00 committed by tykayn
parent 217d9de761
commit d9cbbb9076
5 changed files with 148 additions and 120 deletions

12
babel.config.cjs Normal file
View File

@ -0,0 +1,12 @@
const presets = [
[
"@babel/preset-env",
{
targets: {
node: 'current'
}
}
]
];
module.exports = { presets };

View File

@ -1,7 +0,0 @@
const presets = [
[
"@babel/preset-env",
]
];
module.exports = { presets };

View File

@ -44,24 +44,20 @@ describe('detection in file name', () => {
describe('modification in file name', () => {
let fileNameOriginal = 'mon texte -- famille vacances plage.jpg'
let properties = finder.destructurateFileName(fileNameOriginal)
test('should append to file name in the right place', () => {
let fileNameOriginal = 'mon texte -- famille vacances plage.jpg'
let properties = finder.destructurateFileName(fileNameOriginal)
let modifiedProperties = finder.appendFileName(properties, 'ajouté à la fin du texte libre')
expect(
modifiedProperties.freeText
)
.toBe('mon texte ajouté à la fin du texte libre')
})
test('should prepend to file name in the right place', () => {
let modifiedProperties = finder.prependFileName(properties, 'ajouté au début du texte libre ')
expect(
modifiedProperties.freeText
)
.toBe('ajouté au début du texte libre mon texte')
})
test('should replace text in file name', () => {
let fileNameOriginal = 'mon texte -- famille vacances plage.jpg'
let searchString = 'vacances', replaceString = 'machin'
let replacedString = finder.searchAndReplaceInFileName(searchString, replaceString, fileNameOriginal)
expect(
@ -70,6 +66,25 @@ describe('modification in file name', () => {
.toBe('mon texte -- famille machin plage.jpg')
})
test('should prepend to file name in the right place', () => {
let fileNameOriginal = 'mon texte.jpg'
let properties = finder.destructurateFileName(fileNameOriginal)
let modifiedProperties = finder.prependFileName(properties, 'au début')
expect(
modifiedProperties.freeText
)
.toBe('au début mon texte')
})
test('should clean spaces', () => {
let fileNameOriginal = ' mon texte - - -- bidule un truc '
expect(
finder.cleanSpaces(fileNameOriginal)
)
.toBe('mon texte - - -- bidule un truc')
})
})
describe('modifications with tags', () => {
@ -84,6 +99,7 @@ describe('modifications with tags', () => {
.toStrictEqual([])
})
test('should list existing tags in file name', () => {
let fileNameOriginal = 'mon nom -- carte bidule.jpg'
let otherProperties = finder.destructurateFileName(fileNameOriginal)
@ -91,11 +107,11 @@ describe('modifications with tags', () => {
expect(
otherProperties.tags
)
.toStrictEqual(['carte','bidule'])
.toStrictEqual(['carte', 'bidule'])
})
test('should add tag in file name', () => {
test('should add tag in file name', () => {
let newTag = 'illustration'
let newName = finder.addTagInFileName(newTag, fileNameOriginal)

View File

@ -114,7 +114,7 @@ export default class finder {
}
static cleanSpaces (inputString) {
return inputString.trim().replace(/ *g/, ' ')
return inputString.trim().replace(/ *g/, ' ').replace(/ /, ' ')
}
static searchAndReplaceInFileName (searchString, replaceString, fileName) {
@ -269,9 +269,7 @@ export default class finder {
}
}
static findTemplateInFileName (fileName) {
// test all templates from configuration
}
static appendFileName (fileProperties, newText) {
fileProperties.freeText = finder.cleanSpaces(fileProperties.freeText + ' ' + newText)

View File

@ -8,119 +8,128 @@ import fs from 'node-fs'
---------------------------------------------------------------------
**/
function LogActionRun(){
// get file which contains logs
// add an entry
// persist log file
}
class notReadyFunctions {
function ListActions(idOfAction){
// retrieve log of actions from file
}
function RevertAction(idOfAction){
// select action and run all renames in the other way
}
function RevertMultipleActionsUntil(idOfAction){
// select action and run all renames in the other way for each point in time
}
function TestDownloadedTelegramPictureRename (fileName) {
let fileProperties = destructurateFileName(fileName)
}
function hasDifferentDateInNameThanExif (fileName) {
let foundDate = finder.findFormattedDate(fileName)
if (foundDate && foundDate != getExifCreationDate(fileName)) {
return true
static LogActionRun () {
// get file which contains logs
// add an entry
// persist log file
}
return false
}
function moveToArchive (targetDirectory, fileFullPath) {
// find current directory,
// rename file to move it
}
function getStatisticsOnArchiveFolder (fileFullPath) {
return {
foldersCount: 'TODO',
filesWithoutSemanticName: 'TODO'
static ListActions (idOfAction) {
// retrieve log of actions from file
}
}
/**
* list all tags
* @param fileFullPath
* @returns {[]}
*/
function getControlledVocabularyFromFiles (fileFullPath) {
// find all tags
let listOfTags = []
return listOfTags;
}
function moveToSortingFolder (fileFullPath) {
return 'TODO'
}
/**
* écrit un nouveau nom de fichier formatté
* @param convertedToName
* @param originalFileName
* @returns {*}
*/
function mixDateNameWithFileName (convertedToName, originalFileName) {
// enlever l'ancien timestamp si il existe
// ajouter en début de nom le nouveau timestamp avec un espace et conserver le reste du nom
return originalFileName
}
function TestMixingName () {
let fileMixedNewName = mixDateNameWithFileName(convertedToName, originalFileName)
console.log('new name', fileMixedNewName)
if (fileMixedNewName !== originalFileName) {
console.log('renommage =>', fileMixedNewName)
// renameFile(originalFileName, fileMixedNewName)
static RevertAction (idOfAction) {
// select action and run all renames in the other way
}
}
static RevertMultipleActionsUntil (idOfAction) {
// select action and run all renames in the other way for each point in time
}
static findTemplateInFileName (fileName) {
// test all templates from configuration
}
/**
* obtenir une liste des dossiers uniquement dans le dossier courant
* @param path
* @returns {*}
*/
function getDirectories (path) {
return fs.readdirSync(path).filter(function (file) {
return fs.statSync(path + '/' + file).isDirectory()
})
}
static TestDownloadedTelegramPictureRename (fileName) {
let fileProperties = destructurateFileName(fileName)
}
static hasDifferentDateInNameThanExif (fileName) {
let foundDate = finder.findFormattedDate(fileName)
function convertDateToTimeInFileName (inputDate) {
return inputDate.replace(' ', 'T')
}
if (foundDate && foundDate != getExifCreationDate(fileName)) {
return true
}
return false
}
function testthings(){
// let list = getDirectories(pathFolder)
static moveToArchive (targetDirectory, fileFullPath) {
// find current directory,
// rename file to move it
}
static getStatisticsOnArchiveFolder (fileFullPath) {
return {
foldersCount: 'TODO',
filesWithoutSemanticName: 'TODO'
}
}
/**
* list all tags
* @param fileFullPath
* @returns {[]}
*/
static getControlledVocabularyFromFiles (fileFullPath) {
// find all tags
let listOfTags = []
return listOfTags
}
static moveToSortingFolder (fileFullPath) {
return 'TODO'
}
/**
* écrit un nouveau nom de fichier formatté
* @param convertedToName
* @param originalFileName
* @returns {*}
*/
static mixDateNameWithFileName (convertedToName, originalFileName) {
// enlever l'ancien timestamp si il existe
// ajouter en début de nom le nouveau timestamp avec un espace et conserver le reste du nom
return originalFileName
}
static TestMixingName () {
let fileMixedNewName = mixDateNameWithFileName(convertedToName, originalFileName)
console.log('new name', fileMixedNewName)
if (fileMixedNewName !== originalFileName) {
console.log('renommage =>', fileMixedNewName)
// renameFile(originalFileName, fileMixedNewName)
}
}
/**
* obtenir une liste des dossiers uniquement dans le dossier courant
* @param path
* @returns {*}
*/
static getDirectories (path) {
return fs.readdirSync(path).filter(function (file) {
return fs.statSync(path + '/' + file).isDirectory()
}
)
}
static convertDateToTimeInFileName (inputDate) {
return inputDate.replace(' ', 'T')
}
static testthings () {
// let list = getDirectories(pathFolder)
// console.log('list', list)
let originalFileName = '2015-04-30T09.09.02 -- scan papier.jpg'
let formattedDatePIMBefore = finder.findFormattedDate(originalFileName)
console.log('formattedDatePIMBefore', formattedDatePIMBefore)
let originalFileName = '2015-04-30T09.09.02 -- scan papier.jpg'
let formattedDatePIMBefore = finder.findFormattedDate(originalFileName)
console.log('formattedDatePIMBefore', formattedDatePIMBefore)
let creationDateFound = finder.getExifCreationDate(pathFolder + '/' + originalFileName)
let convertedToName = ''
if (creationDateFound) {
convertedToName = convertDateToTimeInFileName(creationDateFound)
let creationDateFound = finder.getExifCreationDate(pathFolder + '/' + originalFileName)
let convertedToName = ''
if (creationDateFound) {
convertedToName = convertDateToTimeInFileName(creationDateFound)
}
console.log('convertedToName', convertedToName)
}
console.log('convertedToName', convertedToName)
}
export default notReadyFunctions