// Login (FR-01, FR-04): the code is requested at once when the number is in the config, and the dialog says where Telegram sent it. #include "rig.hpp" #include "tttest.hpp" #include "mologram/ui/dialogs/LoginDialog.hpp" using namespace uitest; TEST_CASE("login delivery text names the channel in plain words for every type", "[ui][login][unit]") { CHECK(has(LoginDialog::deliveryText("app", "sms"), "Telegram app on your other devices")); CHECK(has(LoginDialog::deliveryText("app", "sms"), "not an SMS")); CHECK(has(LoginDialog::deliveryText("app", "sms"), "by SMS")); CHECK(has(LoginDialog::deliveryText("sms", ""), "by SMS")); CHECK(has(LoginDialog::deliveryText("call", ""), "call your phone")); CHECK(has(LoginDialog::deliveryText("flash_call", ""), "last digits")); CHECK(has(LoginDialog::deliveryText("email_code", ""), "email")); CHECK(has(LoginDialog::deliveryText("something_new", ""), "something_new")); CHECK(has(LoginDialog::deliveryText("", ""), "was requested")); CHECK(has(LoginDialog::deliveryText("sms", ""), "one-time login")); } TEST_CASE("login: the number is in the config, so the code is requested without typing and the dialog says it went to the app", "[ui][login][integration]") { Rig r(100, 30, "\"phone\":\"+31600000000\"", "", false); CHECK_EQ(r.rec.count("auth.send_phone"), 1); // asked once, by itself ttgui::Window* w = r.window("LoginDialog"); REQUIRE(w != nullptr); std::string s = r.screen(); CHECK(has(s, "Telegram app")); CHECK(has(s, "It is not")); CHECK(has(s, "Resend")); CHECK(has(s, "Login code")); CHECK_EQ(js::getStr(r.rec.last("auth.send_phone"), "phone"), std::string("")); // empty: the service uses the number of its own config } TEST_CASE("login: without a number in the config the phone field waits for the user and nothing is sent", "[ui][login][integration]") { Rig r(100, 30, "", "", false); CHECK_EQ(r.rec.count("auth.send_phone"), 0); ttgui::Window* w = r.window("LoginDialog"); REQUIRE(w != nullptr); CHECK(has(r.screen(), "International format")); r.type(r.edit(w), "+31611111111"); r.click(w, "Next"); CHECK_EQ(r.rec.count("auth.send_phone"), 1); CHECK_EQ(js::getStr(r.rec.last("auth.send_phone"), "phone"), std::string("+31611111111")); CHECK(has(r.screen(), "Telegram app")); } TEST_CASE("login: resend changes the explanation to SMS and the automatic request happens only once per run", "[ui][login][integration]") { Rig r(100, 30, "\"phone\":\"+31600000000\"", "", false); ttgui::Window* w = r.window("LoginDialog"); REQUIRE(w != nullptr); r.click(w, "Resend code"); CHECK_EQ(r.rec.count("auth.resend_code"), 1); CHECK(has(r.screen(), "by SMS")); CHECK_EQ(r.rec.count("auth.send_phone"), 1); // resend does not request the first code again // after a logout the dialog opens at the phone step; the automatic request already ran in this process LoginDialog::open(r.app.context(), "need_phone", ""); r.settle(); CHECK_EQ(r.rec.count("auth.send_phone"), 1); CHECK(has(r.screen(), "International format")); CHECK(has(r.screen(), "Leave it empty")); // the config has a number } TEST_CASE("login: before the login finished no chats are requested; after it they load", "[ui][login][integration]") { Rig r(100, 30, "\"phone\":\"+31600000000\"", "", false); CHECK_EQ(r.rec.count("dialogs.list"), 0); // nothing to load while logged out: no "log in first" errors CHECK_EQ(r.rec.count("dialogs.folders"), 0); ttgui::Window* w = r.window("LoginDialog"); REQUIRE(w != nullptr); r.type(r.edit(w), "12345"); r.click(w, "Next"); w = r.window("LoginDialog"); REQUIRE(w != nullptr); // the fake wants the 2FA password next r.type(r.edit(w), "secret"); r.click(w, "Next"); CHECK(!r.hasWindow("LoginDialog")); CHECK(r.rec.count("dialogs.list") >= 1); // the login finished, now the chats load CHECK(has(r.screen(), "Saved Messages")); }