﻿#if !NETFX_CORE
using UnityEngine;
using UnityEngine.TestTools;
using NUnit.Framework;
using System.Collections;
using UnityEngine.SceneManagement;
using I2.Loc;
using UnityEngine.UI;
using System;


public partial class I2Loc_PlayTest_Targets
{
    [UnityTest, Category("Targets")]
    public IEnumerator I2LocTest_UnityUI()
    {
        SceneManager.LoadScene("I2Localization    UnityUI");
        yield return null;

        Assert.IsTrue(LocalizationManager.Sources.Count == (LocalizationManager.GlobalSources.Length + 1));

        var pText = I2Utils.FindObject("Canvas/Localized Examples/Text").GetComponent<Text>();
        var pImage = I2Utils.FindObject("Canvas/Localized Examples/Image").GetComponent<Image>();
        var pRawImage = I2Utils.FindObject("Canvas/Localized Examples/RawImage").GetComponent<RawImage>();
        var pDropdown = I2Utils.FindObject("Canvas/Localized Examples/Dropdown").GetComponent<Dropdown>();


        I2Utils.FindObject("Canvas/Buttons/Spanish").GetComponent<Button>().onClick.Invoke();
        yield return null;

        Assert.IsTrue(pText.text == "Este es un Texto del Unity UI");
        Assert.IsTrue(pImage.sprite.name == "L_ES");
        Assert.IsTrue(pRawImage.texture.name == "L_ES");
        Assert.IsTrue(pDropdown.captionText.text == "Opción A");

        I2Utils.FindObject("Canvas/Buttons/English").GetComponent<Button>().onClick.Invoke();
        yield return null;

        Assert.IsTrue(pText.text == "This is a localized Unity UI Text");
        Assert.IsTrue(pImage.sprite.name == "L_EN");
        Assert.IsTrue(pRawImage.texture.name == "L_EN");
        Assert.IsTrue(pDropdown.captionText.text == "Option A");

        I2Utils.FindObject("Canvas/Buttons/French").GetComponent<Button>().onClick.Invoke();
        yield return null;

        Assert.IsTrue(pText.text == "Il s'agit d'un texte localise Unity UI");
        Assert.IsTrue(pImage.sprite.name == "L_FR");
        Assert.IsTrue(pRawImage.texture.name == "L_FR");
        Assert.IsTrue(pDropdown.captionText.text == "Un Choix");
    } 
}

#endif