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

import Foundation
import XCTest
import ToolCore

@testable import ResgenSwift

final class ImageExtensionGeneratorTests: XCTestCase {
    
    func test_uiKit_GeneratedExtensionContent() {
        // Given
        let images = [
            ParsedImage(name: "image_one", tags: "id", width: 10, height: 10),
            ParsedImage(name: "image_two", tags: "id", width: 180, height: 90),
        ]
        
        // When
        let extensionContent = ImageExtensionGenerator.getExtensionContent(images: images,
                                                                           staticVar: false,
                                                                           extensionName: "GenImages",
                                                                           inputFilename: "myInputFilename",
                                                                           isSwiftUI: false)
        
        // Expect
        let expect = """
        // Generated by ResgenSwift.Images \(ResgenSwiftVersion)
        // Images from myInputFilename
        
        import UIKit
        
        extension GenImages {
        
            var image_one: UIImage {
                UIImage(named: "image_one")!
            }
        
            var image_two: UIImage {
                UIImage(named: "image_two")!
            }
        }
        """
        
        XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
    }
    
    func test_uiKit_GeneratedExtensionContentForStaticVar() {
        // Given
        let images = [
            ParsedImage(name: "image_one", tags: "id", width: 10, height: 10),
            ParsedImage(name: "image_two", tags: "id", width: 180, height: 90),
        ]
        
        // When
        let extensionContent = ImageExtensionGenerator.getExtensionContent(images: images,
                                                                           staticVar: true,
                                                                           extensionName: "GenImages",
                                                                           inputFilename: "myInputFilename",
                                                                           isSwiftUI: false)
        
        // Expect
        let expect = """
        // Generated by ResgenSwift.Images \(ResgenSwiftVersion)
        // Images from myInputFilename
        
        import UIKit
        
        extension GenImages {
        
            static var image_one: UIImage {
                UIImage(named: "image_one")!
            }
        
            static var image_two: UIImage {
                UIImage(named: "image_two")!
            }
        }
        """
        
        XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
    }
    
    func test_swiftUI_GeneratedExtensionContent() {
        // Given
        let images = [
            ParsedImage(name: "image_one", tags: "id", width: 10, height: 10),
            ParsedImage(name: "image_two", tags: "id", width: 180, height: 90),
        ]
        
        // When
        let extensionContent = ImageExtensionGenerator.getExtensionContent(images: images,
                                                                           staticVar: false,
                                                                           extensionName: "GenImages",
                                                                           inputFilename: "myInputFilename",
                                                                           isSwiftUI: true)
        
        // Expect
        let expect = """
        // Generated by ResgenSwift.Images \(ResgenSwiftVersion)
        // Images from myInputFilename
        
        import SwiftUI
        
        extension GenImages {
        
            var image_one: Image {
                Image("image_one")
            }
        
            var image_two: Image {
                Image("image_two")
            }
        }
        """
        
        XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
    }
    
    func test_swiftUI_GeneratedExtensionContentForStaticVar() {
        // Given
        let images = [
            ParsedImage(name: "image_one", tags: "id", width: 10, height: 10),
            ParsedImage(name: "image_two", tags: "id", width: 180, height: 90),
        ]
        
        // When
        let extensionContent = ImageExtensionGenerator.getExtensionContent(images: images,
                                                                           staticVar: true,
                                                                           extensionName: "GenImages",
                                                                           inputFilename: "myInputFilename",
                                                                           isSwiftUI: true)
        
        // Expect
        let expect = """
        // Generated by ResgenSwift.Images \(ResgenSwiftVersion)
        // Images from myInputFilename
        
        import SwiftUI
        
        extension GenImages {
        
            static var image_one: Image {
                Image("image_one")
            }
        
            static var image_two: Image {
                Image("image_two")
            }
        }
        """
        
        XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
    }
}
