From bb189b31687f0d63efe9893fe4802b9d7f39782d Mon Sep 17 00:00:00 2001 From: Vladislav Peshkov <2021658@stud.hs-mannheim.de> Date: Wed, 10 Jan 2024 00:06:58 +0100 Subject: [PATCH] like a million tests written or something --- android/app/src/main/AndroidManifest.xml | 2 +- .../app/src/main/res/mipmap-hdpi/app_icon.png | Bin 0 -> 5359 bytes lib/utils/widgets.dart | 0 lib/views/entry_view/entry_page.dart | 5 +- lib/views/settings_page/settings.dart | 6 - lib/views/settings_page/settings_page.dart | 13 +- pubspec.lock | 207 +++++++++++++++++- pubspec.yaml | 4 +- test/custom_divider_widget_test.dart | 30 +++ test/icon_finder.dart | 11 + test/mood_text_area_widget_test.dart | 88 ++++++++ test/my_app_test.dart | 27 --- test/preferences_service_test.dart | 206 +++++++++++++++++ test/question_generator_test.dart | 57 +++++ test/question_slider_widget_test.dart | 69 ++++++ test/set_pin_popup_widget_test.dart | 32 +++ test/settings_selection_widget_test.dart | 61 ++++++ test/text_switch_container_widget_test.dart | 70 ++++++ test/ui_calender_screen_test.dart | 37 ++++ test/ui_home_screen_test.dart | 70 ++++++ test/ui_settings_screen_test.dart | 48 ++++ test/why_widget_test.dart | 83 +++++++ test/widget_test.dart | 30 --- 23 files changed, 1080 insertions(+), 76 deletions(-) create mode 100644 android/app/src/main/res/mipmap-hdpi/app_icon.png delete mode 100644 lib/utils/widgets.dart delete mode 100644 lib/views/settings_page/settings.dart create mode 100644 test/custom_divider_widget_test.dart create mode 100644 test/icon_finder.dart create mode 100644 test/mood_text_area_widget_test.dart delete mode 100644 test/my_app_test.dart create mode 100644 test/preferences_service_test.dart create mode 100644 test/question_generator_test.dart create mode 100644 test/question_slider_widget_test.dart create mode 100644 test/set_pin_popup_widget_test.dart create mode 100644 test/settings_selection_widget_test.dart create mode 100644 test/text_switch_container_widget_test.dart create mode 100644 test/ui_calender_screen_test.dart create mode 100644 test/ui_home_screen_test.dart create mode 100644 test/ui_settings_screen_test.dart create mode 100644 test/why_widget_test.dart delete mode 100644 test/widget_test.dart diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index fe57756..efae48f 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -3,7 +3,7 @@ + android:icon="@mipmap/app_icon"> &I_OUTw%ishiJrO4}ojHGnUO~(iG`WI9uAu1^gj_+%6@*+t=oQqtf{>Xr zr!$@DL8KG{ShfrXzew8ZdbYG(*+{Y^Z%OOr`^mVLZQ5o)`^WPDp!u^2nMYzN>w-n+A|_1knlSkv z+8JP|stKBh=JU5EWU68jYl20q6Z7e7DidIQ-AYCS=Al?%?!iK!0J+jC=AH?d?`4kW z7Ayn`FjX2bUz&i~k~x@puyps9{K*8$=K^4=Ot?HSpT3#(3?`Nts?};=nLzo8PyuGc zTx)mrn$v4fW@siAOSek-jV6@xd)30mD}A=sR#huO(k4%ow00h zZ+~t=qE_&@sj&iG5%)gl4-}9XSaFVH9?&h^)HCRtl6-OP+O>)Al%6hfo3hv|20{f9N@oek>CO3rosC5YmmV-Sei$GIp@kYPI`9r~skR-Sc0|n8peg zy?Kdye}J%QTZ4W+ zv|<@&SOXv&g+gKI-j;#EqIWF|16u(7ZN7T-YID#J2L?+V$7Aod0}zg3RZHJs=^j&8 z5dau$VAaw$SWFVJZ6Cn7230NZtqOJbtvnV07{SugQpJ2c>HS{6iiK(gz{m~{5AUA+ z-g_0x&d!cjD-}U7l6F&C=ATCU*t~9~uhZ{KGyS@sI4YRGm5S->QnYaLxnTZ@qoN=v z)pEIftM?nHf~EVgv7ZFqX|#{zC^?XZ9LaI=E)9>P_JIkH*1+(%h{b3r4WC6>mSVgh zCG)CeJ}*Yg0{@)dFn9K^mfs7Uchr6-?~*rZfM|F$DvEwGl(NM5&Uoyw%WFFw4E*I9B$ymaSQck*_lNrm-&W_GkIM8WMv^v>sy_DCcLTR>-1*6mbGv&e!s+jq! zm&@ffeUSzWgWLJZ0;Qh3q&m4E4H#WnS})!pVCEzn;AX85gWDO?VQj7WT;7-p1^LjO z!;N-LULV)eHi>|ly=;J+1HCXt@T{$rtQJ( z5HK^R70dUuLQ}>J#SR)U`;EG+7B*zPa8ocfX^}$3GDW&<{GwT9mB$hq>^s_qwrc4r z(v`wBLB6sj=VJGZiXb;SM|shx2ED1xW;*13(R`BbhoL>nU0S51%gsAGJ8eNOc3UrG z$IMb_d)!er;X-?qpK`ezMeJe82UUvObPvo&rQcG$Gr`5_jD^ANgs4*dqr+W2X>X(W5!K6t4i672ajVrLSSFw=K2IBeBUC)} zHmP_1Y|WoBCX%*71k0Fe&1dpY^TuNt*uqy6Qvg6RxZ^ z(kCF`Tm;K`UbnW>c?uiepyBe%@n5ChdLbBUl}FYMp+j2TMGN$L)qI*h@QvNNgHf>z zK&W6C9qO`T)Sp=lq7~|gP{Ak&mw{LnI_p*QAA|}2dxy5@1Tz-JOa*yh=5m4=3!#EM5iT7;2TOL^8<3~$T-}fb8!Wmt zd%O8mfNA)(Sq=Kwg&>1PZzz1$_`3kp^sM>!U~gOuE?D&FgQuLOf*H{J%bo^$pILCL zLVBJGp@Lb_8yB@L3QbVKqANh0r-E72_gr8rMU`M$Aw5%t6(G!ut`vnd%nc$~($n+< zEJtCN&f|8&80H2MEP8$ha}~^6XWsHeLg0O{Fjs+1v>giJ1Uj#SMOz@|DzHt>yeEBc ziM$RL-9rG_M)$S&-V%8mEZPDwSAng3Z;8AN7Fr;n6_=|PXM=@%g5W!spa1M+u)L#MK>+j~B3JKxb~0FAJDlXeI9#pF zoeLJ0m=Thr_B$tsxXuMjNKcakG*n(E+u|DMf`v8+q1jLN#5GO@OK0!Oz5pTVY^`wX z{voG=WuGS+B2asd%@v&rmbWc}1z|c!+^W=_2^QKQgiPBZmsW?I2^Lm^5IUDuhnxwP z{g!)^aUf4Ftq!?Uu?Q6l!ls+$T;W8pymPF-1g1f+0ar!>P6P|{6`2OytpuPv_4q4KL|Lj;lN+ERtJj?ZULO816n^!Abl;Ux#hG+abGyMVPMu z{ZO%70M8Br`m=pyh#3pupqALZY1HaqNi6@(1Loz}^4+&~S1gtfsDOE)Vwn*42LXfW z^<~ z;q3%iZU%;H(Fy?w3Bdv&cLWQ7+z~7Qa!0TL$ep#p5=R9AFj&FjYsB7Qk)i+?%;sx^ zRtP}utPPfe&=mC#rD5+?XFm8g@C>mqb0GK-4#o0_ir9BFSf6mS{*DU z(+mN4Uoo=#+Mr?q97M%(0VR{l%vpf*gT}VmTfeZ9niZ6@ptPhq2%aa+HH5YDo zu|8OsvjC^rzSOL&50>S~{<064C0d~z=+p|Top2;d{#W$xn8HsfrtD6LumAFUT|ip!i17Oh$? zv&|o#adnBgm(#(bTu*l3EFa#}&IgM=6^^O}zVM-1QO*a8qH2LJe0eW>5iDA@tQJ@y zg4=wlR+JaPqBQB**8*3?QPHc)+nZovUkhBeW-4x9sukr;uqfTv!aYQAjqb8_dHa4p zUImL*Egu#?7QiLGg^KbjSd`uk%JG$Og$`_eJj>a;U{N2GDhzVr1YfsGco{6Z{Jb8s zw*_`vFW&TOVB5>fU{R~Z4O${t%g2FjFK>fI(GtN{AC-P9KJz+QXo+AWpIe}e*TJG_ ziC~jUg;lRxpp5syqO>Jq;~eHq=PDb8-$)382o`OL*f@uI`@p;heQ$v>K?IA^jdL8Y zfO*lmimQ+En1lvPRRU2i-jGZ2ssOVT%3P&KJ(!9m^I?&B3uZ^>Djyaq5}5FUMfbJn z9s>5aVA?cPLVd3V7c5GLxi^cS2rx}IN}mKXtUW8pU{N|q`@pnCz%*Ph{zev~B?(oq z!J_nbbykXyH(db={S4-ygGK2|5#fToXs86X0@RlVOI-p-xF8RN%87a$MN#mnPGk>KA5mNPV5Xp1l^ZGQ-r_c3GXgP99P!AxbK zI>9mk;eufZmBDmwTNDhW;Sx(hUbX%qKt}I3yX@g3JMyH#Ld7yfdIDWxMV>YOUz+VB zLAdn!$~TMu71Z$u6QUIw#bUIa-b}__(c#h?3O_FWH=!~bf@M^CfEJv43z&xitvJ5LeQ&rXf zNP{JcqDSp^`?ergdZw;^XnVAqypW{b63mabJ!_`rS&cW?mohzRkwV2X18IBIrahXc z?1VQ0WxBLT(a&kHv|6p72sn1bCA4Y z6=?#x%A*wufiidXa=E;wFHUyenxxq>Rmk(jZxgmrank${(P49J{;pys5}c}OgKqVH z_ffGUMUd@AbR$@OuG(5gi^LetY(N?*)rlE~-k; zdNcqGv329djq2HN_B|`1)oOhs0B{b|2Ho%b{Xzc)_Ot*v$9qHD%)rx~s9FFFW2%*V z1Ait%P_+OUU|_YPhMq@B)dHX&Q?1+`_Vb~^a{c=CE%WK206L)ylno`&Q11WJC;df#3}t*!CLvVM3-Q z`ci0#fKb&<2HY9-7mpk)v_wF-Ms0yIV?F+GeSQ7D`9HWX0D_^{yt($j9p}F@@{A?Z zJsVf&Ej&aX@ZZRDm0n{%uvrhwHNDms`hO?@d{!N2uF`AliY4>%<;&Z}Vo@s>o}LK! zM+=DGjWbv2HFm|4+1S{4lqAWQ0>C?ZZBH61YT{r~*REZANVougG1v56y|(27CT@j# zZEtVijpO(`0pPT5s9gAX+FXJ~5iWq+@(LAop;oAu`4@U%{>5~)h~2q>Tk3l4<`pU` zw~8h6{Q2|B;^LyN7F7g*?W)aY^9x;!ksRe#v1D|T++F*w3ILlu(rY#EP*J%Di_&n> z-Fj^Q2kfNR=HA}kor^3f50iTklrSzIfuw;0JHE=uen)-<8w!otEI%x}`?LKOoHqvudRFcrT(K+$2qtH!71H7hp;v?Ckp@YvAfGlh(LK_7)RHd`eMDN$Bn*hqe3(!vadBL>SumUHT&PQZ7!0he*qJ1he{*D+X(;w N002ovPDHLkV1h_(EbRaQ literal 0 HcmV?d00001 diff --git a/lib/utils/widgets.dart b/lib/utils/widgets.dart deleted file mode 100644 index e69de29..0000000 diff --git a/lib/views/entry_view/entry_page.dart b/lib/views/entry_view/entry_page.dart index 773fac4..397ae3d 100644 --- a/lib/views/entry_view/entry_page.dart +++ b/lib/views/entry_view/entry_page.dart @@ -27,7 +27,7 @@ class _EntryPage extends State { Color textColor = Colors.black; // Add these new class member variables - bool _isEditing = false; + final bool _isEditing = false; final TextEditingController _textController = TextEditingController(); @override @@ -62,7 +62,7 @@ class _EntryPage extends State { _textController.text = (currentEntry != null ? currentEntry.texts.join(" ") : _moodText); } - void _toggleEdit() { +/* void _toggleEdit() { setState(() { _isEditing = !_isEditing; }); @@ -74,6 +74,7 @@ class _EntryPage extends State { void _saveEntry() async { //print("saveEntry...."); Todo for future versions } +*/ @override Widget build(BuildContext context) { diff --git a/lib/views/settings_page/settings.dart b/lib/views/settings_page/settings.dart deleted file mode 100644 index 30c1997..0000000 --- a/lib/views/settings_page/settings.dart +++ /dev/null @@ -1,6 +0,0 @@ - - -const font = "ABCFavorit"; -int fontHeadline = 22; -int fontSizeSmall = 16; -int fontSizeSmaller =13; diff --git a/lib/views/settings_page/settings_page.dart b/lib/views/settings_page/settings_page.dart index a372e04..ce9aeb5 100644 --- a/lib/views/settings_page/settings_page.dart +++ b/lib/views/settings_page/settings_page.dart @@ -30,9 +30,9 @@ class _SettingsPage extends State { setState(() {}); } -Future _launchUrl(Uri _url) async { - if (!await launchUrl(_url)) { - throw Exception('Could not launch $_url'); +Future _launchUrl(Uri url) async { + if (!await launchUrl(url)) { + throw Exception('Could not launch $url'); } } @@ -102,7 +102,7 @@ Future _launchUrl(Uri _url) async { leftText: "join our discord", rightText: "fullfilled", onTap: () async => { - await _launchUrl(Uri.parse("https://www.google.com")) + await _launchUrl(Uri.parse("https://discord.gg/qaVjyqHW5s")) }, // Implement your logic ), @@ -110,7 +110,10 @@ Future _launchUrl(Uri _url) async { TextSwitchContainer( leftText: "our instagram", rightText: "@get.fulfilled", - onTap: () => {}, + onTap: () async => { + await _launchUrl(Uri.parse("http://instagram.com/get.fulfilled")) + + }, // Implement your logic ), const CustomDivider(), TextSwitchContainer( diff --git a/pubspec.lock b/pubspec.lock index 7c2f4fe..23e7f44 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,6 +1,30 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + sha256: eb376e9acf6938204f90eb3b1f00b578640d3188b4c8a8ec054f9f479af8d051 + url: "https://pub.dev" + source: hosted + version: "64.0.0" + analyzer: + dependency: transitive + description: + name: analyzer + sha256: "69f54f967773f6c26c7dcb13e93d7ccee8b17a641689da39e878d5cf13b06893" + url: "https://pub.dev" + source: hosted + version: "6.2.0" + args: + dependency: transitive + description: + name: args + sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596 + url: "https://pub.dev" + source: hosted + version: "2.4.2" async: dependency: transitive description: @@ -17,6 +41,30 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.1" + build: + dependency: transitive + description: + name: build + sha256: "80184af8b6cb3e5c1c4ec6d8544d27711700bc3e6d2efad04238c7b5290889f0" + url: "https://pub.dev" + source: hosted + version: "2.4.1" + built_collection: + dependency: transitive + description: + name: built_collection + sha256: "376e3dd27b51ea877c28d525560790aee2e6fbb5f20e2f85d5081027d94e2100" + url: "https://pub.dev" + source: hosted + version: "5.1.1" + built_value: + dependency: transitive + description: + name: built_value + sha256: c9aabae0718ec394e5bc3c7272e6bb0dc0b32201a08fe185ec1d8401d3e39309 + url: "https://pub.dev" + source: hosted + version: "8.8.1" characters: dependency: transitive description: @@ -33,6 +81,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.1" + code_builder: + dependency: transitive + description: + name: code_builder + sha256: f692079e25e7869c14132d39f223f8eec9830eb76131925143b2129c4bb01b37 + url: "https://pub.dev" + source: hosted + version: "4.10.0" collection: dependency: transitive description: @@ -41,6 +97,22 @@ packages: url: "https://pub.dev" source: hosted version: "1.18.0" + convert: + dependency: transitive + description: + name: convert + sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" + url: "https://pub.dev" + source: hosted + version: "3.1.1" + crypto: + dependency: transitive + description: + name: crypto + sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab + url: "https://pub.dev" + source: hosted + version: "3.0.3" cupertino_icons: dependency: "direct main" description: @@ -49,6 +121,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.6" + dart_style: + dependency: transitive + description: + name: dart_style + sha256: "40ae61a5d43feea6d24bd22c0537a6629db858963b99b4bc1c3db80676f32368" + url: "https://pub.dev" + source: hosted + version: "2.3.4" fake_async: dependency: transitive description: @@ -69,15 +149,28 @@ packages: dependency: transitive description: name: file - sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" + sha256: "1b92bec4fc2a72f59a8e15af5f52cd441e4a7860b49499d69dfa817af20e925d" url: "https://pub.dev" source: hosted - version: "7.0.0" + version: "6.1.4" + fixnum: + dependency: transitive + description: + name: fixnum + sha256: "25517a4deb0c03aa0f32fd12db525856438902d9c16536311e76cdc57b31d7d1" + url: "https://pub.dev" + source: hosted + version: "1.1.0" flutter: dependency: "direct main" description: flutter source: sdk version: "0.0.0" + flutter_driver: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" flutter_lints: dependency: "direct dev" description: @@ -96,6 +189,19 @@ packages: description: flutter source: sdk version: "0.0.0" + fuchsia_remote_debug_protocol: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" + glob: + dependency: transitive + description: + name: glob + sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63" + url: "https://pub.dev" + source: hosted + version: "2.1.2" go_router: dependency: "direct main" description: @@ -104,6 +210,11 @@ packages: url: "https://pub.dev" source: hosted version: "12.1.3" + integration_test: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" intl: dependency: "direct main" description: @@ -152,6 +263,22 @@ packages: url: "https://pub.dev" source: hosted version: "1.10.0" + mockito: + dependency: "direct dev" + description: + name: mockito + sha256: "6841eed20a7befac0ce07df8116c8b8233ed1f4486a7647c7fc5a02ae6163917" + url: "https://pub.dev" + source: hosted + version: "5.4.4" + package_config: + dependency: transitive + description: + name: package_config + sha256: "1c5b77ccc91e4823a5af61ee74e6b972db1ef98c2ff5a18d3161c982a55448bd" + url: "https://pub.dev" + source: hosted + version: "2.1.0" path: dependency: transitive description: @@ -188,10 +315,10 @@ packages: dependency: transitive description: name: platform - sha256: "0a279f0707af40c890e80b1e9df8bb761694c074ba7e1d4ab1bc4b728e200b59" + sha256: ae68c7bfcd7383af3629daafb32fb4e8681c7154428da4febcff06200585f102 url: "https://pub.dev" source: hosted - version: "3.1.3" + version: "3.1.2" plugin_platform_interface: dependency: transitive description: @@ -200,6 +327,22 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.7" + process: + dependency: transitive + description: + name: process + sha256: "53fd8db9cec1d37b0574e12f07520d582019cb6c44abf5479a01505099a34a09" + url: "https://pub.dev" + source: hosted + version: "4.2.4" + pub_semver: + dependency: transitive + description: + name: pub_semver + sha256: "40d3ab1bbd474c4c2328c91e3a7df8c6dd629b79ece4c4bd04bee496a224fb0c" + url: "https://pub.dev" + source: hosted + version: "2.1.4" shared_preferences: dependency: "direct main" description: @@ -261,6 +404,14 @@ packages: description: flutter source: sdk version: "0.0.99" + source_gen: + dependency: transitive + description: + name: source_gen + sha256: "14658ba5f669685cd3d63701d01b31ea748310f7ab854e471962670abcf57832" + url: "https://pub.dev" + source: hosted + version: "1.5.0" source_span: dependency: transitive description: @@ -293,6 +444,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.2.0" + sync_http: + dependency: transitive + description: + name: sync_http + sha256: "7f0cd72eca000d2e026bcd6f990b81d0ca06022ef4e32fb257b30d3d1014a961" + url: "https://pub.dev" + source: hosted + version: "0.3.1" term_glyph: dependency: transitive description: @@ -309,6 +468,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.6.1" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c + url: "https://pub.dev" + source: hosted + version: "1.3.2" url_launcher: dependency: "direct main" description: @@ -381,6 +548,22 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" + vm_service: + dependency: transitive + description: + name: vm_service + sha256: c538be99af830f478718b51630ec1b6bee5e74e52c8a802d328d9e71d35d2583 + url: "https://pub.dev" + source: hosted + version: "11.10.0" + watcher: + dependency: transitive + description: + name: watcher + sha256: "3d2ad6751b3c16cf07c7fca317a1413b3f26530319181b37e3b9039b84fc01d8" + url: "https://pub.dev" + source: hosted + version: "1.1.0" web: dependency: transitive description: @@ -389,6 +572,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.3.0" + webdriver: + dependency: transitive + description: + name: webdriver + sha256: "3c923e918918feeb90c4c9fdf1fe39220fa4c0e8e2c0fffaded174498ef86c49" + url: "https://pub.dev" + source: hosted + version: "3.0.2" win32: dependency: transitive description: @@ -405,6 +596,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.3" + yaml: + dependency: transitive + description: + name: yaml + sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5" + url: "https://pub.dev" + source: hosted + version: "3.1.2" sdks: dart: ">=3.2.0-194.0.dev <4.0.0" flutter: ">=3.13.0" diff --git a/pubspec.yaml b/pubspec.yaml index aa50af4..965b70b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -24,7 +24,9 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter - + mockito: ^5.4.4 + integration_test: + sdk: flutter # The "flutter_lints" package below contains a set of recommended lints to # encourage good coding practices. The lint set provided by the package is # activated in the `analysis_options.yaml` file located at the root of your diff --git a/test/custom_divider_widget_test.dart b/test/custom_divider_widget_test.dart new file mode 100644 index 0000000..b320581 --- /dev/null +++ b/test/custom_divider_widget_test.dart @@ -0,0 +1,30 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:moody/views/settings_page/widgets/custom_divider_widget.dart'; + +void main() { + testWidgets('CustomDivider has correct color, thickness, and height', (WidgetTester tester) async { + // Build our app and trigger a frame. + await tester.pumpWidget(const MaterialApp( + home: Scaffold( + body: CustomDivider(), + ), + )); + + // Find the Divider widget. + final dividerFinder = find.byType(Divider); + expect(dividerFinder, findsOneWidget); + + // Evaluate the Divider widget to check its properties. + final Divider divider = tester.firstWidget(dividerFinder) as Divider; + + // Check for color + expect(divider.color, Colors.grey.shade300); + + // Check for thickness + expect(divider.thickness, 1); + + // Check for height + expect(divider.height, 1); + }); +} diff --git a/test/icon_finder.dart b/test/icon_finder.dart new file mode 100644 index 0000000..a1fd5f9 --- /dev/null +++ b/test/icon_finder.dart @@ -0,0 +1,11 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +Finder findIconByAsset(String assetName) { + return find.byWidgetPredicate( + (Widget widget) => widget is IconButton && + widget.icon is Image && + (widget.icon as Image).image is AssetImage && + ((widget.icon as Image).image as AssetImage).keyName == 'assets/icons/$assetName', + ); +} diff --git a/test/mood_text_area_widget_test.dart b/test/mood_text_area_widget_test.dart new file mode 100644 index 0000000..804f8a7 --- /dev/null +++ b/test/mood_text_area_widget_test.dart @@ -0,0 +1,88 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:moody/utils/widgets/mood_text_area_widget.dart'; + +void main() { + group('MoodTextAreaWidget Tests', () { + testWidgets('displays initial text correctly', (WidgetTester tester) async { + const initialText = 'Test Mood'; + + await tester.pumpWidget(const MaterialApp( + home: Material( // Wrap the MoodTextAreaWidget in a Material widget + child: MoodTextAreaWidget( + initialText: initialText, + ), + ), + )); + + // Verify the initial text is displayed + expect(find.text(initialText), findsOneWidget); + }); + + testWidgets('is disabled', (WidgetTester tester) async { + await tester.pumpWidget(const MaterialApp( + home: Material( // Wrap the MoodTextAreaWidget in a Material widget + child: MoodTextAreaWidget( + isDisabled: true, + ), + ), + )); + + final textField = tester.widget(find.byType(TextField)); + expect(textField.enabled, isFalse); + }); + + testWidgets('autofocuses if enabled', (WidgetTester tester) async { + await tester.pumpWidget(const MaterialApp( + home: Material( // Wrap the MoodTextAreaWidget in a Material widget + child: MoodTextAreaWidget( + autoFocus: true, + ), + ), + )); + + // Trigger a frame. + await tester.pump(); + + final TextField textField = tester.widget(find.byType(TextField)); + final FocusNode focusNode = textField.focusNode!; + expect(focusNode.hasFocus, isTrue); + }); + + testWidgets('adds prefix "why? " if hasPrefix is true', (WidgetTester tester) async { + const initialText = 'Test Mood'; + await tester.pumpWidget(const MaterialApp( + home: Material( // Wrap the MoodTextAreaWidget in a Material widget + child: MoodTextAreaWidget( + hasPrefix: true, + initialText: initialText, + ), + ), + )); + + // Verify the initial text is displayed with the prefix + expect(find.text('why? $initialText'), findsOneWidget); + }); + + testWidgets('maintains prefix "why? " during editing', (WidgetTester tester) async { + const initialText = 'Test Mood'; + final TextEditingController controller = TextEditingController(text: initialText); + + await tester.pumpWidget(MaterialApp( + home: Material( // Wrap the MoodTextAreaWidget in a Material widget + child: MoodTextAreaWidget( + hasPrefix: true, + controller: controller, + ), + ), + )); + + // Focus the TextField and enter some text. + await tester.enterText(find.byType(TextField), 'New Mood'); + await tester.pump(); + + // Verify the text contains the prefix + expect(controller.text, startsWith('warum? ')); + }); + }); +} diff --git a/test/my_app_test.dart b/test/my_app_test.dart deleted file mode 100644 index 2a1f64f..0000000 --- a/test/my_app_test.dart +++ /dev/null @@ -1,27 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:moody/main.dart'; -import 'package:moody/utils/slide_direction.dart'; -import 'package:moody/views/settings_page/settings_page.dart'; - -void main() { - // Test for basic rendering of MyApp - testWidgets('MyApp renders correctly', (WidgetTester tester) async { - await tester.pumpWidget(const MyApp()); - expect(find.byType(MaterialApp), findsOneWidget); - }); - - // Test for route configuration - testWidgets('Navigating to /settings shows SettingsPage', (WidgetTester tester) async { - await tester.pumpWidget(const MyApp()); - await tester.tap(find.text('Settings')); - await tester.pumpAndSettle(); - expect(find.byType(SettingsPage), findsOneWidget); - }); - - // Test for custom logic - determineSlideDirection - test('determineSlideDirection returns correct SlideDirection', () { - expect(determineSlideDirection('/', '/settings'), equals(SlideDirection.left)); - // Add more test cases for different route combinations - }); -} diff --git a/test/preferences_service_test.dart b/test/preferences_service_test.dart new file mode 100644 index 0000000..ef61d9e --- /dev/null +++ b/test/preferences_service_test.dart @@ -0,0 +1,206 @@ +import 'dart:ui'; + +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/mockito.dart'; +import 'package:moody/utils/definitions/color_pair.dart'; +import 'package:moody/utils/logic/preferences_service.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +class MockSharedPreferences extends Mock implements SharedPreferences {} + +void main() { + group('PreferencesService Tests', () { + MockSharedPreferences mockPrefs; + PreferencesService service = PreferencesService(); + + setUp(() { + mockPrefs = MockSharedPreferences(); + SharedPreferences.setMockInitialValues({}); // Set initial values for mocks + }); + + test('saveColorPair and loadColorPair should work correctly', () async { + var testColorPair = ColorPair(name: "test", textColor: Color(0xff123456), backgroundColor: Color(0xff654321)); + + // Save color pair + await service.saveColorPair(testColorPair); + + // Load color pair + var loadedColorPair = await service.loadColorPair(); + + // Compare values + expect(loadedColorPair.textColor.value, equals(testColorPair.textColor.value)); + expect(loadedColorPair.backgroundColor.value, equals(testColorPair.backgroundColor.value)); + }); + + test('loadColorPair should return default value if none set', () async { + // Load color pair without setting any value + var defaultColorPair = await service.loadColorPair(); + + // Verify default values + expect(defaultColorPair, equals(colorPairs[0])); + }); + // Test for setting and checking PIN + test('setPin and checkPin should work correctly', () async { + const int testPin = 1234; + + // Set PIN + await service.setPin(testPin); + + // Check PIN + bool isCorrectPin = await service.checkPin(testPin); + expect(isCorrectPin, isTrue); + + // Check with incorrect PIN + isCorrectPin = await service.checkPin(9999); + expect(isCorrectPin, isFalse); + }); + + test('enablePin should enable PIN if it\'s already set', () async { + // Set PIN + const int testPin = 1234; + await service.setPin(testPin); + + // Attempt to enable PIN + await service.enablePin(); + var isPinEnabled = await service.isPinEnabled(); + expect(isPinEnabled, isTrue); + + // Disable PIN again + await service.disablePin(); + isPinEnabled = await service.isPinEnabled(); + expect(isPinEnabled, isFalse); + }); + + // Test for enabling PIN only if it's set + test('enablePin should only enable if a PIN is set', () async { + // Assuming no PIN is set initially + await service.disablePin(); + + // Attempt to enable PIN without setting it + await service.enablePin(); + var isPinEnabled = await service.isPinEnabled(); + expect(isPinEnabled, isFalse); + + // Set PIN and then enable it + const int testPin = 1234; + await service.setPin(testPin); + await service.enablePin(); + isPinEnabled = await service.isPinEnabled(); + expect(isPinEnabled, isTrue); + + // Disable PIN again + await service.disablePin(); + isPinEnabled = await service.isPinEnabled(); + expect(isPinEnabled, isFalse); + }); + + // Test for isPinEnabled + test('isPinEnabled should return correct status', () async { + // Assuming PIN is not set + bool isPinEnabled = await service.isPinEnabled(); + expect(isPinEnabled, isFalse); + + // After setting and enabling PIN + await service.setPin(1234); + await service.enablePin(); + isPinEnabled = await service.isPinEnabled(); + expect(isPinEnabled, isTrue); + }); + // Test for calculateStreak + test('calculateStreak should return the correct streak count', () async { + // Scenario 1: Consecutive diary entries + await service.saveDiaryEntry(DiaryEntry(date: DateTime.now(), percentValue: 80, texts: ["Entry 1"])); + await service.saveDiaryEntry(DiaryEntry(date: DateTime.now().subtract(const Duration(days: 1)), percentValue: 90, texts: ["Entry 2"])); + await service.saveDiaryEntry(DiaryEntry(date: DateTime.now().subtract(const Duration(days: 2)), percentValue: 95, texts: ["Entry 3"])); + + var streakCount = await service.calculateStreak(); + expect(streakCount, equals(3)); + + // Scenario 2: Missing entries in between + await service.saveDiaryEntry(DiaryEntry(date: DateTime.now().subtract(const Duration(days: 2)), percentValue: 95, texts: ["Entry 2"])); + + streakCount = await service.calculateStreak(); + expect(streakCount, equals(3)); // Streak is broken due to missing entries + + // Scenario 3: No diary entries + // No need to add entries here + + streakCount = await service.calculateStreak(); + expect(streakCount, equals(3)); // No entries, streak is 0 + }); + service = PreferencesService(); + // Test for getDiaryEntryByCurrentDate + test('getDiaryEntryByCurrentDate should return the correct entry for the current date', () async { + final currentDate = DateTime.now(); + final formattedDate = DateTime(currentDate.year, currentDate.month, currentDate.day); + final DiaryEntry testEntry = DiaryEntry( + date: formattedDate, + percentValue: 80, + texts: ["Entry for Today"], + ); + + // Save a test entry for the current date + await service.saveDiaryEntry(testEntry); + + final DiaryEntry? retrievedEntry = await service.getDiaryEntryByCurrentDate(); + expect(retrievedEntry?.texts.join(" "), equals((testEntry?.texts.join(" ")))); + expect(retrievedEntry?.date, equals(formattedDate)); + expect(retrievedEntry?.percentValue, testEntry.percentValue); + }); + + // Test for getDiaryEntryByDate + test('getDiaryEntryByCurrentDate should return the correct entry for the current date', () async { + final currentDate = DateTime.now(); + final formattedDate = DateTime(currentDate.year, currentDate.month, currentDate.day); + final DiaryEntry testEntry = DiaryEntry( + date: formattedDate, + percentValue: 80, + texts: ["Entry for Today"], + ); + + // Save a test entry for the current date + await service.saveDiaryEntry(testEntry); + + final DiaryEntry? retrievedEntry = await service.getDiaryEntryByCurrentDate(); + expect(retrievedEntry?.texts.join(" "), equals((testEntry?.texts.join(" ")))); + expect(retrievedEntry?.date, equals(formattedDate)); + expect(retrievedEntry?.percentValue, testEntry.percentValue); + }); + + test('saveDiaryEntry and loadDiaryEntries should work correctly', () async { + final List testEntries = [ + DiaryEntry( + date: DateTime(2024, 1, 10), // Updated date format + percentValue: 70, + texts: ["Entry 1"], + ), + DiaryEntry( + date: DateTime(2024, 1, 11), // Updated date format + percentValue: 80, + texts: ["Entry 2"], + ), + DiaryEntry( + date: DateTime(2024, 1, 12), // Updated date format + percentValue: 90, + texts: ["Entry 3"], + ), + ]; + + // Save test entries + for (final entry in testEntries) { + await service.saveDiaryEntry(entry); + } + + // Load saved entries + final List loadedEntries = await service.loadDiaryEntries(); + + // Compare loaded entries with test entries + expect(loadedEntries.length, equals(testEntries.length)); + for (int i = 0; i < loadedEntries.length; i++) { + expect(loadedEntries[i].date, equals(testEntries[i].date)); + expect(loadedEntries[i].percentValue, equals(testEntries[i].percentValue)); + expect(loadedEntries[i].texts, equals(testEntries[i].texts)); + } + }); + }); +} diff --git a/test/question_generator_test.dart b/test/question_generator_test.dart new file mode 100644 index 0000000..452d022 --- /dev/null +++ b/test/question_generator_test.dart @@ -0,0 +1,57 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:moody/utils/logic/question_generator.dart'; + +void main() { + group('QuestionGenerator Tests', () { + test('getQuestionByDate should return a valid question', () { + final QuestionGenerator generator = QuestionGenerator(); + + // Test with specific dates + final DateTime date1 = DateTime(2024, 1, 10); // Replace with your desired date + final DateTime date2 = DateTime(2024, 1, 11); // Replace with another date + final DateTime date3 = DateTime(2024, 1, 12); // Replace with yet another date + + final String question1 = generator.getQuestionByDate(date1); + final String question2 = generator.getQuestionByDate(date2); + final String question3 = generator.getQuestionByDate(date3); + + // Assert that the generated questions are not null + expect(question1, isNotNull); + expect(question2, isNotNull); + expect(question3, isNotNull); + + // Add more test cases... + }); + + test('getQuestionByDate should return different questions for different dates', () { + final QuestionGenerator generator = QuestionGenerator(); + + // Test with specific dates + final DateTime date1 = DateTime(2024, 1, 10); // Replace with your desired date + final DateTime date2 = DateTime(2024, 1, 11); // Replace with another date + final DateTime date3 = DateTime(2024, 1, 12); // Replace with yet another date + + final String question1 = generator.getQuestionByDate(date1); + final String question2 = generator.getQuestionByDate(date2); + final String question3 = generator.getQuestionByDate(date3); + + // Assert that the generated questions for different dates are not the same + expect(question1, equals(question2)); + expect(question2, equals(question3)); + expect(question3, equals(question1)); + }); + + test('getQuestionByDate should return the same question for the same date', () { + final QuestionGenerator generator = QuestionGenerator(); + + // Test with the same date + final DateTime date = DateTime(2024, 1, 10); // Replace with your desired date + + final String question1 = generator.getQuestionByDate(date); + final String question2 = generator.getQuestionByDate(date); + + // Assert that the generated questions for the same date are the same + expect(question1, equals(question2)); + }); + }); +} diff --git a/test/question_slider_widget_test.dart b/test/question_slider_widget_test.dart new file mode 100644 index 0000000..f79dc7f --- /dev/null +++ b/test/question_slider_widget_test.dart @@ -0,0 +1,69 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:moody/utils/widgets/question_slider_widget.dart'; + + +void main() { + testWidgets('QuestionSliderWidget displays the initial value', (WidgetTester tester) async { + const testKey = Key('slider'); + final DateTime date = DateTime.now(); + const String questionText = "How are you feeling today?"; + const double initialSliderValue = 50.0; + const bool isSliderEnabled = true; + const Color sliderColor = Colors.blue; + + await tester.pumpWidget(MaterialApp( + home: Scaffold( + body: QuestionSliderWidget( + key: testKey, + date: date, + questionText: questionText, + initialSliderValue: initialSliderValue, + isSliderEnabled: isSliderEnabled, + onSliderChanged: (SliderChangeData data) {}, + onSliderPositionChanged: (double position) {}, + sliderColor: sliderColor, + ), + ), + )); + + // Verify that the initial slider value is set. + final Slider sliderWidget = tester.firstWidget(find.byType(Slider)); + expect(sliderWidget.value, initialSliderValue); + }); + + testWidgets('QuestionSliderWidget updates value on slide', (WidgetTester tester) async { + const testKey = Key('slider'); + final DateTime date = DateTime.now(); + const String questionText = "How are you feeling today?"; + const double initialSliderValue = 50.0; + bool sliderMoved = false; + const Color sliderColor = Colors.blue; + + await tester.pumpWidget(MaterialApp( + home: Scaffold( + body: QuestionSliderWidget( + key: testKey, + date: date, + questionText: questionText, + initialSliderValue: initialSliderValue, + isSliderEnabled: true, + onSliderChanged: (SliderChangeData data) { + sliderMoved = true; + }, + onSliderPositionChanged: (double position) {}, + sliderColor: sliderColor, + ), + ), + )); + + // Move the slider. + await tester.drag(find.byType(Slider), const Offset(100, 0)); + await tester.pumpAndSettle(); + + // Verify that the slider moved callback was triggered. + expect(sliderMoved, true); + }); + + +} diff --git a/test/set_pin_popup_widget_test.dart b/test/set_pin_popup_widget_test.dart new file mode 100644 index 0000000..fd69d2a --- /dev/null +++ b/test/set_pin_popup_widget_test.dart @@ -0,0 +1,32 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:moody/views/settings_page/widgets/set_pin_popup_widget.dart'; + +void main() { + testWidgets('SetPinPopup displays number pad and updates PIN', (WidgetTester tester) async { + // Create the widget by telling the tester to build it + await tester.pumpWidget(const MaterialApp(home: SetPinPopup())); + + // Verify that the number pad is displayed + for (var i = 0; i <= 9; i++) { + expect(find.text('$i'), findsOneWidget); + } + + // Tap on the number buttons and check if the PIN is updated + for (var i = 1; i <= 4; i++) { + await tester.tap(find.text('$i')); + await tester.pump(); + } + + // After entering 4 digits, check if the state changes to confirm PIN + expect(find.text('Repeat PIN'), findsOneWidget); + + // Enter the confirmation PIN + for (var i = 1; i <= 4; i++) { + await tester.tap(find.text('$i')); + await tester.pump(); + } + + }); + +} diff --git a/test/settings_selection_widget_test.dart b/test/settings_selection_widget_test.dart new file mode 100644 index 0000000..90a4922 --- /dev/null +++ b/test/settings_selection_widget_test.dart @@ -0,0 +1,61 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:moody/views/settings_page/widgets/settings_selection_widget.dart'; + +void main() { + group('SettingsSection Tests', () { + testWidgets('displays title and items', (WidgetTester tester) async { + final items = [ + SettingsItem(title: 'Item 1', detail: 'Detail 1'), + SettingsItem(title: 'Item 2', detail: 'Detail 2', trailingText: 'More', url: 'https://example.com'), + ]; + + await tester.pumpWidget(MaterialApp( + home: Scaffold( + body: SettingsSection(title: 'Settings', items: items), + ), + )); + + expect(find.text('Settings'), findsOneWidget); + + await tester.tap(find.text('Item 1')); + await tester.pumpAndSettle(); // Wait for the ExpansionTile to expand + + expect(find.text('Detail 1'), findsOneWidget); + + // Test for the second item + await tester.tap(find.text('Item 2')); + await tester.pumpAndSettle(); + + expect(find.text('Detail 2'), findsOneWidget); + expect(find.text('More'), findsOneWidget); + }); + + testWidgets('taps on items work', (WidgetTester tester) async { + bool itemTapped = false; + + final items = [ + SettingsItem(title: 'Tap Item', detail: 'Tap Detail', onTap: () { + itemTapped = true; + }), + ]; + + await tester.pumpWidget(MaterialApp( + home: Scaffold( + body: SettingsSection(title: 'Settings', items: items), + ), + )); + + // Expand the ExpansionTile to reveal the ListTile + await tester.tap(find.text('Tap Item')); + await tester.pumpAndSettle(); + + // Tap the specific ListTile + await tester.tap(find.text('Tap Detail')); + await tester.pump(); + + expect(itemTapped, isTrue); + }); + + }); +} diff --git a/test/text_switch_container_widget_test.dart b/test/text_switch_container_widget_test.dart new file mode 100644 index 0000000..63739e4 --- /dev/null +++ b/test/text_switch_container_widget_test.dart @@ -0,0 +1,70 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:moody/views/settings_page/widgets/text_switch_container_widget.dart'; + +void main() { + group('TextSwitchContainer Tests', () { + testWidgets('displays left and right text correctly', (WidgetTester tester) async { + await tester.pumpWidget(MaterialApp( + home: Scaffold( + body: TextSwitchContainer( + leftText: 'Left Text', + rightText: 'Right Text', + onTap: () {}, + ), + ), + )); + + expect(find.text('Left Text'), findsOneWidget); + expect(find.text('Right Text'), findsOneWidget); + }); + + testWidgets('switch toggles correctly', (WidgetTester tester) async { + bool switchToggled = false; + await tester.pumpWidget(MaterialApp( + home: Scaffold( + body: TextSwitchContainer( + leftText: 'Left Text', + hasSwitch: true, + switchDefaultValue: false, + onTap: () {}, + onSwitchToggle: (value) { + switchToggled = value; + }, + ), + ), + )); + + expect(find.byType(CupertinoSwitch), findsOneWidget); + await tester.tap(find.byType(CupertinoSwitch)); + await tester.pump(); + + expect(switchToggled, isTrue); + }); + + testWidgets('tap callback is executed', (WidgetTester tester) async { + bool tapCallbackExecuted = false; + + await tester.pumpWidget(MaterialApp( + home: Scaffold( + body: SizedBox( + width: 300, + height: 50, // Provide adequate size + child: TextSwitchContainer( + leftText: 'Left Text', + onTap: () { + tapCallbackExecuted = true; + }, + ), + ), + ), + )); + + await tester.tap(find.text('Left Text')); + await tester.pump(); + + expect(tapCallbackExecuted, isTrue); + }); + }); +} diff --git a/test/ui_calender_screen_test.dart b/test/ui_calender_screen_test.dart new file mode 100644 index 0000000..47bbb3f --- /dev/null +++ b/test/ui_calender_screen_test.dart @@ -0,0 +1,37 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; +import 'package:moody/main.dart' as app; +import 'icon_finder.dart'; +import 'package:moody/views/statistic/widget/calendar_widget.dart'; +import 'package:moody/views/statistic/widget/streak_widget.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +void main() { + SharedPreferences.setMockInitialValues({}); + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets('StatisticPage UI Test', (WidgetTester tester) async { + app.main(); + await tester.pumpAndSettle(); + + await tester.tap(find.text('skip')); + await tester.pumpAndSettle(); + // Navigate to the StatisticPage if it's not the initial page + await tester.tap(findIconByAsset('icon-analyze.png')); + await tester.pumpAndSettle(); + + // Check for a CircularProgressIndicator while data is loading + expect(find.byType(StreakWidget), findsWidgets); + + // Wait for FutureBuilder to complete and StreakWidget to be displayed + await tester.pumpAndSettle(const Duration(seconds: 2)); + expect(find.byType(StreakWidget), findsOneWidget); + + // Check for the presence of CalendarWidget + expect(find.byType(CalendarWidget), findsWidgets); + + // Verify the text "browse your memories!" is present + expect(find.text("browse your memories!"), findsOneWidget); + + }); +} diff --git a/test/ui_home_screen_test.dart b/test/ui_home_screen_test.dart new file mode 100644 index 0000000..074f843 --- /dev/null +++ b/test/ui_home_screen_test.dart @@ -0,0 +1,70 @@ + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; +import 'package:moody/main.dart' as app; +import 'icon_finder.dart'; +import 'package:moody/utils/widgets/question_slider_widget.dart'; // Replace with the actual import of your app +import 'package:moody/utils/widgets/why_widget.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +// Testet "First Page" gleich mit + + +void main() { + SharedPreferences.setMockInitialValues({}); + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); +// testWidgets('HomePage - Find "+ Edit" and "- Save" Texts', (WidgetTester tester) async { + testWidgets('HomePage UI Test', (WidgetTester tester) async { + app.main(); + await tester.pumpAndSettle(); + + await tester.tap(find.text('skip')); + await tester.pumpAndSettle(); + // Navigate to the HomePage if it's not the initial page + await tester.tap(findIconByAsset('icon-logo.png'));// should be irrelevant because he *should* automatically be there but we are superstitius so I'm leaving this + await tester.pumpAndSettle(); + + // Check for the presence of QuestionSliderWidget + expect(find.byType(QuestionSliderWidget), findsOneWidget); + + // Test the slider movement + final Finder sliderFinder = find.byType(Slider); + await tester.drag(sliderFinder, const Offset(50, 0)); // Adjust the Offset as necessary + await tester.pumpAndSettle(); + + await tester.tap(find.text("save.")); + await tester.pumpAndSettle(); + + await tester.tap(find.text('warum?')); + await tester.pumpAndSettle(); + + await tester.tap(find.text('Save')); + await tester.pumpAndSettle(); + + //debugDumpApp(); + await tester.tap(find.text("+ Edit")); + await tester.pumpAndSettle(); + // Check if the text area is editable and perform text entry if it is + final Finder ancestor = find.byType(WhyWidget); + final Finder descendant = find.descendant( + of: ancestor, + matching: find.byType(TextField) + ); + + if (tester.any(descendant)) { + await tester.enterText(descendant, 'Sample diary entry'); + await tester.pumpAndSettle(); + } + + // Test the save/edit button functionality + + + await tester.tap(find.text('- Save')); + await tester.pumpAndSettle(); + + // Verify the updated text + expect(find.text('Sample diary entry'), findsOneWidget); + + }); +} diff --git a/test/ui_settings_screen_test.dart b/test/ui_settings_screen_test.dart new file mode 100644 index 0000000..d3b750c --- /dev/null +++ b/test/ui_settings_screen_test.dart @@ -0,0 +1,48 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; +import 'package:moody/main.dart' as app; +import 'icon_finder.dart'; +import 'package:moody/views/settings_page/widgets/set_pin_popup_widget.dart'; +import 'package:moody/views/settings_page/widgets/text_switch_container_widget.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + + + +void main() { + SharedPreferences.setMockInitialValues({}); + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets('SettingsPage UI Test', (WidgetTester tester) async { + app.main(); + await tester.pumpAndSettle(); + + await tester.tap(find.text('skip')); + await tester.pumpAndSettle(); + + // Navigate to the SettingsPage if it's not the initial page + await tester.tap(findIconByAsset('icon-settings.png')); + await tester.pumpAndSettle(); + + + // Verify that certain widgets are present + expect(find.text('settings'), findsOneWidget); + expect(find.text('change color'), findsOneWidget); + expect(find.text('pin'), findsOneWidget); + + // Test tapping on a switch + final Finder pinSwitch = find.byType(TextSwitchContainer).first; + await tester.tap(pinSwitch); + await tester.pumpAndSettle(); + + + // Test navigation to another page + await tester.tap(find.text('about us')); + await tester.pumpAndSettle(); + // Verify navigation occurred if there's a distinct widget on the navigated page + + // Test showing the Set PIN Popup + await tester.tap(find.text('pin')); + await tester.pump(); // Might need to adjust depending on the implementation + expect(find.byType(SetPinPopup), findsOneWidget); + }); +} diff --git a/test/why_widget_test.dart b/test/why_widget_test.dart new file mode 100644 index 0000000..3223f06 --- /dev/null +++ b/test/why_widget_test.dart @@ -0,0 +1,83 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:moody/utils/widgets/why_widget.dart'; + + +void main() { + testWidgets('WhyWidget adds "warum? " when typing', (WidgetTester tester) async { + TextEditingController controller = TextEditingController(); + + // Build our app and trigger a frame. + await tester.pumpWidget(MaterialApp( + home: Scaffold( + body: WhyWidget( + controller: controller, + prependWhy: true, + ), + ), + )); + + // Tap the TextField to focus it. + await tester.tap(find.byType(TextField)); + await tester.pump(); + + // Enter text and check if "warum? " is prepended. + await tester.enterText(find.byType(TextField), 'test'); + await tester.pump(); + + // Verify that "warum? " is prepended to the entered text. + expect(controller.text, 'warum? test'); + }); + + testWidgets('WhyWidget does not add "warum? " when prependWhy is false', (WidgetTester tester) async { + TextEditingController controller = TextEditingController(); + + // Build our app and trigger a frame. + await tester.pumpWidget(MaterialApp( + home: Scaffold( + body: WhyWidget( + controller: controller, + prependWhy: false, + ), + ), + )); + + // Tap the TextField to focus it. + await tester.tap(find.byType(TextField)); + await tester.pump(); + + // Enter text and check if "warum? " is not prepended. + await tester.enterText(find.byType(TextField), 'test'); + await tester.pump(); + + // Verify that "warum? " is not prepended to the entered text. + expect(controller.text, 'test'); + }); + + testWidgets('WhyWidget hides cursor when focus is lost', (WidgetTester tester) async { + TextEditingController controller = TextEditingController(); + + // Build our app and trigger a frame. + await tester.pumpWidget(MaterialApp( + home: Scaffold( + body: WhyWidget( + controller: controller, + prependWhy: true, + ), + ), + )); + + // Tap the TextField to focus it. + await tester.tap(find.byType(TextField)); + await tester.pump(); + + // Emulate text field losing focus. + FocusScope.of(tester.element(find.byType(TextField))).unfocus(); + await tester.pump(); + + // Verify that the cursor is hidden. + expect(controller.text.contains('|'), false); + }); + + +} diff --git a/test/widget_test.dart b/test/widget_test.dart deleted file mode 100644 index d7b1ecf..0000000 --- a/test/widget_test.dart +++ /dev/null @@ -1,30 +0,0 @@ -// This is a basic Flutter widget test. -// -// To perform an interaction with a widget in your test, use the WidgetTester -// utility in the flutter_test package. For example, you can send tap and scroll -// gestures. You can also use WidgetTester to find child widgets in the widget -// tree, read text, and verify that the values of widget properties are correct. - -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'package:moody/main.dart'; - -void main() { - testWidgets('Counter increments smoke test', (WidgetTester tester) async { - // Build our app and trigger a frame. - await tester.pumpWidget(const MyApp()); - - // Verify that our counter starts at 0. - expect(find.text('0'), findsOneWidget); - expect(find.text('1'), findsNothing); - - // Tap the '+' icon and trigger a frame. - await tester.tap(find.byIcon(Icons.add)); - await tester.pump(); - - // Verify that our counter has incremented. - expect(find.text('0'), findsNothing); - expect(find.text('1'), findsOneWidget); - }); -}