2023-07-05 23:11:46 +02:00
|
|
|
import finder from '../finder.mjs'
|
2023-07-18 23:28:48 +02:00
|
|
|
import { makeFileNameFromProperties } from '../index'
|
|
|
|
import { expect } from '@jest/globals'
|
2023-07-05 23:11:46 +02:00
|
|
|
|
|
|
|
describe('detection in file name', () => {
|
|
|
|
|
|
|
|
test('detects date in file name', () => {
|
|
|
|
expect(finder
|
|
|
|
.findFormattedDate('2023-06-23T18.36.47 -- machin bidule.jpg')
|
|
|
|
)
|
|
|
|
.toBe('2023-06-23T18.36.47')
|
|
|
|
})
|
|
|
|
test('detects jpg file extension in file name', () => {
|
|
|
|
expect(finder
|
|
|
|
.findFileExtension('2023-06-23T18.36.47 -- machin bidule.jpg')
|
|
|
|
)
|
|
|
|
.toBe('.jpg')
|
|
|
|
})
|
|
|
|
test('detects JPG file extension in file name', () => {
|
|
|
|
expect(finder
|
|
|
|
.findFileExtension('2023-06-23T18.36.47 -- machin bidule.JPG')
|
|
|
|
)
|
|
|
|
.toBe('.JPG')
|
|
|
|
})
|
|
|
|
test('detects correct free text part in file name with a formatted date', () => {
|
|
|
|
expect(finder
|
|
|
|
.findFileNameFreeTextPart('2023-06-23T18.36.47 mon texte libre -- machin bidule.JPG')
|
|
|
|
)
|
|
|
|
.toBe('mon texte libre')
|
|
|
|
})
|
|
|
|
test('detects correct free text part in file name', () => {
|
|
|
|
expect(finder
|
|
|
|
.findFileNameFreeTextPart('mon texte libre autre.jpg')
|
|
|
|
)
|
|
|
|
.toBe('mon texte libre autre')
|
|
|
|
})
|
|
|
|
test('detects correct correct array of tags in file name', () => {
|
|
|
|
expect(finder
|
|
|
|
.findTagSectionInString('mon texte libre autre - somewhere -- famille vacances plage.jpg')
|
|
|
|
)
|
|
|
|
.toStrictEqual(['famille', 'vacances', 'plage'])
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
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 modifiedProperties = finder.appendFileName(properties, 'ajouté à la fin du texte libre')
|
|
|
|
expect(
|
|
|
|
modifiedProperties.freeText
|
|
|
|
)
|
|
|
|
.toBe('mon texte ajouté à la fin du texte libre')
|
|
|
|
})
|
2023-07-18 23:28:48 +02:00
|
|
|
test('should replace text in file name', () => {
|
|
|
|
let searchString = 'vacances', replaceString = 'machin'
|
|
|
|
let replacedString = finder.searchAndReplaceInFileName(searchString, replaceString, fileNameOriginal)
|
|
|
|
expect(
|
|
|
|
replacedString
|
|
|
|
)
|
|
|
|
.toBe('mon texte -- famille machin plage.jpg')
|
2023-07-05 23:11:46 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
2023-07-18 23:28:48 +02:00
|
|
|
describe('modifications with tags', () => {
|
2023-07-05 23:11:46 +02:00
|
|
|
|
2023-07-18 23:28:48 +02:00
|
|
|
let fileNameOriginal = 'mon nom sans aucun tag.jpg'
|
|
|
|
let properties = finder.destructurateFileName(fileNameOriginal)
|
|
|
|
|
|
|
|
test('should have no tag in file properties', () => {
|
|
|
|
expect(
|
|
|
|
properties.tags
|
|
|
|
)
|
|
|
|
.toStrictEqual([])
|
2023-07-05 23:11:46 +02:00
|
|
|
|
|
|
|
})
|
2023-07-18 23:28:48 +02:00
|
|
|
test('should list existing tags in file name', () => {
|
|
|
|
let fileNameOriginal = 'mon nom -- carte bidule.jpg'
|
|
|
|
let otherProperties = finder.destructurateFileName(fileNameOriginal)
|
|
|
|
|
|
|
|
expect(
|
|
|
|
otherProperties.tags
|
|
|
|
)
|
|
|
|
.toStrictEqual(['carte','bidule'])
|
2023-07-05 23:11:46 +02:00
|
|
|
|
|
|
|
})
|
2023-07-18 23:28:48 +02:00
|
|
|
test('should add tag in file name', () => {
|
|
|
|
|
|
|
|
let newTag = 'illustration'
|
|
|
|
let newName = finder.addTagInFileName(newTag, fileNameOriginal)
|
|
|
|
|
|
|
|
expect(newName)
|
|
|
|
.toBe('mon nom sans aucun tag -- illustration.jpg')
|
|
|
|
|
|
|
|
let otherProperties = finder.destructurateFileName(newName)
|
|
|
|
expect(
|
|
|
|
otherProperties.tags
|
|
|
|
)
|
|
|
|
.toStrictEqual(['illustration'])
|
|
|
|
|
|
|
|
expect(
|
|
|
|
makeFileNameFromProperties(otherProperties)
|
|
|
|
)
|
|
|
|
.toBe('mon nom sans aucun tag -- illustration.jpg')
|
|
|
|
})
|
|
|
|
test('should remove tag in file name', () => {
|
|
|
|
|
|
|
|
let fileNameOriginal = 'mon nom avec un tag -- voyages.jpg'
|
|
|
|
// let properties = finder.destructurateFileName(fileNameOriginal)
|
|
|
|
// expect(properties.tags).toStrictEqual(['voyages'])
|
|
|
|
|
|
|
|
let newProperties = finder.removeTagInProperties(properties, 'voyages')
|
|
|
|
expect(newProperties.tags).toStrictEqual([])
|
|
|
|
})
|
|
|
|
|
|
|
|
xtest('should remove with minus prefix and add tags in file name at the same time', () => {
|
2023-07-05 23:11:46 +02:00
|
|
|
|
|
|
|
})
|
|
|
|
})
|