Skip to content

Instantly share code, notes, and snippets.

@marceloandrader
Created September 10, 2019 17:14
Show Gist options
  • Save marceloandrader/d5c5e418cd6d4a1485df8c81c38951e9 to your computer and use it in GitHub Desktop.
Save marceloandrader/d5c5e418cd6d4a1485df8c81c38951e9 to your computer and use it in GitHub Desktop.
import docNameParsing from 'dummy/utils/doc-name-parsing'
import { module, test } from 'qunit'
import { A } from '@ember/array'
import Ember from 'ember'
module('Unit | Utility | doc name parsing')
function getDataNeeded (fileName) {
return {
fileName,
currentSubject: null,
subjects: A([
Ember.Object.create({ fullNameWithMiddle: 'Alvarez, Maria Eunice' }),
Ember.Object.create({ fullNameWithMiddle: 'Doe-Doe, John-Boy' })
]),
documentTypes: A([
Ember.Object.create({ display: 'BIRTH', value: 'BIRTH' }),
Ember.Object.create({ display: 'REPORT', value: 'REPORT' })
])
}
}
test('parse 3 sections doc name with incorrect separator', function (assert) {
let args = getDataNeeded('Alvarez, Maria Eunice-BIRTH-File about birth certificate.pdf')
let result = docNameParsing(
args.fileName,
args.currentSubject,
args.subjects,
args.documentTypes
)
assert.equal(null, result.subject)
assert.equal(null, result.subjectName)
assert.equal(null, result.docType)
assert.equal('Alvarez, Maria Eunice-BIRTH-File about birth certificate.pdf', result.fileName)
})
test('parse 3 sections doc name', function (assert) {
let args = getDataNeeded('Alvarez, Maria Eunice - BIRTH - File about birth certificate.pdf')
let result = docNameParsing(
args.fileName,
args.currentSubject,
args.subjects,
args.documentTypes
)
assert.equal(args.subjects[0], result.subject)
assert.equal('Alvarez, Maria Eunice', result.subjectName)
assert.equal('BIRTH', result.docType)
assert.equal('File about birth certificate.pdf', result.fileName)
})
test('parse 3 sections doc name with internal dashes', function (assert) {
let args = getDataNeeded('Doe-Doe, John-Boy - REPORT - SampleReport-2019-04-03--085-Sample-Images.pdf')
let result = docNameParsing(
args.fileName,
args.currentSubject,
args.subjects,
args.documentTypes
)
assert.equal(args.subjects[1], result.subject)
assert.equal('Doe-Doe, John-Boy', result.subjectName)
assert.equal('REPORT', result.docType)
assert.equal('SampleReport-2019-04-03--085-Sample-Images.pdf', result.fileName)
})
test('parse doc name with tab', function (assert) {
let args = getDataNeeded('TAB 9 - Doe-Doe, John-Boy - REPORT - SampleReport-2019-04-03--085-Sample-Images.pdf')
let result = docNameParsing(
args.fileName,
args.currentSubject,
args.subjects,
args.documentTypes
)
assert.equal('9', result.tabNumber)
assert.equal(args.subjects[1], result.subject)
assert.equal('Doe-Doe, John-Boy', result.subjectName)
assert.equal('REPORT', result.docType)
assert.equal('SampleReport-2019-04-03--085-Sample-Images.pdf', result.fileName)
})
test('parse doc name with relationship in parenthesis', function (assert) {
let args = getDataNeeded('Doe-Doe, John-Boy (Spouse) - REPORT - SampleReport-2019-04-03--085-Sample-Images.pdf')
let result = docNameParsing(
args.fileName,
args.currentSubject,
args.subjects,
args.documentTypes
)
assert.equal(args.subjects[1], result.subject)
assert.equal('Doe-Doe, John-Boy', result.subjectName)
assert.equal('REPORT', result.docType)
assert.equal('SampleReport-2019-04-03--085-Sample-Images.pdf', result.fileName)
})
test('parse doc name with unrecognized doc type', function (assert) {
let args = getDataNeeded('Doe-Doe, John-Boy - NONREPORT - SampleReport-2019-04-03--085-Sample-Images.pdf')
let result = docNameParsing(
args.fileName,
args.currentSubject,
args.subjects,
args.documentTypes
)
assert.equal(args.subjects[1], result.subject)
assert.equal('Doe-Doe, John-Boy', result.subjectName)
assert.equal(undefined, result.docType)
assert.equal('NONREPORT - SampleReport-2019-04-03--085-Sample-Images.pdf', result.fileName)
})
test('parse doc name with unrecognized subject name', function (assert) {
let args = getDataNeeded('Andrade, Marcelo - REPORT - SampleReport-2019-04-03--085-Sample-Images.pdf')
let result = docNameParsing(
args.fileName,
args.currentSubject,
args.subjects,
args.documentTypes
)
assert.equal(null, result.subject)
assert.equal(null, result.subjectName)
assert.equal('REPORT', result.docType)
assert.equal('Andrade, Marcelo - SampleReport-2019-04-03--085-Sample-Images.pdf', result.fileName)
})
test('parse doc name with a set currentSubject', function (assert) {
let args = getDataNeeded('Alvarez, Maria Eunice - REPORT - SampleReport-2019-04-03--085-Sample-Images.pdf')
let result = docNameParsing(
args.fileName,
args.subjects[0],
args.subjects,
args.documentTypes
)
assert.equal(args.subjects[0], result.subject)
assert.equal('Alvarez, Maria Eunice', result.subjectName)
assert.equal('REPORT', result.docType)
assert.equal('SampleReport-2019-04-03--085-Sample-Images.pdf', result.fileName)
})
test('parse 3 sections doc name with incomplete doc type', function (assert) {
let args = getDataNeeded('Alvarez, Maria Eunice - BIR - File about birth certificate.pdf')
let result = docNameParsing(
args.fileName,
args.currentSubject,
args.subjects,
args.documentTypes
)
assert.equal(args.subjects[0], result.subject)
assert.equal('Alvarez, Maria Eunice', result.subjectName)
assert.equal('BIRTH', result.docType)
assert.equal('File about birth certificate.pdf', result.fileName)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment