Skip to content

Commit

Permalink
Check isViewInjected in imports(with:including:)
Browse files Browse the repository at this point in the history
  • Loading branch information
tinder-garricnahapetian committed Sep 19, 2024
1 parent 9917a79 commit ffaf2c2
Show file tree
Hide file tree
Showing 33 changed files with 169 additions and 26 deletions.
16 changes: 11 additions & 5 deletions Sources/NodesGenerator/StencilTemplate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ public enum StencilTemplate: CustomStringConvertible, Equatable, Sendable {

// swiftlint:disable:next function_body_length cyclomatic_complexity
public func imports(with config: Config, including uiFramework: UIFramework? = nil) -> Set<String> {
switch self {
let isViewInjected: Bool = uiFramework == nil
return switch self {
case .analytics:
config.baseImports
case .analyticsTests:
Expand All @@ -246,6 +247,7 @@ public enum StencilTemplate: CustomStringConvertible, Equatable, Sendable {
.union(config.reactiveImports)
case .contextTests:
config.baseTestImports
.union(isViewInjected ? [] : ["NodesTesting"])
case .flow:
config.baseImports
.union(["Nodes"])
Expand All @@ -270,7 +272,7 @@ public enum StencilTemplate: CustomStringConvertible, Equatable, Sendable {
case .state:
config.baseImports
case .viewController:
uiFramework == nil ? [] : config.baseImports
isViewInjected ? [] : config.baseImports
.union(["Nodes"])
.union(config.reactiveImports)
.union(config.viewControllerImports)
Expand All @@ -279,10 +281,14 @@ public enum StencilTemplate: CustomStringConvertible, Equatable, Sendable {
uiFramework == nil ? [] : config.baseTestImports
.union(config.reactiveImports)
case .viewState:
uiFramework == nil ? [] : config.baseImports
.union(["Nodes"])
isViewInjected
? []
: config.baseImports
.union(["Nodes"])
case .viewStateFactoryTests:
uiFramework == nil ? [] : config.baseTestImports
isViewInjected
? []
: config.baseTestImports
case .worker:
config.baseImports
.union(["Nodes"])
Expand Down
99 changes: 98 additions & 1 deletion Tests/NodesGeneratorTests/StencilTemplateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ final class StencilTemplateTests: XCTestCase, TestFactories {
]
case .contextTests:
expect(imports) == [
"<baseTestImport>"
"<baseTestImport>",
"NodesTesting"
]
case .flow:
expect(imports) == [
Expand Down Expand Up @@ -466,6 +467,102 @@ final class StencilTemplateTests: XCTestCase, TestFactories {
}
}
}

// swiftlint:disable:next cyclomatic_complexity
func testImports_givenUIFrameworkNil() {
let config: Config = givenConfig()
for stencilTemplate in StencilTemplate.allCases {
let imports: Set<String> = stencilTemplate.imports(with: config, including: nil)
switch stencilTemplate {
case .analytics:
expect(imports) == [
"<baseImport>"
]
case .analyticsTests:
expect(imports) == [
"<baseTestImport>"
]
case .builder:
expect(imports) == [
"Nodes",
"<baseImport>",
"<reactiveImport>",
"<dependencyInjectionImport>",
"<builderImport>"
]
case .builderTests:
expect(imports) == [
"NodesTesting",
"<baseTestImport>"
]
case .context:
expect(imports) == [
"Nodes",
"<baseImport>",
"<reactiveImport>"
]
case .contextTests:
expect(imports) == [
"<baseTestImport>"
]
case .flow:
expect(imports) == [
"Nodes",
"<baseImport>",
"<flowImport>"
]
case .flowTests:
expect(imports) == [
"<baseTestImport>"
]
case .plugin:
expect(imports) == [
"Nodes",
"<baseImport>",
"<dependencyInjectionImport>"
]
case .pluginTests:
expect(imports) == [
"NodesTesting",
"<baseTestImport>"
]
case .pluginList:
expect(imports) == [
"Nodes",
"<baseImport>",
"<dependencyInjectionImport>",
"<pluginListImport>"
]
case .pluginListTests:
expect(imports) == [
"NodesTesting",
"<baseTestImport>"
]
case .state:
expect(imports) == [
"<baseImport>"
]
case .viewController:
expect(imports).to(beEmpty())
case .viewControllerTests:
expect(imports).to(beEmpty())
case .viewState:
expect(imports).to(beEmpty())
case .viewStateFactoryTests:
expect(imports).to(beEmpty())
case .worker:
expect(imports) == [
"Nodes",
"<baseImport>",
"<reactiveImport>"
]
case .workerTests:
expect(imports) == [
"<baseTestImport>"
]
}
}
}
}

extension StencilTemplate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#warning("Manually move this test file to the corresponding test target then delete this warning.")

import Nimble
import NodesTesting
import XCTest

final class ___VARIABLE_productName___ContextTests: XCTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#warning("Manually move this test file to the corresponding test target then delete this warning.")

import Nimble
import NodesTesting
import XCTest

final class ___VARIABLE_productName___ContextTests: XCTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#warning("Manually move this test file to the corresponding test target then delete this warning.")

import Nimble
import NodesTesting
import XCTest

final class ___VARIABLE_productName___ContextTests: XCTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#warning("Manually move this test file to the corresponding test target then delete this warning.")

import Nimble
import NodesTesting
import XCTest

final class ___VARIABLE_productName___ContextTests: XCTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#warning("Manually move this test file to the corresponding test target then delete this warning.")

import Nimble
import NodesTesting
import XCTest

final class ___VARIABLE_productName___ContextTests: XCTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#warning("Manually move this test file to the corresponding test target then delete this warning.")

import Nimble
import NodesTesting
import XCTest

final class ___VARIABLE_productName___ContextTests: XCTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#warning("Manually move this test file to the corresponding test target then delete this warning.")

import Nimble
import NodesTesting
import XCTest

final class ___VARIABLE_productName___ContextTests: XCTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#warning("Manually move this test file to the corresponding test target then delete this warning.")

import Nimble
import NodesTesting
import XCTest

final class ___VARIABLE_productName___ContextTests: XCTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#warning("Manually move this test file to the corresponding test target then delete this warning.")

import Nimble
import NodesTesting
import XCTest

final class ___VARIABLE_productName___ContextTests: XCTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#warning("Manually move this test file to the corresponding test target then delete this warning.")

import Nimble
import NodesTesting
import XCTest

final class ___VARIABLE_productName___ContextTests: XCTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#warning("Manually move this test file to the corresponding test target then delete this warning.")

import Nimble
import NodesTesting
import XCTest

final class ___VARIABLE_productName___ContextTests: XCTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#warning("Manually move this test file to the corresponding test target then delete this warning.")

import Nimble
import NodesTesting
import XCTest

final class ___VARIABLE_productName___ContextTests: XCTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#warning("Manually move this test file to the corresponding test target then delete this warning.")

import Nimble
import NodesTesting
import XCTest

final class ___VARIABLE_productName___ContextTests: XCTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#warning("Manually move this test file to the corresponding test target then delete this warning.")

import Nimble
import NodesTesting
import XCTest

final class ___VARIABLE_productName___ContextTests: XCTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#warning("Manually move this test file to the corresponding test target then delete this warning.")

import Nimble
import NodesTesting
import XCTest

final class ___VARIABLE_productName___ContextTests: XCTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#warning("Manually move this test file to the corresponding test target then delete this warning.")

import Nimble
import NodesTesting
import XCTest

final class ___VARIABLE_productName___ContextTests: XCTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#warning("Manually move this test file to the corresponding test target then delete this warning.")

import Nimble
import NodesTesting
import XCTest

final class ___VARIABLE_productName___ContextTests: XCTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#warning("Manually move this test file to the corresponding test target then delete this warning.")

import Nimble
import NodesTesting
import XCTest

final class ___VARIABLE_productName___ContextTests: XCTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#warning("Manually move this test file to the corresponding test target then delete this warning.")

import Nimble
import NodesTesting
import XCTest

final class ___VARIABLE_productName___ContextTests: XCTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#warning("Manually move this test file to the corresponding test target then delete this warning.")

import Nimble
import NodesTesting
import XCTest

final class ___VARIABLE_productName___ContextTests: XCTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
- "<baseImport>"
- "<reactiveImport>"
- "Nodes"
▿ contextTestsImports: 1 element
▿ contextTestsImports: 2 elements
- "<baseTestImport>"
- "NodesTesting"
▿ dependencies: 1 element
▿ 2 key/value pairs
▿ (2 elements)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
- "<baseImport>"
- "<reactiveImport>"
- "Nodes"
▿ contextTestsImports: 1 element
▿ contextTestsImports: 2 elements
- "<baseTestImport>"
- "NodesTesting"
▿ dependencies: 1 element
▿ 2 key/value pairs
▿ (2 elements)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
- "<baseImport>"
- "<reactiveImport>"
- "Nodes"
▿ contextTestsImports: 1 element
▿ contextTestsImports: 2 elements
- "<baseTestImport>"
- "NodesTesting"
▿ dependencies: 1 element
▿ 2 key/value pairs
▿ (2 elements)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
- "<baseImport>"
- "<reactiveImport>"
- "Nodes"
▿ contextTestsImports: 1 element
▿ contextTestsImports: 2 elements
- "<baseTestImport>"
- "NodesTesting"
▿ dependencies: 1 element
▿ 2 key/value pairs
▿ (2 elements)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
- "<baseImport>"
- "<reactiveImport>"
- "Nodes"
▿ contextTestsImports: 1 element
▿ contextTestsImports: 2 elements
- "<baseTestImport>"
- "NodesTesting"
▿ dependencies: 1 element
▿ 2 key/value pairs
▿ (2 elements)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
- "<baseImport>"
- "<reactiveImport>"
- "Nodes"
▿ contextTestsImports: 1 element
▿ contextTestsImports: 2 elements
- "<baseTestImport>"
- "NodesTesting"
▿ dependencies: 1 element
▿ 2 key/value pairs
▿ (2 elements)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
- "<baseImport>"
- "<reactiveImport>"
- "Nodes"
▿ contextTestsImports: 1 element
▿ contextTestsImports: 2 elements
- "<baseTestImport>"
- "NodesTesting"
▿ dependencies: 1 element
▿ 2 key/value pairs
▿ (2 elements)
Expand Down
Loading

0 comments on commit ffaf2c2

Please sign in to comment.