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,78 +8,86 @@ import fs from 'node-fs'
---------------------------------------------------------------------
**/
function LogActionRun(){
class notReadyFunctions {
static LogActionRun () {
// get file which contains logs
// add an entry
// persist log file
}
}
function ListActions(idOfAction){
static ListActions (idOfAction) {
// retrieve log of actions from file
}
function RevertAction(idOfAction){
}
static RevertAction (idOfAction) {
// select action and run all renames in the other way
}
function RevertMultipleActionsUntil(idOfAction){
}
static RevertMultipleActionsUntil (idOfAction) {
// select action and run all renames in the other way for each point in time
}
}
function TestDownloadedTelegramPictureRename (fileName) {
static findTemplateInFileName (fileName) {
// test all templates from configuration
}
static TestDownloadedTelegramPictureRename (fileName) {
let fileProperties = destructurateFileName(fileName)
}
}
function hasDifferentDateInNameThanExif (fileName) {
static hasDifferentDateInNameThanExif (fileName) {
let foundDate = finder.findFormattedDate(fileName)
if (foundDate && foundDate != getExifCreationDate(fileName)) {
return true
}
return false
}
}
function moveToArchive (targetDirectory, fileFullPath) {
static moveToArchive (targetDirectory, fileFullPath) {
// find current directory,
// rename file to move it
}
}
function getStatisticsOnArchiveFolder (fileFullPath) {
static getStatisticsOnArchiveFolder (fileFullPath) {
return {
foldersCount: 'TODO',
filesWithoutSemanticName: 'TODO'
}
}
}
/**
/**
* list all tags
* @param fileFullPath
* @returns {[]}
*/
function getControlledVocabularyFromFiles (fileFullPath) {
static getControlledVocabularyFromFiles (fileFullPath) {
// find all tags
let listOfTags = []
return listOfTags;
}
return listOfTags
}
function moveToSortingFolder (fileFullPath) {
static moveToSortingFolder (fileFullPath) {
return 'TODO'
}
}
/**
/**
* écrit un nouveau nom de fichier formatté
* @param convertedToName
* @param originalFileName
* @returns {*}
*/
function mixDateNameWithFileName (convertedToName, originalFileName) {
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
}
}
function TestMixingName () {
static TestMixingName () {
let fileMixedNewName = mixDateNameWithFileName(convertedToName, originalFileName)
console.log('new name', fileMixedNewName)
@ -88,27 +96,25 @@ function TestMixingName () {
console.log('renommage =>', fileMixedNewName)
// renameFile(originalFileName, fileMixedNewName)
}
}
}
/**
/**
* obtenir une liste des dossiers uniquement dans le dossier courant
* @param path
* @returns {*}
*/
function getDirectories (path) {
static getDirectories (path) {
return fs.readdirSync(path).filter(function (file) {
return fs.statSync(path + '/' + file).isDirectory()
})
}
}
)
}
function convertDateToTimeInFileName (inputDate) {
static convertDateToTimeInFileName (inputDate) {
return inputDate.replace(' ', 'T')
}
}
function testthings(){
static testthings () {
// let list = getDirectories(pathFolder)
// console.log('list', list)
@ -122,5 +128,8 @@ function testthings(){
convertedToName = convertDateToTimeInFileName(creationDateFound)
}
console.log('convertedToName', convertedToName)
}
}
export default notReadyFunctions