//
//  ColorExtensionGeneratorTests.swift
//  
//
//  Created by Thibaut Schmitt on 05/09/2022.
//

import Foundation
import XCTest
import ToolCore

@testable import ResgenSwift

final class ColorExtensionGeneratorTests: XCTestCase {
    
    func test_uiKit_GeneratedExtensionContent() {
        // Given
        let colors = [
            ParsedColor(name: "colorOne", light: "#FF00FF", dark: "#00FF00"),
            ParsedColor(name: "colorTwo", light: "#F0F0F0", dark: "#0F0F0F")
        ]
        
        // When
        let extensionContent = ColorExtensionGenerator.getExtensionContent(colors: colors,
                                                                           staticVar: false,
                                                                           extensionName: "GenColors",
                                                                           isSwiftUI: false)
        
        // Expect
        let expect = """
        // Generated by ResgenSwift.Color \(ResgenSwiftVersion)

        import UIKit

        extension GenColors {
        
            /// Color colorOne is #FF00FF (light) or #00FF00 (dark)"
            @objc var colorOne: UIColor {
                UIColor(named: "colorOne")!
            }
        
            /// Color colorTwo is #F0F0F0 (light) or #0F0F0F (dark)"
            @objc var colorTwo: UIColor {
                UIColor(named: "colorTwo")!
            }
        }
        """
        
        XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
    }
    
    func test_uiKit_GeneratedExtensionContentForStaticVar() {
        // Given
        let colors = [
            ParsedColor(name: "colorOne", light: "#FF00FF", dark: "#00FF00"),
            ParsedColor(name: "colorTwo", light: "#F0F0F0", dark: "#0F0F0F")
        ]
        
        // When
        let extensionContent = ColorExtensionGenerator.getExtensionContent(colors: colors,
                                                                           staticVar: true,
                                                                           extensionName: "GenColor",
                                                                           isSwiftUI: false)
        
        // Expect
        let expect = """
        // Generated by ResgenSwift.Color \(ResgenSwiftVersion)

        import UIKit

        extension GenColor {
        
            /// Color colorOne is #FF00FF (light) or #00FF00 (dark)"
            static var colorOne: UIColor {
                UIColor(named: "colorOne")!
            }
        
            /// Color colorTwo is #F0F0F0 (light) or #0F0F0F (dark)"
            static var colorTwo: UIColor {
                UIColor(named: "colorTwo")!
            }
        }
        """
        
        XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
    }
    
    func test_swiftUI_GeneratedExtensionContent() {
        // Given
        let colors = [
            ParsedColor(name: "colorOne", light: "#FF00FF", dark: "#00FF00"),
            ParsedColor(name: "colorTwo", light: "#F0F0F0", dark: "#0F0F0F")
        ]
        
        // When
        let extensionContent = ColorExtensionGenerator.getExtensionContent(colors: colors,
                                                                           staticVar: false,
                                                                           extensionName: "GenColors",
                                                                           isSwiftUI: true)
        
        // Expect
        let expect = """
        // Generated by ResgenSwift.Color \(ResgenSwiftVersion)

        import SwiftUI

        extension GenColors {
        
            /// Color colorOne is #FF00FF (light) or #00FF00 (dark)"
            var colorOne: Color {
                Color("colorOne")
            }
        
            /// Color colorTwo is #F0F0F0 (light) or #0F0F0F (dark)"
             var colorTwo: Color {
                Color("colorTwo")
            }
        }
        """
        
        XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
    }
    
    func test_swiftUI_GeneratedExtensionContentForStaticVar() {
        // Given
        let colors = [
            ParsedColor(name: "colorOne", light: "#FF00FF", dark: "#00FF00"),
            ParsedColor(name: "colorTwo", light: "#F0F0F0", dark: "#0F0F0F")
        ]
        
        // When
        let extensionContent = ColorExtensionGenerator.getExtensionContent(colors: colors,
                                                                           staticVar: true,
                                                                           extensionName: "GenColor",
                                                                           isSwiftUI: true)
        
        // Expect
        let expect = """
        // Generated by ResgenSwift.Color \(ResgenSwiftVersion)

        import SwiftUI

        extension GenColor {
        
            /// Color colorOne is #FF00FF (light) or #00FF00 (dark)"
            static var colorOne: Color {
                Color("colorOne")
            }
        
            /// Color colorTwo is #F0F0F0 (light) or #0F0F0F (dark)"
            static var colorTwo: Color {
                Color("colorTwo")
            }
        }
        """
        
        XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
    }
}
