@@ -3,7 +3,7 @@ import { describe, it } from 'mocha'
33import xpath from 'xpath'
44import { DOMParser as xmldom } from '@xmldom/xmldom'
55
6- import { removeBadNameUsageAttrs , unwrapSimpleElement , fixTitleAttributes , unwrapDateCreated , unwrapDateOther , renameElement , removeElement , removeEmptyElements , removeAttribute , convertAuthorityElement , moveClassificationToSubject , wrapElement , wrapTextWithChild , moveAndRenameElement , convertNamePartDate , convertSubNameWrapper , wrapCopyInformation , convertSpeakerReleaseDetail , toStrictMODS } from './strict-mods.js'
6+ import { removeBadNameUsageAttrs , unwrapSimpleElement , fixTitleAttributes , unwrapDateCreated , unwrapDateOther , renameElement , removeElement , removeEmptyElements , removeAttribute , convertAuthorityElement , moveClassificationToSubject , wrapElement , wrapTextWithChild , moveAndRenameElement , convertNamePartDate , convertSubNameWrapper , wrapCopyInformation , wrapLocationTextContent , convertSpeakerReleaseDetail , toStrictMODS } from './strict-mods.js'
77
88// Test fixtures
99const fixtures = {
@@ -2090,6 +2090,134 @@ describe('Strict MODS Conversion', () => {
20902090 } )
20912091 } )
20922092
2093+ describe ( 'wrapLocationTextContent' , ( ) => {
2094+ const locationTextFixtures = {
2095+ urlInRelatedItem : {
2096+ input : `<xml><mods>
2097+ <relatedItem type="isReferencedBy">
2098+ <titleInfo><title>Related Resource</title></titleInfo>
2099+ <location>https://vault.cca.edu/items/9d019022-72ce-4774-9e2a-0c315c14f1d1/1/</location>
2100+ </relatedItem>
2101+ </mods></xml>` ,
2102+ expected : `<xml><mods>
2103+ <relatedItem type="isReferencedBy">
2104+ <titleInfo><title>Related Resource</title></titleInfo>
2105+ <location><url>https://vault.cca.edu/items/9d019022-72ce-4774-9e2a-0c315c14f1d1/1/</url></location>
2106+ </relatedItem>
2107+ </mods></xml>`
2108+ } ,
2109+ physicalLocationInRelatedItem : {
2110+ input : `<xml><mods>
2111+ <relatedItem type="otherVersion">
2112+ <titleInfo><title>Publication</title></titleInfo>
2113+ <location>CCA/C Archives / Archives Publications / Catalogs:Reference Copies / 1971-1974</location>
2114+ </relatedItem>
2115+ </mods></xml>` ,
2116+ expected : `<xml><mods>
2117+ <relatedItem type="otherVersion">
2118+ <titleInfo><title>Publication</title></titleInfo>
2119+ <location><physicalLocation>CCA/C Archives / Archives Publications / Catalogs:Reference Copies / 1971-1974</physicalLocation></location>
2120+ </relatedItem>
2121+ </mods></xml>`
2122+ } ,
2123+ httpUrlInLocation : {
2124+ input : `<xml><mods>
2125+ <location>http://www.example.com/resource</location>
2126+ </mods></xml>` ,
2127+ expected : `<xml><mods>
2128+ <location><url>http://www.example.com/resource</url></location>
2129+ </mods></xml>`
2130+ } ,
2131+ wikipediaUrl : {
2132+ input : `<xml><mods>
2133+ <location>https://en.wikipedia.org/wiki/Wikipedia:Meetup/Oakland/ArtandFeminism_2015</location>
2134+ </mods></xml>` ,
2135+ expected : `<xml><mods>
2136+ <location><url>https://en.wikipedia.org/wiki/Wikipedia:Meetup/Oakland/ArtandFeminism_2015</url></location>
2137+ </mods></xml>`
2138+ } ,
2139+ alreadyWrapped : {
2140+ input : `<xml><mods>
2141+ <location>
2142+ <physicalLocation>Oakland Campus</physicalLocation>
2143+ </location>
2144+ </mods></xml>` ,
2145+ expected : `<xml><mods>
2146+ <location>
2147+ <physicalLocation>Oakland Campus</physicalLocation>
2148+ </location>
2149+ </mods></xml>`
2150+ } ,
2151+ emptyLocation : {
2152+ input : `<xml><mods>
2153+ <location></location>
2154+ </mods></xml>` ,
2155+ expected : `<xml><mods>
2156+ <location></location>
2157+ </mods></xml>`
2158+ } ,
2159+ whitespaceOnly : {
2160+ input : `<xml><mods>
2161+ <location> </location>
2162+ </mods></xml>` ,
2163+ expected : `<xml><mods>
2164+ <location> </location>
2165+ </mods></xml>`
2166+ }
2167+ }
2168+
2169+ it ( 'should wrap URL text content in <url> element' , ( ) => {
2170+ const result = normalizeXML ( toStrictMODS ( locationTextFixtures . urlInRelatedItem . input ) )
2171+ const expected = normalizeXML ( `<mods xmlns="http://www.loc.gov/mods/v3"><relatedItem type="isReferencedBy"><titleInfo><title>Related Resource</title></titleInfo><location><url>https://vault.cca.edu/items/9d019022-72ce-4774-9e2a-0c315c14f1d1/1/</url></location></relatedItem></mods>` )
2172+
2173+ assert . strictEqual ( result , expected )
2174+ } )
2175+
2176+ it ( 'should wrap physical location text content in <physicalLocation> element' , ( ) => {
2177+ const result = normalizeXML ( toStrictMODS ( locationTextFixtures . physicalLocationInRelatedItem . input ) )
2178+ const expected = normalizeXML ( `<mods xmlns="http://www.loc.gov/mods/v3"><relatedItem type="otherVersion"><titleInfo><title>Publication</title></titleInfo><location><physicalLocation>CCA/C Archives / Archives Publications / Catalogs:Reference Copies / 1971-1974</physicalLocation></location></relatedItem></mods>` )
2179+
2180+ assert . strictEqual ( result , expected )
2181+ } )
2182+
2183+ it ( 'should wrap HTTP URLs in <url> element' , ( ) => {
2184+ const result = normalizeXML ( toStrictMODS ( locationTextFixtures . httpUrlInLocation . input ) )
2185+ const expected = normalizeXML ( `<mods xmlns="http://www.loc.gov/mods/v3"><location><url>http://www.example.com/resource</url></location></mods>` )
2186+
2187+ assert . strictEqual ( result , expected )
2188+ } )
2189+
2190+ it ( 'should wrap Wikipedia URLs in <url> element' , ( ) => {
2191+ const result = normalizeXML ( toStrictMODS ( locationTextFixtures . wikipediaUrl . input ) )
2192+ const expected = normalizeXML ( `<mods xmlns="http://www.loc.gov/mods/v3"><location><url>https://en.wikipedia.org/wiki/Wikipedia:Meetup/Oakland/ArtandFeminism_2015</url></location></mods>` )
2193+
2194+ assert . strictEqual ( result , expected )
2195+ } )
2196+
2197+ it ( 'should not modify already wrapped location' , ( ) => {
2198+ const result = normalizeXML ( toStrictMODS ( locationTextFixtures . alreadyWrapped . input ) )
2199+ const expected = normalizeXML ( `<mods xmlns="http://www.loc.gov/mods/v3"><location><physicalLocation>Oakland Campus</physicalLocation></location></mods>` )
2200+
2201+ assert . strictEqual ( result , expected )
2202+ } )
2203+
2204+ it ( 'should not modify empty location' , ( ) => {
2205+ const result = normalizeXML ( toStrictMODS ( locationTextFixtures . emptyLocation . input ) )
2206+ // Empty elements are removed by removeEmptyElements()
2207+ const expected = normalizeXML ( `<xml/>` )
2208+
2209+ assert . strictEqual ( result , expected )
2210+ } )
2211+
2212+ it ( 'should not modify location with only whitespace' , ( ) => {
2213+ const result = normalizeXML ( toStrictMODS ( locationTextFixtures . whitespaceOnly . input ) )
2214+ // Empty elements are removed by removeEmptyElements()
2215+ const expected = normalizeXML ( `<xml/>` )
2216+
2217+ assert . strictEqual ( result , expected )
2218+ } )
2219+ } )
2220+
20932221 describe ( 'toStrictMODS' , ( ) => {
20942222 it ( 'should extract mods element and add namespace by default' , ( ) => {
20952223 const input = `<xml><mods>
0 commit comments