package com.njcn.gather.report.util;

import com.njcn.gather.tools.report.util.Docx4jUtil;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.openpackaging.parts.WordprocessingML.DocumentSettingsPart;
import org.docx4j.wml.CTSettings;
import org.junit.Test;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

public class Docx4jUtilUpdateFieldsTest {

    @Test
    public void enableUpdateFieldsOnOpenSetsWordSettingsFlag() throws Exception {
        WordprocessingMLPackage wordPackage = WordprocessingMLPackage.createPackage();

        Docx4jUtil.enableUpdateFieldsOnOpen(wordPackage);

        DocumentSettingsPart settingsPart = wordPackage.getMainDocumentPart().getDocumentSettingsPart();
        assertNotNull(settingsPart);
        CTSettings settings = settingsPart.getContents();
        assertNotNull(settings.getUpdateFields());
        assertTrue(settings.getUpdateFields().isVal());
    }
}
