/* * Copyright 2026 Kingsrook, LLC * * 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 com.kingsrook.qbits.cms; import java.util.EnumSet; import java.util.List; import com.kingsrook.qqq.backend.core.model.metadata.QInstance; import com.kingsrook.qqq.backend.core.model.metadata.help.bundles.HelpBundles; import com.kingsrook.qqq.backend.core.testing.HelpBundleAssertions; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; /******************************************************************************* ** The qbit ships its own help (help/qbit-cms.yaml): a host gets it with the ** jar and writes none of it. It covers every app, table, field, home, child ** list and value list of the qbit, names nothing that does not exist, and is ** registered only under the default names it is written for. *******************************************************************************/ class CmsHelpTest { /******************************************************************************* ** With every feature: registered once as a QBIT layer bundle of this version, ** complete by the core's own gate, and every home, child list and value list ** has its text. *******************************************************************************/ @Test void testHelpCoversTheQBit() throws Exception { QInstance qInstance = CmsTestSupport.blankInstance(CmsTestSupport.h2Backend()); new CmsQBitProducer().withQBitConfig(new CmsQBitConfig().withBackendName(CmsTestSupport.BACKEND).withStartupMode(CmsStartupMode.SKIP)).produce(qInstance); assertThat(HelpBundles.of(qInstance).getBundles()).singleElement().satisfies(bundle -> { assertThat(bundle.getId()).isEqualTo("qbit-cms"); assertThat(bundle.getVersion()).isEqualTo(CmsQBitProducer.VERSION); assertThat(bundle.getLayer().name()).isEqualTo("QBIT"); }); HelpBundleAssertions.forInstance(qInstance) .bundles(CmsQBitProducer.HELP_BUNDLE) .owning(target -> target.name().equals("cms") || target.name().startsWith("cms")) .assertComplete(); var entries = HelpBundles.of(qInstance).resolveWinningEntries(); List widgets = qInstance.getWidgets().keySet().stream().filter(name -> name.startsWith("cms")).sorted().toList(); assertThat(widgets).hasSizeGreaterThan(30); for(String name : widgets) { assertThat(entries).as("the card " + name).containsKey(new HelpBundles.EntryKey("widget:" + name + ";slot:label", "ALL_SCREENS")); } List sources = qInstance.getPossibleValueSources().keySet().stream().filter(name -> name.startsWith("cms_")).sorted().toList(); assertThat(sources).hasSize(36); for(String name : sources) { assertThat(entries).as("the value source " + name).containsKey(new HelpBundles.EntryKey("possibleValueSource:" + name + ";slot:help", "ALL_SCREENS")); } } /******************************************************************************* ** Every section of every table has its text too (the core's gate leaves ** sections optional). *******************************************************************************/ @Test void testEverySectionHasHelp() throws Exception { QInstance qInstance = CmsTestSupport.blankInstance(CmsTestSupport.h2Backend()); new CmsQBitProducer().withQBitConfig(new CmsQBitConfig().withBackendName(CmsTestSupport.BACKEND).withStartupMode(CmsStartupMode.SKIP)).produce(qInstance); var entries = HelpBundles.of(qInstance).resolveWinningEntries(); int sections = 0; for(var table : qInstance.getTables().values()) { if(!table.getName().startsWith("cms_")) { continue; } for(var section : table.getSections()) { sections++; assertThat(entries).as(table.getName() + " section " + section.getName()) .containsKey(new HelpBundles.EntryKey("table:" + table.getName() + ";section:" + section.getName(), "ALL_SCREENS")); } } assertThat(sections).isGreaterThan(100); } /******************************************************************************* ** The text is written for the default names: an install under other ** prefixes does not register it, and with a feature off the entries of its ** tables are simply unused (the gate still passes for what is there). *******************************************************************************/ @Test void testOtherNamesAndFeatureSubsets() throws Exception { QInstance renamed = CmsTestSupport.blankInstance(CmsTestSupport.h2Backend()); new CmsQBitProducer().withQBitConfig(new CmsQBitConfig().withBackendName(CmsTestSupport.BACKEND).withStartupMode(CmsStartupMode.SKIP) .withTableNamePrefix("acme_cms_")).produce(renamed); assertThat(HelpBundles.of(renamed).getBundles()).isEmpty(); QInstance core = CmsTestSupport.blankInstance(CmsTestSupport.h2Backend()); new CmsQBitProducer().withQBitConfig(new CmsQBitConfig().withBackendName(CmsTestSupport.BACKEND).withStartupMode(CmsStartupMode.SKIP) .withFeatures(EnumSet.of(CmsFeature.CORE))).produce(core); assertThat(HelpBundles.of(core).getBundles()).hasSize(1); assertThat(HelpBundleAssertions.forInstance(core).bundles(CmsQBitProducer.HELP_BUNDLE) .owning(target -> target.name().equals("cms") || target.name().startsWith("cms")).report()) .as("with CORE alone nothing of CORE is missing; entries of the other features have no object and are reported as such") .noneMatch(line -> line.toLowerCase(java.util.Locale.ROOT).contains("missing")); } }