<commit_before><commit_msg>teste básico para o view by block<commit_after>/*
 * Copyright (C) 2016 Singular Studios (a.k.a Atom Tecnologia) - www.opensingular.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.opensingular.form.wicket.mapper;

import org.junit.Test;
import org.opensingular.form.SIComposite;
import org.opensingular.form.STypeComposite;
import org.opensingular.form.type.core.STypeInteger;
import org.opensingular.form.type.core.STypeString;
import org.opensingular.form.view.SViewByBlock;
import org.opensingular.form.view.SViewTab;
import org.opensingular.form.wicket.enums.AnnotationMode;
import org.opensingular.form.wicket.helpers.SingularDummyFormPageTester;

import java.util.function.Consumer;

/**
 * Teste apenas renderização sem exception, devem ser criados outros cenários de teste
 * @author <NAME> on 10/04/2017.
 *
 */
public class BlocksCompositeMapperTest {

    private static void createSimpleForm(STypeComposite<SIComposite> testForm) {

        STypeString  nome  = testForm.addFieldString("nome");
        STypeInteger idade = testForm.addFieldInteger("idade");

        STypeComposite<SIComposite> experiencia = testForm.addFieldComposite("experiencia");
        STypeString                 empresa     = experiencia.addFieldString("empresa", true);
        STypeString                 cargo       = experiencia.addFieldString("cargo", true);
        experiencia.asAtr().label("Experiencias");
        experiencia.asAtrAnnotation().setAnnotated();


        SViewTab tabbed = new SViewTab();
        tabbed.addTab("informacoes", "Informações pessoais")
                .add(nome)
                .add(idade);
        tabbed.addTab(experiencia);
        testForm.withView(tabbed);

        testForm.withView(new SViewByBlock(), vbb -> {
            vbb.newBlock("Empres ")
                    .add(empresa)
                    .newBlock("Dados Cargo")
                    .add(nome)
                    .add(cargo);
        });
    }

    @Test
    public void test_Edit() {
        testBlocksCompositeMapper(ctx -> ctx.getDummyPage().setAsEditView());
    }

    @Test
    public void test_Edit_Annotation() {
        testBlocksCompositeMapper(ctx -> {
            ctx.getDummyPage().setAsEditView();
            ctx.getDummyPage().getSingularFormPanel().setAnnotationMode(AnnotationMode.EDIT);
        });
        testBlocksCompositeMapper(ctx -> ctx.getDummyPage().setAsEditView());
    }

    @Test
    public void test_ReadOnly() {
        testBlocksCompositeMapper(ctx -> ctx.getDummyPage().setAsVisualizationView());
    }

    @Test
    public void test_ReadOnly_Annotation() {
        testBlocksCompositeMapper(ctx -> {
            ctx.getDummyPage().setAsVisualizationView();
            ctx.getDummyPage().getSingularFormPanel().setAnnotationMode(AnnotationMode.EDIT);
        });
    }

    public void testBlocksCompositeMapper(Consumer<SingularDummyFormPageTester> config) {
        SingularDummyFormPageTester ctx = new SingularDummyFormPageTester();
        ctx.getDummyPage().setTypeBuilder(BlocksCompositeMapperTest::createSimpleForm);
        config.accept(ctx);
        ctx.startDummyPage();
    }
}

{'fraction_non_alphanumeric': 0.10206297502714441, 'fraction_numerical': 0.004343105320304018, 'mean_word_length': 3.121923937360179, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5048514', 'n_tokens_mistral': 1086, 'n_tokens_neox': 1060, 'n_words': 218}