122 lines
3.5 KiB
JavaScript
122 lines
3.5 KiB
JavaScript
import finder from '../finder.mjs'
|
|
import { makeFileNameFromProperties } from '../index'
|
|
import { expect } from '@jest/globals'
|
|
|
|
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')
|
|
})
|
|
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')
|
|
})
|
|
|
|
})
|
|
|
|
describe('modifications with tags', () => {
|
|
|
|
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([])
|
|
|
|
})
|
|
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'])
|
|
|
|
})
|
|
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', () => {
|
|
|
|
})
|
|
}) |