rangement/tests/finder.test.js

143 lines
4.0 KiB
JavaScript
Raw Normal View History

import finder from '../utils/finder'
2023-07-19 12:32:13 +02:00
import { makeFileNameFromProperties } from '../old_index'
2023-07-18 23:28:48 +02:00
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', () => {
test('should append to file name in the right place', () => {
2023-07-19 11:11:43 +02:00
let fileNameOriginal = 'mon texte -- famille vacances plage.jpg'
let properties = finder.destructurateFileName(fileNameOriginal)
2023-07-05 23:11:46 +02:00
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-19 11:11:43 +02:00
2023-07-18 23:28:48 +02:00
test('should replace text in file name', () => {
2023-07-19 11:11:43 +02:00
let fileNameOriginal = 'mon texte -- famille vacances plage.jpg'
2023-07-18 23:28:48 +02:00
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-19 11:11:43 +02:00
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')
})
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-19 11:11:43 +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
)
2023-07-19 11:11:43 +02:00
.toStrictEqual(['carte', 'bidule'])
2023-07-05 23:11:46 +02:00
})
2023-07-18 23:28:48 +02:00
2023-07-19 11:11:43 +02:00
test('should add tag in file name', () => {
2023-07-18 23:28:48 +02:00
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
})
})