<commit_before>import {NewDocument} from 'idai-components-2';
import {DuplicationUtil} from '../../../../app/components/docedit/duplication-util';


/**
 * @author <NAME>
 */

describe('DuplicationUtil', () => {

    let validator;
    let identifiers = [];


    beforeAll(() => {

        validator = jasmine.createSpyObj('validator', ['assertIdentifierIsUnique']);
        validator.assertIdentifierIsUnique.and.callFake(async (document: NewDocument) => {
            if (identifiers.includes(document.resource.identifier)) throw 'duplicate identifier';
        });
    });
<commit_msg>add unit test for creating template<commit_after>import {NewDocument, Document} from 'idai-components-2';
import {DuplicationUtil} from '../../../../app/components/docedit/duplication-util';


/**
 * @author <NAME>
 */

describe('DuplicationUtil', () => {

    let validator;
    let identifiers = [];


    beforeAll(() => {

        validator = jasmine.createSpyObj('validator', ['assertIdentifierIsUnique']);
        validator.assertIdentifierIsUnique.and.callFake(async (document: NewDocument) => {
            if (identifiers.includes(document.resource.identifier)) throw 'duplicate identifier';
        });
    });


    it('do not include non-hierarchy relations, id and geometry in template', () => {

        const document: Document = {
            resource: {
                id: 't1',
                identifier: 'test1',
                relations: {
                    isRecordedIn: ['t2'],
                    liesWithin: ['t3'],
                    borders: ['t4']
                },
                geometry: {
                    type: 'Point',
                    coordinates: [1.0, 1.0]
                },
                type: 'Find'
            },
            created: {
                user: 'testuser',
                date: new Date()
            },
            modified: []
        };

        const template: NewDocument = DuplicationUtil.createTemplate(document);

        expect(template.resource.id).toBeUndefined();
        expect(template.resource.relations.isRecordedIn).toEqual(['t2']);
        expect(template.resource.relations.liesWithin).toEqual(['t3']);
        expect(template.resource.relations.borders).toBeUndefined();
        expect(template.resource.geometry).toBeUndefined();
    });

{'fraction_non_alphanumeric': 0.14532125916343253, 'fraction_numerical': 0.00560586459680897, 'mean_word_length': 2.152173913043478, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5708641', 'n_tokens_mistral': 628, 'n_tokens_neox': 593, 'n_words': 109}