Skip to main content Skills Marketplace Descubra e explore skills de IA criadas pela comunidade.
Ocupações relacionadas SOC
Baseado na classificação ocupacional SOC
Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Copiar promptMostrar detalhes do prompt Um comando direto ignora o prompt de revisão. Verifique a origem antes de executá-lo.
npx skills add https://github.com/ForceInjection/domain-driven-design-skills --skill fosmvvm-viewmodel-test-generatorO comando permanece em uma só linha. Role horizontalmente para revisá-lo antes de copiar.
Prefere uma cópia local? Baixe os arquivos disponíveis atualmente no SkillsMP.
Baixar Zip Baixando... Explorador de arquivos
2 arquivos Mais deste repositório Conduct deep academic research for philosophy, neuroscience, cognitive science, and theoretical computer science (computability, complexity, AI theory, logic). Use when user asks to: research academic topics, find scholarly papers, conduct literature reviews, analyze citations, synthesize research findings, explore philosophical arguments, investigate consciousness/cognition, study computability/decidability/Turing machines, or analyze academic debates. Triggers on: 'research papers', 'literature review', 'academic sources', 'scholarly articles', 'philosophy of mind', 'computability theory', 'neuroscience studies', 'find papers on', 'what does the research say'.
Create clear action plans with steps, success criteria, and risk awareness. Use before implementing features, making changes, starting projects, or anytime you need a roadmap to success. Triggers on "plan this", "how should we approach", "what's the strategy", "steps to complete", or when facing complex multi-step work.
Add keyboard navigation to a feature using CommandRegistryService. Use when implementing keyboard shortcuts, vim-style navigation, or hotkeys for a page or component.
name fosmvvm-viewmodel-test-generator description Generate comprehensive ViewModel tests with multi-locale translation verification. Use when creating test coverage for ViewModels, especially those with localization.
FOSMVVM ViewModel Test Generator
Generate test files for ViewModels following FOSMVVM testing patterns.
Conceptual Foundation
For full architecture context, see FOSMVVMArchitecture.md
ViewModel testing in FOSMVVM verifies three critical aspects:
Codable round-trip - ViewModel encodes and decodes without data loss
Versioning stability - Structure hasn't changed unexpectedly
Multi-locale translations - All @LocalizedString properties have values in all supported locales
The LocalizableTestCase protocol provides infrastructure that tests all three in a single call.
When to Use This Skill
Creating tests for new ViewModels
Adding test coverage to existing ViewModels
Verifying localization completeness across locales
Testing ViewModels with embedded/nested child ViewModels
Verifying @LocalizedSubs substitution behavior
What This Skill Generates
File Location Purpose {Name}ViewModelTests.swiftTests/{Target}Tests/Localization/Test suite conforming to LocalizableTestCase {Name}ViewModel.ymlTests/{Target}Tests/TestYAML/
YAML translations for test (if needed)
The Testing Pattern
Standard Pattern (Most Tests) For most ViewModels, a single line provides complete coverage:
@Test func dashboardViewModel () throws {
try expectFullViewModelTests(DashboardViewModel .self )
}
Codable encoding/decoding
Versioned ViewModel stability
Translations exist for all locales (en, es by default)
This is sufficient for the vast majority of ViewModel tests.
Extended Pattern (Specific Formatting Verification) When testing specific formatting behavior (substitutions, compound strings), add locale-specific assertions:
@Test func greetingWithSubstitution () throws {
try expectFullViewModelTests(GreetingViewModel .self )
let vm: GreetingViewModel = try .stub()
.toJSON(encoder: encoder(locale: en))
.fromJSON()
#expect(try vm.welcomeMessage.localizedString == "Welcome, John!" )
}
This is optional - use only when verifying specific formatting techniques.
LocalizableTestCase Protocol Test suites conform to LocalizableTestCase to access testing infrastructure:
import FOSFoundation
@testable import FOSMVVM
import FOSTesting
import Foundation
import Testing
@Suite ("My ViewModel Tests" )
struct MyViewModelTests : LocalizableTestCase {
let locStore: LocalizationStore
init () throws {
self .locStore = try Self .loadLocalizationStore(
bundle: Bundle .module,
resourceDirectoryName: "TestYAML"
)
}
}
What LocalizableTestCase Provides Property/Method Purpose locStoreRequired - the localization store localesOptional - locales to test (default: en, es) encoder(locale:)Creates a localizing JSONEncoder en, es, enGB, enUSLocale constants
Testing Methods Method Use When expectFullViewModelTests(_:)Primary - complete ViewModel testingexpectTranslations(_:)Translation-only verification expectFullFieldValidationModelTests(_:)Testing FieldValidationModel types expectFullFormFieldTests(_:)Testing FormField instances expectCodable(_:encoder:)Codable round-trip only expectVersionedViewModel(_:encoder:)Versioning stability only
YAML Requirements
ViewModels with @LocalizedString Every ViewModel with @LocalizedString properties needs YAML entries:
@ViewModel
public struct DashboardViewModel : RequestableViewModel {
@LocalizedString public var pageTitle
@LocalizedString public var emptyMessage
public let itemCount: Int
}
en:
DashboardViewModel:
pageTitle: "Dashboard"
emptyMessage: "No items yet"
es:
DashboardViewModel:
pageTitle: "Tablero"
emptyMessage: "No hay elementos todavía"
Embedded ViewModels When a ViewModel contains child ViewModels, all types in the hierarchy need YAML entries:
@ViewModel
public struct BoardViewModel : RequestableViewModel {
@LocalizedString public var title
public let cards: [CardViewModel ]
}
@ViewModel
public struct CardViewModel {
@LocalizedString public var cardTitle
}
Both BoardViewModel and CardViewModel need YAML entries (can be in same or separate files).
Private Test ViewModels When tests define private ViewModel structs for testing specific scenarios, those also need YAML:
private struct TestParentViewModel : ViewModel {
@LocalizedString var title
let children: [TestChildViewModel ]
}
private struct TestChildViewModel : ViewModel {
@LocalizedString var label
}
Add entries to a test YAML file for these private types.
Generation Process
Step 1: Identify ViewModels to Test Determine which ViewModels need test coverage:
New ViewModels being created
Existing ViewModels without tests
ViewModels with localization properties
Step 2: Check YAML Coverage Verify YAML entries exist for:
The ViewModel itself
Any embedded/child ViewModels
All supported locales (typically en, es)
Step 3: Generate Test File Create test suite conforming to LocalizableTestCase:
One @Test function per ViewModel (or logical grouping)
Use expectFullViewModelTests() as the primary assertion
Add specific formatting tests only when needed
Step 4: Run Tests swift test --filter {TestSuiteName}
File Templates
Common Scenarios
Testing a Single Top-Level ViewModel @Test func dashboardViewModel () throws {
try expectFullViewModelTests(DashboardViewModel .self )
}
Testing Multiple Related ViewModels @Test func boardViewModels () throws {
try expectFullViewModelTests(BoardViewModel .self )
try expectFullViewModelTests(ColumnViewModel .self )
try expectFullViewModelTests(CardViewModel .self )
}
Testing with Custom Locales var locales: Set <Locale > { [en, es, enGB] }
@Test func multiLocaleViewModel () throws {
try expectFullViewModelTests(MyViewModel .self )
}
Testing Substitution Behavior @Test func greetingSubstitutions () throws {
try expectFullViewModelTests(GreetingViewModel .self )
let vm: GreetingViewModel = try .stub(userName: "Alice" )
.toJSON(encoder: encoder(locale: en))
.fromJSON()
#expect(try vm.welcomeMessage.localizedString == "Welcome, Alice!" )
}
Testing Embedded ViewModels @Test func parentWithChildren () throws {
try expectFullViewModelTests(ParentViewModel .self )
let vm: ParentViewModel = try .stub()
.toJSON(encoder: encoder(locale: en))
.fromJSON()
#expect(try vm.children[0 ].label.localizedString == "Child 1" )
}
Troubleshooting
"Missing Translation" Error FOSLocalizableError: _pageTitle -- Missing Translation -- en
Cause: YAML entry missing for a @LocalizedString property.
Fix: Add the property to the YAML file:
en:
MyViewModel:
pageTitle: "Page Title"
"Is pending localization" Error Cause: The ViewModel wasn't encoded with a localizing encoder.
Fix: Ensure using encoder(locale:) or expectFullViewModelTests().
Test Passes But Translations Seem Wrong Cause: YAML values exist but may have typos or wrong content.
Fix: Add specific assertions to verify exact values:
let vm = try .stub().toJSON(encoder: encoder(locale: en)).fromJSON()
#expect(try vm.title.localizedString == "Expected Value" )
Naming Conventions Concept Convention Example Test suite {Feature}ViewModelTestsDashboardViewModelTestsTest file {Feature}ViewModelTests.swiftDashboardViewModelTests.swiftYAML file {ViewModelName}.ymlDashboardViewModel.ymlTest method {viewModelName}() or descriptivedashboardViewModel()
See Also
Version History Version Date Changes 1.0 2025-01-02 Initial skill