// tools/generate-tests-mobile.ts — Mobile platform test scaffold generators
// iOS (XCTest) and Android (JUnit5 + MockK/Mockito/Compose/Espresso) content
function toPascalMobile(str) {
    return str
        .replace(/[^a-zA-Z0-9\s]/g, '')
        .split(/\s+/)
        .map((w) => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase())
        .join('');
}
export function generateXCTestContent(specId, testType) {
    const cls = toPascalMobile(specId);
    if (testType === 'ui') {
        return [
            `// XCUITest for: ${specId}`,
            '// Generated by Planu SDD MCP Server',
            '',
            'import XCTest',
            '',
            `final class ${cls}UITests: XCTestCase {`,
            '    private var app: XCUIApplication!',
            '',
            '    override func setUp() {',
            '        super.setUp()',
            '        continueAfterFailure = false',
            '        app = XCUIApplication()',
            '        app.launch()',
            '    }',
            '',
            '    override func tearDown() {',
            '        app = nil',
            '        super.tearDown()',
            '    }',
            '',
            '    func test_mainElement_isVisible() throws {',
            `        let element = app.otherElements["${cls.toLowerCase()}-container"]`,
            '        XCTAssertTrue(element.exists)',
            '    }',
            '',
            '    func test_primaryAction_triggersExpectedState() throws {',
            `        let button = app.buttons["${cls.toLowerCase()}-primary-action"]`,
            '        XCTAssertTrue(button.exists)',
            '        button.tap()',
            '        // TODO: Assert expected state after tap',
            '    }',
            '}',
        ].join('\n');
    }
    if (testType === 'snapshot') {
        return [
            `// Snapshot tests for: ${specId}`,
            '// Generated by Planu SDD MCP Server',
            '// Requires: swift-snapshot-testing (PointFree)',
            '',
            'import XCTest',
            'import SnapshotTesting',
            '',
            `final class ${cls}SnapshotTests: XCTestCase {`,
            '    override func setUp() {',
            '        super.setUp()',
            '        // isRecording = true // Uncomment to record new snapshots',
            '    }',
            '',
            '    func test_view_rendersCorrectly() throws {',
            `        let sut = ${cls}ViewController()`,
            '        assertSnapshot(matching: sut, as: .image)',
            '    }',
            '',
            '    func test_view_rendersCorrectly_darkMode() throws {',
            `        let sut = ${cls}ViewController()`,
            '        assertSnapshot(matching: sut, as: .image(traits: .init(userInterfaceStyle: .dark)))',
            '    }',
            '}',
        ].join('\n');
    }
    // Default: unit
    return [
        `// Unit tests for: ${specId}`,
        '// Generated by Planu SDD MCP Server',
        '',
        'import XCTest',
        '',
        `final class ${cls}Tests: XCTestCase {`,
        `    private var sut: ${cls}!`,
        '',
        '    override func setUp() {',
        '        super.setUp()',
        `        sut = ${cls}()`,
        '    }',
        '',
        '    override func tearDown() {',
        '        sut = nil',
        '        super.tearDown()',
        '    }',
        '',
        '    func test_coreLogic_returnsExpectedValue() throws {',
        '        // TODO: Implement test',
        '        XCTAssertNotNil(sut)',
        '    }',
        '',
        '    func test_edgeCase_handledGracefully() throws {',
        '        XCTAssertTrue(true)',
        '    }',
        '',
        '    func test_invalidInput_throwsError() throws {',
        '        // TODO: Implement error handling test',
        '        XCTAssertThrowsError(try sut.performAction(with: nil))',
        '    }',
        '}',
    ].join('\n');
}
export function generateAndroidTestContent(specId, testType, uiFramework, mockFramework) {
    const cls = toPascalMobile(specId);
    if (testType === 'ui') {
        return uiFramework === 'compose'
            ? buildComposeUITest(specId, cls)
            : buildEspressoUITest(specId, cls);
    }
    if (testType === 'integration') {
        return buildRobolectricTest(specId, cls);
    }
    return mockFramework === 'mockito'
        ? buildMockitoUnitTest(specId, cls)
        : buildMockKUnitTest(specId, cls);
}
function buildComposeUITest(specId, cls) {
    return [
        `// Compose UI tests for: ${specId}`,
        '// Generated by Planu SDD MCP Server',
        '',
        'import androidx.compose.ui.test.junit4.createComposeRule',
        'import androidx.compose.ui.test.onNodeWithTag',
        'import androidx.compose.ui.test.performClick',
        'import androidx.compose.ui.test.assertIsDisplayed',
        'import org.junit.Rule',
        'import org.junit.Test',
        '',
        `class ${cls}ComposeTest {`,
        '    @get:Rule',
        '    val composeTestRule = createComposeRule()',
        '',
        '    @Test',
        '    fun mainContent_isDisplayed() {',
        '        composeTestRule.setContent {',
        `            ${cls}Screen()`,
        '        }',
        `        composeTestRule.onNodeWithTag("${cls.toLowerCase()}-container")`,
        '            .assertIsDisplayed()',
        '    }',
        '',
        '    @Test',
        '    fun primaryAction_triggersExpectedState() {',
        '        composeTestRule.setContent {',
        `            ${cls}Screen()`,
        '        }',
        `        composeTestRule.onNodeWithTag("${cls.toLowerCase()}-primary-action")`,
        '            .performClick()',
        '        // TODO: Assert expected state',
        '    }',
        '}',
    ].join('\n');
}
function buildEspressoUITest(specId, cls) {
    return [
        `// Espresso UI tests for: ${specId}`,
        '// Generated by Planu SDD MCP Server',
        '',
        'import androidx.test.espresso.Espresso.onView',
        'import androidx.test.espresso.action.ViewActions.click',
        'import androidx.test.espresso.matcher.ViewMatchers.withId',
        'import androidx.test.ext.junit.runners.AndroidJUnit4',
        'import org.junit.Test',
        'import org.junit.runner.RunWith',
        '',
        '@RunWith(AndroidJUnit4::class)',
        `class ${cls}EspressoTest {`,
        '    @Test',
        '    fun button_click_triggersExpectedBehavior() {',
        '        // TODO: Launch activity via ActivityScenario',
        `        onView(withId(R.id.${cls.toLowerCase()}_button)).perform(click())`,
        '        // TODO: Assert expected state',
        '    }',
        '}',
    ].join('\n');
}
function buildRobolectricTest(specId, cls) {
    return [
        `// Robolectric integration tests for: ${specId}`,
        '// Generated by Planu SDD MCP Server',
        '',
        'import org.junit.Test',
        'import org.junit.runner.RunWith',
        'import org.robolectric.RobolectricTestRunner',
        'import org.robolectric.annotation.Config',
        '',
        '@RunWith(RobolectricTestRunner::class)',
        '@Config(sdk = [33])',
        `class ${cls}IntegrationTest {`,
        '    @Test',
        '    fun component_initializesCorrectly() {',
        '        // TODO: Implement integration test',
        '    }',
        '',
        '    @Test',
        '    fun component_handlesLifecycleEvents() {',
        '        // TODO: Test lifecycle transitions',
        '    }',
        '}',
    ].join('\n');
}
function buildMockitoUnitTest(specId, cls) {
    return [
        `// Unit tests for: ${specId}`,
        '// Generated by Planu SDD MCP Server',
        '',
        'import org.junit.jupiter.api.Test',
        'import org.junit.jupiter.api.extension.ExtendWith',
        'import org.mockito.InjectMocks',
        'import org.mockito.Mock',
        'import org.mockito.junit.jupiter.MockitoExtension',
        'import org.mockito.kotlin.whenever',
        'import org.junit.jupiter.api.Assertions.assertNotNull',
        '',
        '@ExtendWith(MockitoExtension::class)',
        `class ${cls}Test {`,
        '    @Mock',
        `    private lateinit var dependency: ${cls}Dependency`,
        '',
        '    @InjectMocks',
        `    private lateinit var sut: ${cls}`,
        '',
        '    @Test',
        '    fun coreLogic_returnsExpectedValue() {',
        '        whenever(dependency.getData()).thenReturn(listOf())',
        '        val result = sut.execute()',
        '        assertNotNull(result)',
        '    }',
        '',
        '    @Test',
        '    fun edgeCase_handledGracefully() {',
        '        whenever(dependency.getData()).thenReturn(null)',
        '        val result = sut.execute()',
        '        assertNotNull(result)',
        '    }',
        '',
        '    @Test',
        '    fun invalidInput_throwsException() {',
        '        // TODO: Implement error case',
        '    }',
        '}',
    ].join('\n');
}
function buildMockKUnitTest(specId, cls) {
    return [
        `// Unit tests for: ${specId}`,
        '// Generated by Planu SDD MCP Server',
        '',
        'import io.mockk.every',
        'import io.mockk.impl.annotations.MockK',
        'import io.mockk.verify',
        'import org.junit.jupiter.api.BeforeEach',
        'import org.junit.jupiter.api.Test',
        'import org.junit.jupiter.api.extension.ExtendWith',
        'import io.mockk.junit5.MockKExtension',
        'import org.junit.jupiter.api.Assertions.assertNotNull',
        '',
        '@ExtendWith(MockKExtension::class)',
        `class ${cls}Test {`,
        '    @MockK',
        `    private lateinit var dependency: ${cls}Dependency`,
        '',
        `    private lateinit var sut: ${cls}`,
        '',
        '    @BeforeEach',
        '    fun setUp() {',
        `        sut = ${cls}(dependency)`,
        '    }',
        '',
        '    @Test',
        '    fun coreLogic_returnsExpectedValue() {',
        '        every { dependency.getData() } returns listOf()',
        '        val result = sut.execute()',
        '        assertNotNull(result)',
        '        verify { dependency.getData() }',
        '    }',
        '',
        '    @Test',
        '    fun edgeCase_handledGracefully() {',
        '        every { dependency.getData() } returns emptyList()',
        '        val result = sut.execute()',
        '        assertNotNull(result)',
        '    }',
        '',
        '    @Test',
        '    fun invalidInput_throwsException() {',
        '        // TODO: Implement error case',
        '    }',
        '}',
    ].join('\n');
}
//# sourceMappingURL=generate-tests-mobile.js.map