namespace Tests.E2ETests {
    [TestFixture, Order(1)]
    public class MainWindowTest {

        private AppSession Session;

        [OneTimeSetUp]
        public void Setup() {
            Session = new(Utils.ApplicationPath, Utils.ConfigPath, WinAppDriver.WinAppDriverUrl);
        }

        [OneTimeTearDown]
        public void Teardown() {
            Session.Dispose();
        }

        [Test]
        public void Test_Open_MemberAdminWindow() {
            Assert.DoesNotThrow(() => {
                Session.App.FindElement(By.Name("Mitglieder")).Click();
                Thread.Sleep(Utils.WINDOW_OPEN_SLEEP);
                var window = Session.CreateWindowDriver("MemberAdminWindow");
                Assert.That(window.Title, Is.EqualTo("Mitglieder - Elwig"));
                window.Close();
            });
        }

        [Test]
        public void Test_Open_DeliveryAdminWindow() {
            Assert.DoesNotThrow(() => {
                Session.App.FindElement(By.Name("Lieferungen")).Click();
                Thread.Sleep(Utils.WINDOW_OPEN_SLEEP);
                var window = Session.CreateWindowDriver("DeliveryAdminWindow");
                Assert.That(window.Title, Is.EqualTo("Lieferungen - Elwig"));
                window.Close();
            });
        }

        [Test]
        public void Test_Open_BaseDataWindow() {
            Assert.DoesNotThrow(() => {
                Session.App.FindElement(By.Name("Stammdaten")).Click();
                Thread.Sleep(Utils.WINDOW_OPEN_SLEEP);
                var window = Session.CreateWindowDriver("BaseDataWindow");
                Assert.That(window.Title, Is.EqualTo("Stammdaten - Elwig"));
                window.Close();
            });
        }

        [Test]
        public void Test_Open_MailWindow() {
            Assert.DoesNotThrow(() => {
                Session.App.FindElement(By.Name("Rundschreiben")).Click();
                Thread.Sleep(Utils.WINDOW_OPEN_SLEEP);
                var window = Session.CreateWindowDriver("MailWindow");
                Assert.That(window.Title, Is.EqualTo($"Rundschreiben - Lese {Elwig.Helpers.Utils.Today.Year} - Elwig"));
                window.Close();
            });
        }
    }
}
