[
  {
    "path": ".gitignore",
    "content": "node_modules\n.DS_Store\n.vscode\n"
  },
  {
    "path": "COPYING",
    "content": "                    GNU AFFERO GENERAL PUBLIC LICENSE\n                       Version 3, 19 November 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The GNU Affero General Public License is a free, copyleft license for\nsoftware and other kinds of works, specifically designed to ensure\ncooperation with the community in the case of network server software.\n\n  The licenses for most software and other practical works are designed\nto take away your freedom to share and change the works.  By contrast,\nour General Public Licenses are intended to guarantee your freedom to\nshare and change all versions of a program--to make sure it remains free\nsoftware for all its users.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthem if you wish), that you receive source code or can get it if you\nwant it, that you can change the software or use pieces of it in new\nfree programs, and that you know you can do these things.\n\n  Developers that use our General Public Licenses protect your rights\nwith two steps: (1) assert copyright on the software, and (2) offer\nyou this License which gives you legal permission to copy, distribute\nand/or modify the software.\n\n  A secondary benefit of defending all users' freedom is that\nimprovements made in alternate versions of the program, if they\nreceive widespread use, become available for other developers to\nincorporate.  Many developers of free software are heartened and\nencouraged by the resulting cooperation.  However, in the case of\nsoftware used on network servers, this result may fail to come about.\nThe GNU General Public License permits making a modified version and\nletting the public access it on a server without ever releasing its\nsource code to the public.\n\n  The GNU Affero General Public License is designed specifically to\nensure that, in such cases, the modified source code becomes available\nto the community.  It requires the operator of a network server to\nprovide the source code of the modified version running there to the\nusers of that server.  Therefore, public use of a modified version, on\na publicly accessible server, gives the public access to the source\ncode of the modified version.\n\n  An older license, called the Affero General Public License and\npublished by Affero, was designed to accomplish similar goals.  This is\na different license, not a version of the Affero GPL, but Affero has\nreleased a new version of the Affero GPL which permits relicensing under\nthis license.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                       TERMS AND CONDITIONS\n\n  0. Definitions.\n\n  \"This License\" refers to version 3 of the GNU Affero General Public License.\n\n  \"Copyright\" also means copyright-like laws that apply to other kinds of\nworks, such as semiconductor masks.\n\n  \"The Program\" refers to any copyrightable work licensed under this\nLicense.  Each licensee is addressed as \"you\".  \"Licensees\" and\n\"recipients\" may be individuals or organizations.\n\n  To \"modify\" a work means to copy from or adapt all or part of the work\nin a fashion requiring copyright permission, other than the making of an\nexact copy.  The resulting work is called a \"modified version\" of the\nearlier work or a work \"based on\" the earlier work.\n\n  A \"covered work\" means either the unmodified Program or a work based\non the Program.\n\n  To \"propagate\" a work means to do anything with it that, without\npermission, would make you directly or secondarily liable for\ninfringement under applicable copyright law, except executing it on a\ncomputer or modifying a private copy.  Propagation includes copying,\ndistribution (with or without modification), making available to the\npublic, and in some countries other activities as well.\n\n  To \"convey\" a work means any kind of propagation that enables other\nparties to make or receive copies.  Mere interaction with a user through\na computer network, with no transfer of a copy, is not conveying.\n\n  An interactive user interface displays \"Appropriate Legal Notices\"\nto the extent that it includes a convenient and prominently visible\nfeature that (1) displays an appropriate copyright notice, and (2)\ntells the user that there is no warranty for the work (except to the\nextent that warranties are provided), that licensees may convey the\nwork under this License, and how to view a copy of this License.  If\nthe interface presents a list of user commands or options, such as a\nmenu, a prominent item in the list meets this criterion.\n\n  1. Source Code.\n\n  The \"source code\" for a work means the preferred form of the work\nfor making modifications to it.  \"Object code\" means any non-source\nform of a work.\n\n  A \"Standard Interface\" means an interface that either is an official\nstandard defined by a recognized standards body, or, in the case of\ninterfaces specified for a particular programming language, one that\nis widely used among developers working in that language.\n\n  The \"System Libraries\" of an executable work include anything, other\nthan the work as a whole, that (a) is included in the normal form of\npackaging a Major Component, but which is not part of that Major\nComponent, and (b) serves only to enable use of the work with that\nMajor Component, or to implement a Standard Interface for which an\nimplementation is available to the public in source code form.  A\n\"Major Component\", in this context, means a major essential component\n(kernel, window system, and so on) of the specific operating system\n(if any) on which the executable work runs, or a compiler used to\nproduce the work, or an object code interpreter used to run it.\n\n  The \"Corresponding Source\" for a work in object code form means all\nthe source code needed to generate, install, and (for an executable\nwork) run the object code and to modify the work, including scripts to\ncontrol those activities.  However, it does not include the work's\nSystem Libraries, or general-purpose tools or generally available free\nprograms which are used unmodified in performing those activities but\nwhich are not part of the work.  For example, Corresponding Source\nincludes interface definition files associated with source files for\nthe work, and the source code for shared libraries and dynamically\nlinked subprograms that the work is specifically designed to require,\nsuch as by intimate data communication or control flow between those\nsubprograms and other parts of the work.\n\n  The Corresponding Source need not include anything that users\ncan regenerate automatically from other parts of the Corresponding\nSource.\n\n  The Corresponding Source for a work in source code form is that\nsame work.\n\n  2. Basic Permissions.\n\n  All rights granted under this License are granted for the term of\ncopyright on the Program, and are irrevocable provided the stated\nconditions are met.  This License explicitly affirms your unlimited\npermission to run the unmodified Program.  The output from running a\ncovered work is covered by this License only if the output, given its\ncontent, constitutes a covered work.  This License acknowledges your\nrights of fair use or other equivalent, as provided by copyright law.\n\n  You may make, run and propagate covered works that you do not\nconvey, without conditions so long as your license otherwise remains\nin force.  You may convey covered works to others for the sole purpose\nof having them make modifications exclusively for you, or provide you\nwith facilities for running those works, provided that you comply with\nthe terms of this License in conveying all material for which you do\nnot control copyright.  Those thus making or running the covered works\nfor you must do so exclusively on your behalf, under your direction\nand control, on terms that prohibit them from making any copies of\nyour copyrighted material outside their relationship with you.\n\n  Conveying under any other circumstances is permitted solely under\nthe conditions stated below.  Sublicensing is not allowed; section 10\nmakes it unnecessary.\n\n  3. Protecting Users' Legal Rights From Anti-Circumvention Law.\n\n  No covered work shall be deemed part of an effective technological\nmeasure under any applicable law fulfilling obligations under article\n11 of the WIPO copyright treaty adopted on 20 December 1996, or\nsimilar laws prohibiting or restricting circumvention of such\nmeasures.\n\n  When you convey a covered work, you waive any legal power to forbid\ncircumvention of technological measures to the extent such circumvention\nis effected by exercising rights under this License with respect to\nthe covered work, and you disclaim any intention to limit operation or\nmodification of the work as a means of enforcing, against the work's\nusers, your or third parties' legal rights to forbid circumvention of\ntechnological measures.\n\n  4. Conveying Verbatim Copies.\n\n  You may convey verbatim copies of the Program's source code as you\nreceive it, in any medium, provided that you conspicuously and\nappropriately publish on each copy an appropriate copyright notice;\nkeep intact all notices stating that this License and any\nnon-permissive terms added in accord with section 7 apply to the code;\nkeep intact all notices of the absence of any warranty; and give all\nrecipients a copy of this License along with the Program.\n\n  You may charge any price or no price for each copy that you convey,\nand you may offer support or warranty protection for a fee.\n\n  5. Conveying Modified Source Versions.\n\n  You may convey a work based on the Program, or the modifications to\nproduce it from the Program, in the form of source code under the\nterms of section 4, provided that you also meet all of these conditions:\n\n    a) The work must carry prominent notices stating that you modified\n    it, and giving a relevant date.\n\n    b) The work must carry prominent notices stating that it is\n    released under this License and any conditions added under section\n    7.  This requirement modifies the requirement in section 4 to\n    \"keep intact all notices\".\n\n    c) You must license the entire work, as a whole, under this\n    License to anyone who comes into possession of a copy.  This\n    License will therefore apply, along with any applicable section 7\n    additional terms, to the whole of the work, and all its parts,\n    regardless of how they are packaged.  This License gives no\n    permission to license the work in any other way, but it does not\n    invalidate such permission if you have separately received it.\n\n    d) If the work has interactive user interfaces, each must display\n    Appropriate Legal Notices; however, if the Program has interactive\n    interfaces that do not display Appropriate Legal Notices, your\n    work need not make them do so.\n\n  A compilation of a covered work with other separate and independent\nworks, which are not by their nature extensions of the covered work,\nand which are not combined with it such as to form a larger program,\nin or on a volume of a storage or distribution medium, is called an\n\"aggregate\" if the compilation and its resulting copyright are not\nused to limit the access or legal rights of the compilation's users\nbeyond what the individual works permit.  Inclusion of a covered work\nin an aggregate does not cause this License to apply to the other\nparts of the aggregate.\n\n  6. Conveying Non-Source Forms.\n\n  You may convey a covered work in object code form under the terms\nof sections 4 and 5, provided that you also convey the\nmachine-readable Corresponding Source under the terms of this License,\nin one of these ways:\n\n    a) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by the\n    Corresponding Source fixed on a durable physical medium\n    customarily used for software interchange.\n\n    b) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by a\n    written offer, valid for at least three years and valid for as\n    long as you offer spare parts or customer support for that product\n    model, to give anyone who possesses the object code either (1) a\n    copy of the Corresponding Source for all the software in the\n    product that is covered by this License, on a durable physical\n    medium customarily used for software interchange, for a price no\n    more than your reasonable cost of physically performing this\n    conveying of source, or (2) access to copy the\n    Corresponding Source from a network server at no charge.\n\n    c) Convey individual copies of the object code with a copy of the\n    written offer to provide the Corresponding Source.  This\n    alternative is allowed only occasionally and noncommercially, and\n    only if you received the object code with such an offer, in accord\n    with subsection 6b.\n\n    d) Convey the object code by offering access from a designated\n    place (gratis or for a charge), and offer equivalent access to the\n    Corresponding Source in the same way through the same place at no\n    further charge.  You need not require recipients to copy the\n    Corresponding Source along with the object code.  If the place to\n    copy the object code is a network server, the Corresponding Source\n    may be on a different server (operated by you or a third party)\n    that supports equivalent copying facilities, provided you maintain\n    clear directions next to the object code saying where to find the\n    Corresponding Source.  Regardless of what server hosts the\n    Corresponding Source, you remain obligated to ensure that it is\n    available for as long as needed to satisfy these requirements.\n\n    e) Convey the object code using peer-to-peer transmission, provided\n    you inform other peers where the object code and Corresponding\n    Source of the work are being offered to the general public at no\n    charge under subsection 6d.\n\n  A separable portion of the object code, whose source code is excluded\nfrom the Corresponding Source as a System Library, need not be\nincluded in conveying the object code work.\n\n  A \"User Product\" is either (1) a \"consumer product\", which means any\ntangible personal property which is normally used for personal, family,\nor household purposes, or (2) anything designed or sold for incorporation\ninto a dwelling.  In determining whether a product is a consumer product,\ndoubtful cases shall be resolved in favor of coverage.  For a particular\nproduct received by a particular user, \"normally used\" refers to a\ntypical or common use of that class of product, regardless of the status\nof the particular user or of the way in which the particular user\nactually uses, or expects or is expected to use, the product.  A product\nis a consumer product regardless of whether the product has substantial\ncommercial, industrial or non-consumer uses, unless such uses represent\nthe only significant mode of use of the product.\n\n  \"Installation Information\" for a User Product means any methods,\nprocedures, authorization keys, or other information required to install\nand execute modified versions of a covered work in that User Product from\na modified version of its Corresponding Source.  The information must\nsuffice to ensure that the continued functioning of the modified object\ncode is in no case prevented or interfered with solely because\nmodification has been made.\n\n  If you convey an object code work under this section in, or with, or\nspecifically for use in, a User Product, and the conveying occurs as\npart of a transaction in which the right of possession and use of the\nUser Product is transferred to the recipient in perpetuity or for a\nfixed term (regardless of how the transaction is characterized), the\nCorresponding Source conveyed under this section must be accompanied\nby the Installation Information.  But this requirement does not apply\nif neither you nor any third party retains the ability to install\nmodified object code on the User Product (for example, the work has\nbeen installed in ROM).\n\n  The requirement to provide Installation Information does not include a\nrequirement to continue to provide support service, warranty, or updates\nfor a work that has been modified or installed by the recipient, or for\nthe User Product in which it has been modified or installed.  Access to a\nnetwork may be denied when the modification itself materially and\nadversely affects the operation of the network or violates the rules and\nprotocols for communication across the network.\n\n  Corresponding Source conveyed, and Installation Information provided,\nin accord with this section must be in a format that is publicly\ndocumented (and with an implementation available to the public in\nsource code form), and must require no special password or key for\nunpacking, reading or copying.\n\n  7. Additional Terms.\n\n  \"Additional permissions\" are terms that supplement the terms of this\nLicense by making exceptions from one or more of its conditions.\nAdditional permissions that are applicable to the entire Program shall\nbe treated as though they were included in this License, to the extent\nthat they are valid under applicable law.  If additional permissions\napply only to part of the Program, that part may be used separately\nunder those permissions, but the entire Program remains governed by\nthis License without regard to the additional permissions.\n\n  When you convey a copy of a covered work, you may at your option\nremove any additional permissions from that copy, or from any part of\nit.  (Additional permissions may be written to require their own\nremoval in certain cases when you modify the work.)  You may place\nadditional permissions on material, added by you to a covered work,\nfor which you have or can give appropriate copyright permission.\n\n  Notwithstanding any other provision of this License, for material you\nadd to a covered work, you may (if authorized by the copyright holders of\nthat material) supplement the terms of this License with terms:\n\n    a) Disclaiming warranty or limiting liability differently from the\n    terms of sections 15 and 16 of this License; or\n\n    b) Requiring preservation of specified reasonable legal notices or\n    author attributions in that material or in the Appropriate Legal\n    Notices displayed by works containing it; or\n\n    c) Prohibiting misrepresentation of the origin of that material, or\n    requiring that modified versions of such material be marked in\n    reasonable ways as different from the original version; or\n\n    d) Limiting the use for publicity purposes of names of licensors or\n    authors of the material; or\n\n    e) Declining to grant rights under trademark law for use of some\n    trade names, trademarks, or service marks; or\n\n    f) Requiring indemnification of licensors and authors of that\n    material by anyone who conveys the material (or modified versions of\n    it) with contractual assumptions of liability to the recipient, for\n    any liability that these contractual assumptions directly impose on\n    those licensors and authors.\n\n  All other non-permissive additional terms are considered \"further\nrestrictions\" within the meaning of section 10.  If the Program as you\nreceived it, or any part of it, contains a notice stating that it is\ngoverned by this License along with a term that is a further\nrestriction, you may remove that term.  If a license document contains\na further restriction but permits relicensing or conveying under this\nLicense, you may add to a covered work material governed by the terms\nof that license document, provided that the further restriction does\nnot survive such relicensing or conveying.\n\n  If you add terms to a covered work in accord with this section, you\nmust place, in the relevant source files, a statement of the\nadditional terms that apply to those files, or a notice indicating\nwhere to find the applicable terms.\n\n  Additional terms, permissive or non-permissive, may be stated in the\nform of a separately written license, or stated as exceptions;\nthe above requirements apply either way.\n\n  8. Termination.\n\n  You may not propagate or modify a covered work except as expressly\nprovided under this License.  Any attempt otherwise to propagate or\nmodify it is void, and will automatically terminate your rights under\nthis License (including any patent licenses granted under the third\nparagraph of section 11).\n\n  However, if you cease all violation of this License, then your\nlicense from a particular copyright holder is reinstated (a)\nprovisionally, unless and until the copyright holder explicitly and\nfinally terminates your license, and (b) permanently, if the copyright\nholder fails to notify you of the violation by some reasonable means\nprior to 60 days after the cessation.\n\n  Moreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from that\ncopyright holder, and you cure the violation prior to 30 days after\nyour receipt of the notice.\n\n  Termination of your rights under this section does not terminate the\nlicenses of parties who have received copies or rights from you under\nthis License.  If your rights have been terminated and not permanently\nreinstated, you do not qualify to receive new licenses for the same\nmaterial under section 10.\n\n  9. Acceptance Not Required for Having Copies.\n\n  You are not required to accept this License in order to receive or\nrun a copy of the Program.  Ancillary propagation of a covered work\noccurring solely as a consequence of using peer-to-peer transmission\nto receive a copy likewise does not require acceptance.  However,\nnothing other than this License grants you permission to propagate or\nmodify any covered work.  These actions infringe copyright if you do\nnot accept this License.  Therefore, by modifying or propagating a\ncovered work, you indicate your acceptance of this License to do so.\n\n  10. Automatic Licensing of Downstream Recipients.\n\n  Each time you convey a covered work, the recipient automatically\nreceives a license from the original licensors, to run, modify and\npropagate that work, subject to this License.  You are not responsible\nfor enforcing compliance by third parties with this License.\n\n  An \"entity transaction\" is a transaction transferring control of an\norganization, or substantially all assets of one, or subdividing an\norganization, or merging organizations.  If propagation of a covered\nwork results from an entity transaction, each party to that\ntransaction who receives a copy of the work also receives whatever\nlicenses to the work the party's predecessor in interest had or could\ngive under the previous paragraph, plus a right to possession of the\nCorresponding Source of the work from the predecessor in interest, if\nthe predecessor has it or can get it with reasonable efforts.\n\n  You may not impose any further restrictions on the exercise of the\nrights granted or affirmed under this License.  For example, you may\nnot impose a license fee, royalty, or other charge for exercise of\nrights granted under this License, and you may not initiate litigation\n(including a cross-claim or counterclaim in a lawsuit) alleging that\nany patent claim is infringed by making, using, selling, offering for\nsale, or importing the Program or any portion of it.\n\n  11. Patents.\n\n  A \"contributor\" is a copyright holder who authorizes use under this\nLicense of the Program or a work on which the Program is based.  The\nwork thus licensed is called the contributor's \"contributor version\".\n\n  A contributor's \"essential patent claims\" are all patent claims\nowned or controlled by the contributor, whether already acquired or\nhereafter acquired, that would be infringed by some manner, permitted\nby this License, of making, using, or selling its contributor version,\nbut do not include claims that would be infringed only as a\nconsequence of further modification of the contributor version.  For\npurposes of this definition, \"control\" includes the right to grant\npatent sublicenses in a manner consistent with the requirements of\nthis License.\n\n  Each contributor grants you a non-exclusive, worldwide, royalty-free\npatent license under the contributor's essential patent claims, to\nmake, use, sell, offer for sale, import and otherwise run, modify and\npropagate the contents of its contributor version.\n\n  In the following three paragraphs, a \"patent license\" is any express\nagreement or commitment, however denominated, not to enforce a patent\n(such as an express permission to practice a patent or covenant not to\nsue for patent infringement).  To \"grant\" such a patent license to a\nparty means to make such an agreement or commitment not to enforce a\npatent against the party.\n\n  If you convey a covered work, knowingly relying on a patent license,\nand the Corresponding Source of the work is not available for anyone\nto copy, free of charge and under the terms of this License, through a\npublicly available network server or other readily accessible means,\nthen you must either (1) cause the Corresponding Source to be so\navailable, or (2) arrange to deprive yourself of the benefit of the\npatent license for this particular work, or (3) arrange, in a manner\nconsistent with the requirements of this License, to extend the patent\nlicense to downstream recipients.  \"Knowingly relying\" means you have\nactual knowledge that, but for the patent license, your conveying the\ncovered work in a country, or your recipient's use of the covered work\nin a country, would infringe one or more identifiable patents in that\ncountry that you have reason to believe are valid.\n\n  If, pursuant to or in connection with a single transaction or\narrangement, you convey, or propagate by procuring conveyance of, a\ncovered work, and grant a patent license to some of the parties\nreceiving the covered work authorizing them to use, propagate, modify\nor convey a specific copy of the covered work, then the patent license\nyou grant is automatically extended to all recipients of the covered\nwork and works based on it.\n\n  A patent license is \"discriminatory\" if it does not include within\nthe scope of its coverage, prohibits the exercise of, or is\nconditioned on the non-exercise of one or more of the rights that are\nspecifically granted under this License.  You may not convey a covered\nwork if you are a party to an arrangement with a third party that is\nin the business of distributing software, under which you make payment\nto the third party based on the extent of your activity of conveying\nthe work, and under which the third party grants, to any of the\nparties who would receive the covered work from you, a discriminatory\npatent license (a) in connection with copies of the covered work\nconveyed by you (or copies made from those copies), or (b) primarily\nfor and in connection with specific products or compilations that\ncontain the covered work, unless you entered into that arrangement,\nor that patent license was granted, prior to 28 March 2007.\n\n  Nothing in this License shall be construed as excluding or limiting\nany implied license or other defenses to infringement that may\notherwise be available to you under applicable patent law.\n\n  12. No Surrender of Others' Freedom.\n\n  If conditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot convey a\ncovered work so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you may\nnot convey it at all.  For example, if you agree to terms that obligate you\nto collect a royalty for further conveying from those to whom you convey\nthe Program, the only way you could satisfy both those terms and this\nLicense would be to refrain entirely from conveying the Program.\n\n  13. Remote Network Interaction; Use with the GNU General Public License.\n\n  Notwithstanding any other provision of this License, if you modify the\nProgram, your modified version must prominently offer all users\ninteracting with it remotely through a computer network (if your version\nsupports such interaction) an opportunity to receive the Corresponding\nSource of your version by providing access to the Corresponding Source\nfrom a network server at no charge, through some standard or customary\nmeans of facilitating copying of software.  This Corresponding Source\nshall include the Corresponding Source for any work covered by version 3\nof the GNU General Public License that is incorporated pursuant to the\nfollowing paragraph.\n\n  Notwithstanding any other provision of this License, you have\npermission to link or combine any covered work with a work licensed\nunder version 3 of the GNU General Public License into a single\ncombined work, and to convey the resulting work.  The terms of this\nLicense will continue to apply to the part which is the covered work,\nbut the work with which it is combined will remain governed by version\n3 of the GNU General Public License.\n\n  14. Revised Versions of this License.\n\n  The Free Software Foundation may publish revised and/or new versions of\nthe GNU Affero General Public License from time to time.  Such new versions\nwill be similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\n  Each version is given a distinguishing version number.  If the\nProgram specifies that a certain numbered version of the GNU Affero General\nPublic License \"or any later version\" applies to it, you have the\noption of following the terms and conditions either of that numbered\nversion or of any later version published by the Free Software\nFoundation.  If the Program does not specify a version number of the\nGNU Affero General Public License, you may choose any version ever published\nby the Free Software Foundation.\n\n  If the Program specifies that a proxy can decide which future\nversions of the GNU Affero General Public License can be used, that proxy's\npublic statement of acceptance of a version permanently authorizes you\nto choose that version for the Program.\n\n  Later license versions may give you additional or different\npermissions.  However, no additional obligations are imposed on any\nauthor or copyright holder as a result of your choosing to follow a\nlater version.\n\n  15. Disclaimer of Warranty.\n\n  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\nAPPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\nOF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\nIS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\nALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. Limitation of Liability.\n\n  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\nTHE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\nGENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\nUSE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\nDATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\nPARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\nEVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\nSUCH DAMAGES.\n\n  17. Interpretation of Sections 15 and 16.\n\n  If the disclaimer of warranty and limitation of liability provided\nabove cannot be given local legal effect according to their terms,\nreviewing courts shall apply local law that most closely approximates\nan absolute waiver of all civil liability in connection with the\nProgram, unless a warranty or assumption of liability accompanies a\ncopy of the Program in return for a fee.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nstate the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU Affero General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU Affero General Public License for more details.\n\n    You should have received a copy of the GNU Affero General Public License\n    along with this program.  If not, see <http://www.gnu.org/licenses/>.\n\nAlso add information on how to contact you by electronic and paper mail.\n\n  If your software can interact with users remotely through a computer\nnetwork, you should also make sure that it provides a way for users to\nget its source.  For example, if your program is a web application, its\ninterface could display a \"Source\" link that leads users to an archive\nof the code.  There are many ways you could offer source, and different\nsolutions will be better for different programs; see section 13 for the\nspecific requirements.\n\n  You should also get your employer (if you work as a programmer) or school,\nif any, to sign a \"copyright disclaimer\" for the program, if necessary.\nFor more information on this, and how to apply and follow the GNU AGPL, see\n<http://www.gnu.org/licenses/>.\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/README",
    "content": "This is legacy code from when the course used class-based\ncomponents for the Redux portion. It is NOT maintained!\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/.gitignore",
    "content": "# See https://help.github.com/ignore-files/ for more about ignoring files.\n\n# dependencies\n/node_modules\n\n# testing\n/coverage\n\n# production\n/build\n\n# misc\n.DS_Store\n.env.local\n.env.development.local\n.env.test.local\n.env.production.local\nconfig.js\n\nnpm-debug.log*\nyarn-debug.log*\nyarn-error.log*\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/README.md",
    "content": "# Jotto\n### A React / Redux app used to demonstrate testing\n\n## Solutions\n\nSolutions can be found in the [SOLUTIONS for Jotto Hooks- Context Challenges](https://github.com/flyrightsister/udemy-react-testing-projects/tree/master/SOLUTIONS%20for%20Jotto%20Hooks-Context%20Challenges) folder.\n\n\n## Challenges\n\n### 1. Number of Guesses\n  ![Number of Guesses Wireframe](https://github.com/flyrightsister/udemy-react-testing-projects/blob/master/jotto/readme-images/number-of-guesses_wireframe.png)\n\n  * _Note_: Try to accomplish this _without_ adding a new piece of state!\n  * Add “guess number” column to the \"guessed words\" table\n    * The first guess should show 1, second guess 2, etc.\n  * Add a component that displays total guesses as shown in wireframe\n\n### 2. Reset Game\n  ![Reset Game Wireframe](https://github.com/flyrightsister/udemy-react-testing-projects/blob/master/jotto/readme-images/new-game_wireframe.png)\n  * Create a “New word” button component\n    * only display after successful guess\n  * Upon click, reset the game with a new word from the server\n  * _Note_: This can be done with a connected component (which lends itself to state testing similar to `Input.js`) or with an unconnected component which receives the action creator from the parent `App.js` component (which will require unit testing for action creators and reducers instead, as using a store with an unconnected component is not covered in this course). The solution in the `jotto-challenges` branch covers the second approach.\n\n### 3. “Give up” Button\n  ![Give Up Button Wireframe](https://github.com/flyrightsister/udemy-react-testing-projects/blob/master/jotto/readme-images/give-up-button_wireframe.png)\n  ![After Give Up Click Wireframe](https://github.com/flyrightsister/udemy-react-testing-projects/blob/master/jotto/readme-images/after-give-up_wireframe.png)  \n  \n  * Create a “Give up” button\n    * only display when word has not been guessed correctly\n  * Upon click:\n    * Show secret word\n    * Display \"better luck next time\" message\n    * Display “new word” button component\n\n### 4. User inputs secret word\n  ![Enter Secret Word Button Wireframe](https://github.com/flyrightsister/udemy-react-testing-projects/blob/master/jotto/readme-images/enter-secret-word_wireframe.png)  \n  ![Secret Word Entry Form Wireframe](https://github.com/flyrightsister/udemy-react-testing-projects/blob/master/jotto/readme-images/secret-word-entry-form_wireframe.png)  \n\n  * _Note: This one is quite involved, with a new piece of state, Redux Thunk, and testing that an action creator receives the correct argument. Not for the faint of heart! It is great for using existing tests to see whether new code breaks old functionality._\n  * Add a button for the user to input the secret word\n    * This way, the user can play against a friend\n  * After submission, the game should use the user’s secret word, not a word from the server\n  * This button should disapppear once the user has nonzero `guessedWords`\n    * Should disappear whether the word came from the server or user input\n\n### 5. Random Word Server Error\n  ![Random Word Server Error Wireframe](https://github.com/flyrightsister/udemy-react-testing-projects/blob/master/jotto/readme-images/random-word-server-error_wireframe.png) \n\n  * Display an error if:\n    * There’s a problem contacting the “random word” server\n    * The server responds with status 4xx or 5xx\n\n### 6. Use Wordnik to get secret word\n  * Get a [Wordnik auth token](http://developer.wordnik.com/)\n  * Use the [words/randomWord](http://developer.wordnik.com/docs.html) endpoint (instead of the random word server that came with this course)\n \n## Credits\nThis project was bootstrapped with [Create React App](https://github.com/facebookincubator/create-react-app).\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/package.json",
    "content": "{\n  \"name\": \"jotto\",\n  \"version\": \"0.1.0\",\n  \"private\": true,\n  \"dependencies\": {\n    \"axios\": \"^0.18.1\",\n    \"prop-types\": \"^15.6.1\",\n    \"react\": \"^16.3.2\",\n    \"react-dom\": \"^16.3.2\",\n    \"react-redux\": \"^5.0.7\",\n    \"react-scripts\": \"1.1.4\",\n    \"redux\": \"^4.0.0\",\n    \"redux-thunk\": \"^2.2.0\"\n  },\n  \"scripts\": {\n    \"start\": \"react-scripts start\",\n    \"build\": \"react-scripts build\",\n    \"test\": \"react-scripts test --env=jsdom\",\n    \"eject\": \"react-scripts eject\"\n  },\n  \"devDependencies\": {\n    \"ajv\": \"^6.4.0\",\n    \"check-prop-types\": \"^1.1.2\",\n    \"enzyme\": \"^3.3.0\",\n    \"enzyme-adapter-react-16\": \"^1.1.1\",\n    \"jest\": \"^22.4.3\",\n    \"jest-enzyme\": \"^6.0.0\",\n    \"moxios\": \"^0.4.0\"\n  }\n}\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/public/index.html",
    "content": "<!DOCTYPE html>\n<html lang=\"en\">\n  <head>\n    <meta charset=\"utf-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\">\n    <meta name=\"theme-color\" content=\"#000000\">\n    <!--\n      manifest.json provides metadata used when your web app is added to the\n      homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/\n    -->\n    <link rel=\"manifest\" href=\"%PUBLIC_URL%/manifest.json\">\n    <link rel=\"shortcut icon\" href=\"%PUBLIC_URL%/favicon.ico\">\n    <link rel=\"stylesheet\" href=\"https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css\" integrity=\"sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB\" crossorigin=\"anonymous\">\n    <!--\n      Notice the use of %PUBLIC_URL% in the tags above.\n      It will be replaced with the URL of the `public` folder during the build.\n      Only files inside the `public` folder can be referenced from the HTML.\n\n      Unlike \"/favicon.ico\" or \"favicon.ico\", \"%PUBLIC_URL%/favicon.ico\" will\n      work correctly both with client-side routing and a non-root public URL.\n      Learn how to configure a non-root public URL by running `npm run build`.\n    -->\n    <title>React App</title>\n  </head>\n  <body>\n    <noscript>\n      You need to enable JavaScript to run this app.\n    </noscript>\n    <div id=\"root\"></div>\n    <!--\n      This HTML file is a template.\n      If you open it directly in the browser, you will see an empty page.\n\n      You can add webfonts, meta tags, or analytics to this file.\n      The build step will place the bundled scripts into the <body> tag.\n\n      To begin the development, run `npm start` or `yarn start`.\n      To create a production bundle, use `npm run build` or `yarn build`.\n    -->\n  </body>\n</html>\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/public/manifest.json",
    "content": "{\n  \"short_name\": \"React App\",\n  \"name\": \"Create React App Sample\",\n  \"icons\": [\n    {\n      \"src\": \"favicon.ico\",\n      \"sizes\": \"64x64 32x32 24x24 16x16\",\n      \"type\": \"image/x-icon\"\n    }\n  ],\n  \"start_url\": \"./index.html\",\n  \"display\": \"standalone\",\n  \"theme_color\": \"#000000\",\n  \"background_color\": \"#ffffff\"\n}\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/App.css",
    "content": ".spacer-bottom {\n  margin-bottom: 20px;\n}"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/App.js",
    "content": "import React, { Component } from 'react';\nimport { connect } from 'react-redux';\nimport './App.css';\n\n// Challenge #1: Number of Guesses\nimport TotalGuesses from './TotalGuesses';\n// END: Challenge #1: Number of Guesses\n\n// Challenge #2: Reset Game\nimport NewWordButton from './NewWordButton';\n// END: Challenge #2: Reset Game\n\n// Challenge #2: Reset Game\nimport SecretWordReveal from './SecretWordReveal';\n// END: Challenge #2: Reset Game\n\n// Challenge #4: Enter Secret Word\nimport EnterWordButton from './EnterWordButton';\nimport EnterWordForm from './EnterWordForm';\n// END: Challenge #4: Enter Secret Word\n\n// Challenge #2: Reset Game\nimport ServerError from './ServerError';\n// END: Challenge #2: Reset Game\n\n\nimport GuessedWords from './GuessedWords';\nimport Congrats from './Congrats';\nimport Input from './Input';\n\n// Challenge #2 and #4\nimport { \n  getSecretWord, \n  resetGame, \n  setUserSecretWord,\n  setUserEntering } \nfrom './actions';\n// END: Challenge #2 and #4\n\nexport class UnconnectedApp extends Component {\n  /**\n   * @method componentDidMount\n   * @returns {undefined}\n   */\n  componentDidMount() {\n    // get the secret word\n    this.props.getSecretWord();\n  }\n  \n  render() {\n    // Challenge #4: Enter Secret Word\n    let contents;\n    // Challenge #5: Server Error\n    if (this.props.serverError) {\n      contents = <ServerError />\n    // END: Challenge #5: Server Error\n    } else if (this.props.userEnter === 'inProgress') {\n      contents = (\n        <EnterWordForm formAction={this.props.setUserSecretWord}/>\n      );\n    } else {\n      contents = (\n        <div>\n          <Congrats success={this.props.success} />\n\n          {/* Challenge #3: Give Up Button */}\n          <SecretWordReveal display={this.props.gaveUp} secretWord={this.props.secretWord} />\n          {/* END: Challenge #3: Give Up Button */}\n\n          {/* Challenge #2 and #3 */}\n          <NewWordButton \n            display={this.props.success || this.props.gaveUp } \n            resetAction={this.props.resetGame} />\n          {/* END: Challenge #2 and #3 */}\n\n\n          <Input />\n          <GuessedWords guessedWords={this.props.guessedWords} />\n\n          {/* Challenge #1: Number of guesses */}\n          <TotalGuesses guessCount={this.props.guessedWords.length} />\n          {/* END: Challenge #1: Number of guesses */}\n\n          {/* Challenge #4: Enter Secret Word */}\n          <EnterWordButton \n            display={this.props.guessedWords.length === 0}\n            buttonAction={this.props.setUserEntering} \n          />\n          {/* END: Challenge #4: Enter Secret Word */}\n        </div>\n      );\n    }\n    return (\n      <div className=\"container\">\n        <h1>Jotto</h1>\n        { contents }\n      </div>\n    );\n    // END: Challenge #4: Enter Secret Word\n  }\n}\n\n\n// Challenge #4: Enter Secret Word\nconst mapStateToProps = ({ success, guessedWords, secretWord, gaveUp, userEnter, serverError }) => {\n  return { success, guessedWords, secretWord, gaveUp, userEnter, serverError };\n}\n// END: Challenge #4: Enter Secret Word\n\n// Challenge #2 and #4\nconst actions = { \n  getSecretWord, \n  resetGame, \n  setUserSecretWord,\n  setUserEntering,\n};\n\nexport default connect(mapStateToProps, actions)(UnconnectedApp);\n// END: Challenge #2 and #4\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/App.test.js",
    "content": "import React from 'react';\nimport { shallow } from 'enzyme';\n\nimport { storeFactory } from '../test/testUtils';\nimport App, { UnconnectedApp } from './App';\n\n/**\n * @function setup\n * @param {object} state - State for this setup.\n * @returns {ShallowWrapper}\n */\nconst setup = (state={}) => {\n  const store = storeFactory(state);\n  const wrapper = shallow(<App store={store} />).dive();\n  return wrapper;\n}\n\n// Challenge #3: Refactored to set up the wrapper once in a beforeEach \ndescribe('redux properties', () => {\n  let wrapper;\n  const success = false;\n  const gaveUp = false;\n  const secretWord = 'party';\n  const guessedWords = [{ guessedWord: 'train', letterMatchCount: 3 }];\n\n  beforeEach(() => {\n    wrapper = setup({ \n      success,\n      gaveUp,\n      secretWord,\n      guessedWords,\n    });\n  })\n  test('has access to `success` state', () => {\n    const successProp = wrapper.instance().props.success;\n    expect(successProp).toBe(success);\n  });\n  // Challenge #3: Give Up Button\n  test('has access to `gaveUp` state', () => {\n    const gaveUpProp = wrapper.instance().props.gaveUp;\n    expect(gaveUpProp).toBe(gaveUp);\n  });\n  // END: Challenge #3: Give Up Button\n  test('has access to `secretWord` state', () => {\n    const secretWordProp = wrapper.instance().props.secretWord;\n    expect(secretWordProp).toBe(secretWord);\n  });\n  test('has access to `guessedWords` state', () => {\n    const guessedWordsProp = wrapper.instance().props.guessedWords;\n    expect(guessedWordsProp).toEqual(guessedWords);\n  });\n  test('`getSecretWord` action creator is a function on the props', () => {\n    const getSecretWordProp = wrapper.instance().props.getSecretWord;\n    expect(getSecretWordProp).toBeInstanceOf(Function);\n  });\n  // Challenge #2: Reset Game\n  test('`resetGame` action creator is a function on the props', () => {\n    const resetGameProp = wrapper.instance().props.resetGame;\n    expect(resetGameProp).toBeInstanceOf(Function);\n  });\n  // END: Challenge #2: Reset Game\n});\n// END: Challenge #3: Refactored to set up the wrapper once in a beforeEach \n\n\ntest('`getSecretWord` runs on App mount', () => {\n  const getSecretWordMock = jest.fn();\n\n  const props = {\n    getSecretWord: getSecretWordMock,\n    success: false,\n    // Challenge #3: Give Up Button\n    gaveUp: false,\n    // END: Challenge #3: Give Up Button\n    secretWord: 'party',\n    guessedWords: [],\n  }\n\n  // set up app component with getSecretWordMock as the getSecretWord prop\n  const wrapper = shallow(<UnconnectedApp {...props} />);\n\n  // run lifecycle method\n  wrapper.instance().componentDidMount();\n\n  // check to see if mock ran\n  const getSecretWordCallCount = getSecretWordMock.mock.calls.length;\n\n  expect(getSecretWordCallCount).toBe(1);\n\n});\n\n// NOTE: the logic of what displays according to state \n// should be tested here. That is left as an exercise for\n// the student. :-)"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/Congrats.js",
    "content": "import React from 'react';\nimport PropTypes from 'prop-types';\n\n/**\n * Functional react component for congratulatory message.\n * @function\n * @param {object} props - React props.\n * @returns {JSX.Element} - Rendered component (or null if `success` prop is false).\n */\nconst Congrats = (props) => {\n  if (props.success) {\n    return (\n      <div data-test=\"component-congrats\" className=\"alert alert-success\">\n        <span data-test=\"congrats-message\">\n          Congratulations! You guessed the word!\n        </span>\n      </div>\n    );\n  } else {\n    return (\n      <div data-test=\"component-congrats\" />\n    );\n  }\n};\n\nCongrats.propTypes = {\n  success: PropTypes.bool.isRequired,\n};\n\nexport default Congrats;\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/Congrats.test.js",
    "content": "import React from 'react';\nimport { shallow } from 'enzyme';\n\nimport { findByTestAttr, checkProps } from '../test/testUtils';\nimport Congrats from './Congrats';\n\nconst defaultProps = { success: false };\n\n/**\n* Factory function to create a ShallowWrapper for the Congrats component.\n* @function setup\n* @param {object} props - Component props specific to this setup.\n* @returns {ShallowWrapper}\n*/\nconst setup = (props={}) => {\n  const setupProps = { ...defaultProps, ...props };\n  return shallow(<Congrats {...setupProps} />)\n}\n\ntest('renders without error', () => {\n  const wrapper = setup();\n  const component = findByTestAttr(wrapper, 'component-congrats');\n  expect(component.length).toBe(1);\n});\ntest('renders no text when `success` prop is false', () => {\n  const wrapper = setup({ success: false });\n  const component = findByTestAttr(wrapper, 'component-congrats');\n  expect(component.text()).toBe('');\n});\ntest('renders non-empty congrats message when `success` prop is true', () => {\n  const wrapper = setup({ success: true });\n  const message = findByTestAttr(wrapper, 'congrats-message');\n  expect(message.text().length).not.toBe(0);\n});\ntest('does not throw warning with expected props', () => {\n  const expectedProps = { success: false };\n  checkProps(Congrats, expectedProps);\n});\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/EnterWordButton.js",
    "content": "// Challenge #4: Enter Secret Word\nimport React from 'react';\nimport PropTypes from 'prop-types';\n\nconst EnterWordButton = (props) => {\n  if (props.display) {\n    return (\n      <button \n        data-test=\"component-enter-word-button\" \n        className=\"btn btn-primary spacer-bottom\"\n        onClick={props.buttonAction}>\n        Enter your own secret word\n      </button>\n    );\n  } else {\n    return (\n      <div data-test=\"component-enter-word-button\" />\n    );\n  }\n};\n\nEnterWordButton.propTypes = {\n  display: PropTypes.bool.isRequired,\n  buttonAction: PropTypes.func,\n};\n\nexport default EnterWordButton;\n\n// END: Challenge #4: Enter Secret Word\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/EnterWordButton.test.js",
    "content": "// Challenge #4: Enter Secret Word\nimport React from 'react';\nimport { shallow } from 'enzyme';\n\nimport { findByTestAttr, checkProps } from '../test/testUtils';\nimport EnterWordButton from './EnterWordButton';\n\nconst defaultProps = { display: true };\n\n/**\n* Factory function to create a ShallowWrapper for the EnterWordButton component.\n* @function setup\n* @param {object} props - Component props specific to this setup.\n* @returns {ShallowWrapper}\n*/\nconst setup = (props={}) => {\n  const setupProps = { ...defaultProps, ...props };\n  return shallow(<EnterWordButton {...setupProps} />)\n}\n\ndescribe('render', () => {\n\n  test('renders without error', () => {\n    const wrapper = setup();\n    const component = findByTestAttr(wrapper, 'component-enter-word-button');\n    expect(component.length).toBe(1);\n  });\n  test('renders no text when `display` prop is false', () => {\n    const wrapper = setup({ display: false });\n    const component = findByTestAttr(wrapper, 'component-enter-word-button');\n    expect(component.text()).toBe('');\n  });\n  test('renders non-empty text when `display` prop is true', () => {\n    const wrapper = setup({ display: true, buttonAction: () => {} });\n    const component = findByTestAttr(wrapper, 'component-enter-word-button');\n    expect(component.text().length).not.toBe(0);\n  });\n  test('does not throw warning with expected props', () => {\n    const expectedProps = { display: false };\n    checkProps(EnterWordButton, expectedProps);\n  });\n});\ntest('calls `buttonAction` prop upon button click', () => {\n  // create a mock function so we can see whether it's called on click\n  const buttonActionMock = jest.fn();\n  const wrapper = setup({ display: true, buttonAction: buttonActionMock });\n\n  // find the button (which is the top level element of this component)\n  const resetButton = findByTestAttr(wrapper, 'component-enter-word-button');\n  resetButton.simulate('click');\n\n  // expect the mock to have been called once\n  expect(buttonActionMock.mock.calls.length).toBe(1);\n});\n// END: Challenge #4: Enter Secret Word\n\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/EnterWordForm.js",
    "content": "// Challenge #4: Enter Secret Word\nimport React from 'react';\nimport PropTypes from 'prop-types';\n\nexport class EnterWordForm extends React.Component {\n  constructor(props) {\n    super(props);\n    this.inputBox = React.createRef();\n    this.submitForm = this.submitForm.bind(this);\n  }\n  submitForm(evt) {\n    evt.preventDefault();\n    // don't submit empty word\n    if (this.inputBox.current.value.length > 0) {\n      this.props.formAction(this.inputBox.current.value);\n    }\n  }\n  render() {\n    return (\n      <div data-test=\"component-enter-word-form\">\n        <p data-test=\"enter-word-instructions\">\n          Enter a secret word for someone else to guess!\n        </p>\n        <form className=\"form-inline\">\n            <input\n              data-test=\"enter-word-input\"\n              ref={this.inputBox}\n              className=\"mb-2 mx-sm-3\"\n              type=\"text\"\n              placeholder=\"enter secret word\" />\n            <button\n              data-test=\"submit-button\"\n              onClick={this.submitForm}\n              className=\"btn btn-primary mb-2\"\n              type=\"submit\">\n              Submit\n            </button>\n          </form>\n      </div>\n    );\n  }\n}\n\nEnterWordForm.propTypes = {\n  formAction: PropTypes.func,\n}\n\nexport default EnterWordForm;\n// END: Challenge #4: Enter Secret Word\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/EnterWordForm.test.js",
    "content": "// Challenge #4: Enter Secret Word\nimport React from 'react';\nimport { shallow } from 'enzyme';\n\nimport { findByTestAttr, checkProps } from '../test/testUtils';\nimport EnterWordForm from './EnterWordForm';\n\nconst defaultProps = { formAction: () => {} };\n\n/**\n* Factory function to create a ShallowWrapper for the EnterWordForm component.\n* @function setup\n* @param {object} props - Component props specific to this setup.\n* @returns {ShallowWrapper}\n*/\nconst setup = (props={}) => {\n  const setupProps = { ...defaultProps, ...props };\n  return shallow(<EnterWordForm {...setupProps} />)\n}\ndescribe('render', () => {\n  // the condition for this to render is within the App\n  // component, so we don't need to test conditional rendering here\n  test('renders without error', () => {\n    const wrapper = setup();\n    const component = findByTestAttr(wrapper, 'component-enter-word-form');\n    expect(component.length).toBe(1);\n  });\n  test('renders instructions', () => {\n    const wrapper = setup();\n    const instructions = findByTestAttr(wrapper, 'enter-word-instructions');\n    expect(instructions.length).toBe(1);\n  });\n  test('renders submit button', () => {\n    const wrapper = setup();\n    const submit = findByTestAttr(wrapper, 'submit-button');\n    expect(submit.length).toBe(1);\n  });\n  test('renders input box', () => {\n    const wrapper = setup();\n    const input = findByTestAttr(wrapper, 'enter-word-input');\n    expect(input.length).toBe(1);\n  });\n  test('does not throw warning with expected props', () => {\n    const expectedProps = { formAction: () => {} };\n    checkProps(EnterWordForm, expectedProps);\n  });\n});\n\ndescribe('submit click action', () => {\n  let setUserSecretWordMock;\n  let wrapper;\n  const userSecretWord = 'lunch';\n  beforeEach(() => {\n    // create a mock function for `setUserSecretWord`\n    setUserSecretWordMock = jest.fn();\n\n    // set up Input, with setUserSecretWordMock as a prop\n    wrapper = setup({formAction: setUserSecretWordMock});\n\n    // simulate the input\n    wrapper.instance().inputBox.current = { value: userSecretWord };\n\n    // simulate click on submit button\n    const submit = findByTestAttr(wrapper, 'submit-button');\n    submit.simulate('click', { preventDefault() {} });\n  });\n  test('`setUserSecretWord` was called once', () => {\n    const setUserSecretWordCallCount = setUserSecretWordMock.mock.calls.length;\n    expect(setUserSecretWordCallCount).toBe(1);\n  });\n  test('`setUserSecretWord` was called with input value as argument', () => {\n    const userSecretWordArg = setUserSecretWordMock.mock.calls[0][0];\n    expect(userSecretWordArg).toBe(userSecretWord);\n  });\n});\n\n// END: Challenge #4: Enter Secret Word\n\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/GuessedWords.js",
    "content": "import React from 'react';\nimport PropTypes from 'prop-types';\n\nconst GuessedWords = (props) => {\n  let contents\n  if (props.guessedWords.length === 0) {\n    contents = (\n      <span data-test=\"guess-instructions\">\n        Try to guess the secret word!\n      </span>\n    );\n  } else {\n    const guessedWordsRows = props.guessedWords.map((word, index) => (\n      <tr data-test=\"guessed-word\" key={ index }>\n        {/* Challenge #1: Number of Guesses */}\n        <td data-test=\"guessed-word-index\">{ index + 1 }</td>\n        {/* END: Challenge #1: Number of Guesses */}\n        <td>{ word.guessedWord }</td>\n        <td>{ word.letterMatchCount }</td>\n      </tr>\n    ));\n    contents = (\n      <div data-test=\"guessed-words\">\n        <h3>Guessed Words</h3>\n        <table className=\"table table-sm\">\n          <thead className=\"thead-light\">\n            <tr>\n              {/* Challenge #1: Number of Guesses */}\n              <th>#</th>\n              {/* Challenge #1: Number of Guesses */}\n              <th>Guess</th>\n              <th>Matching Letters</th>\n            </tr>\n          </thead>\n          <tbody>\n            { guessedWordsRows }\n          </tbody>\n        </table>\n      </div>\n    );\n  }\n  return (\n    <div data-test=\"component-guessed-words\">\n      { contents }\n    </div>\n  );\n};\n\nGuessedWords.propTypes = {\n  guessedWords: PropTypes.arrayOf(\n    PropTypes.shape({\n      guessedWord: PropTypes.string.isRequired,\n      letterMatchCount: PropTypes.number.isRequired,\n    })\n  ).isRequired,\n};\n\nexport default GuessedWords;\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/GuessedWords.test.js",
    "content": "import React from 'react';\nimport { shallow } from 'enzyme';\nimport { findByTestAttr, checkProps } from '../test/testUtils';\nimport GuessedWords from './GuessedWords';\n\nconst defaultProps = {\n  guessedWords: [{ guessedWord: 'train', letterMatchCount: 3 }],\n};\n\n/**\n* Factory function to create a ShallowWrapper for the GuessedWords component.\n* @function setup\n* @param {object} props - Component props specific to this setup.\n* @returns {ShallowWrapper}\n*/\nconst setup = (props={}) => {\n  const setupProps = { ...defaultProps, ...props };\n  return shallow(<GuessedWords {...setupProps } />)\n};\n\ntest('does not throw warning with expected props', () => {\n  checkProps(GuessedWords, defaultProps);\n});\n\ndescribe('if there are no words guessed', () => {\n  let wrapper\n  beforeEach(() => {\n    wrapper = setup({ guessedWords: [] });\n  });\n  test('renders without error', () => {\n    const component = findByTestAttr(wrapper, 'component-guessed-words');\n    expect(component.length).toBe(1);\n  });\n  test('renders instructions to guess a word', () => {\n    const instructions = findByTestAttr(wrapper, 'guess-instructions');\n    expect(instructions.text().length).not.toBe(0);\n  });\n});\ndescribe('if there are words guessed', () => {\n  let wrapper;\n  const guessedWords = [\n    { guessedWord: 'train', letterMatchCount: 3 },\n    { guessedWord: 'agile', letterMatchCount: 1 },\n    { guessedWord: 'party', letterMatchCount: 5 },\n  ];\n  beforeEach(() => {\n    wrapper = setup({ guessedWords });\n  });\n  test ('renders without error', () => {\n    const component = findByTestAttr(wrapper, 'component-guessed-words');\n    expect(component.length).toBe(1);\n  });\n  test('renders \"guessed words\" section', () => {\n    const guessedWordsNode = findByTestAttr(wrapper, 'guessed-words');\n    expect(guessedWordsNode.length).toBe(1);\n  });\n  test('correct number of guessed words', () => {\n    const guessedWordNodes = findByTestAttr(wrapper, 'guessed-word');\n    expect(guessedWordNodes.length).toBe(guessedWords.length);\n  });\n  // Challenge #1: Number of Guesses\n  test('includes guess word index for each word', () => {\n    const guessWordIndexes = findByTestAttr(wrapper, 'guessed-word-index');\n    const indexTextSet = new Set(guessWordIndexes.map(wrapper => wrapper.text()));\n    const expectedSet = new Set(guessedWords.map((word, index) => (index + 1).toString()));\n    expect(indexTextSet).toEqual(expectedSet);\n  });\n  // END: Challenge #1: Number of Guesses\n});\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/Input.js",
    "content": "import React, { Component } from 'react';\nimport { connect } from 'react-redux';\n\n// Challenge #3: Give Up Button\nimport { guessWord, giveUp } from './actions';\n// END: Challenge #3: Give Up Button\n\nexport class UnconnectedInput extends Component {\n  /**\n   * @method constructor\n   * @param {object} props - Component props.\n   * @returns {undefined}\n   */\n  constructor(props) {\n    super(props);\n\n    this.inputBox = React.createRef();\n    this.submitGuessedWord = this.submitGuessedWord.bind(this);\n    this.giveUpOnClick = this.giveUpOnClick.bind(this);\n  }\n  /**\n   * Run `guessWord` action on the submitted word (if it's not empty)\n   * @method submitGuessedWord\n   * @param {Event} evt - Event that triggered the call.\n   * @returns {undefined}\n   */\n  submitGuessedWord(evt) {\n    evt.preventDefault();\n\n    const guessedWord = this.inputBox.current.value;\n    if (guessedWord && guessedWord.length > 0) {\n      this.props.guessWord(guessedWord);\n    }\n\n    this.inputBox.current.value = '';\n  }\n\n  giveUpOnClick(evt) {\n    evt.preventDefault(); \n    this.props.giveUp();\n  }\n\n  render() {\n    const contents = this.props.success || this.props.gaveUp\n      ? null\n      : (\n        <form className=\"form-inline\">\n          <input\n            data-test=\"input-box\"\n            ref={this.inputBox}\n            className=\"mb-2 mx-sm-3\"\n            id=\"word-guess\"\n            type=\"text\"\n            placeholer=\"enter guess\" />\n          <button\n            data-test=\"submit-button\"\n            onClick={this.submitGuessedWord}\n            className=\"btn btn-primary mb-2\"\n            type=\"submit\">\n            Submit\n          </button>\n          {/* Challenge #3: Give Up Button */}\n          <button \n            data-test=\"give-up-button\"\n            onClick={this.giveUpOnClick}\n            className=\"btn btn-danger mb-2\">\n            Give up\n          </button>\n          {/* END: Challenge #3: Give Up Button */}\n        </form>\n      );\n    return (\n      <div data-test=\"component-input\">\n        { contents }\n      </div>\n    )\n  }\n};\n\nconst mapStateToProps = ({ success, gaveUp }) => {\n  return { success, gaveUp };\n}\n\n// Challenge #3: Give Up Button\nexport default connect(mapStateToProps, { guessWord, giveUp })(UnconnectedInput);\n// END: Challenge #3: Give Up Button\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/Input.test.js",
    "content": "import React from 'react';\nimport { shallow } from 'enzyme';\n\nimport { findByTestAttr, storeFactory } from '../test/testUtils';\nimport Input, { UnconnectedInput } from './Input';\n\n/**\n* Factory function to create a ShallowWrapper for the Input component.\n* @function setup\n* @param {object} initialState - Initial state for this setup.\n* @returns {ShallowWrapper}\n*/\nconst setup = (initialState={}) => {\n  const store = storeFactory(initialState);\n  const wrapper = shallow(<Input store={store} />).dive();\n  return wrapper;\n}\n\ndescribe('render', () => {\n  describe('word has not been guessed', () => {\n    let wrapper;\n    beforeEach(() => {\n      const initialState = { success: false };\n      wrapper = setup(initialState);\n    })\n    test('renders component without error', () => {\n      const component = findByTestAttr(wrapper, 'component-input');\n      expect(component.length).toBe(1);\n    });\n    test('renders input box', () => {\n      const inputBox = findByTestAttr(wrapper, 'input-box');\n      expect(inputBox.length).toBe(1);\n    });\n    test('renders submit button', () => {\n      const submitButton = findByTestAttr(wrapper, 'submit-button');\n      expect(submitButton.length).toBe(1);\n    });\n    // Challenge #3: Give Up Button\n    test('renders \"give up\" button', () => {\n      const giveUpButton = findByTestAttr(wrapper, 'give-up-button');\n      expect(giveUpButton.length).toBe(1);\n    });\n    // END: Challenge #3: Give Up Button\n  });\n  describe('word has been guessed', () => {\n    let wrapper;\n    beforeEach(() => {\n      const initialState = { success: true };\n      wrapper = setup(initialState);\n    });\n    test('renders component without error', () => {\n      const component = findByTestAttr(wrapper, 'component-input');\n      expect(component.length).toBe(1);\n    });\n    test('does not render input box', () => {\n      const inputBox = findByTestAttr(wrapper, 'input-box');\n      expect(inputBox.length).toBe(0);\n    });\n    test('does not render submit button', () => {\n      const submit = findByTestAttr(wrapper, 'submit-button');\n      expect(submit.length).toBe(0);\n    });\n  });\n});\n\ndescribe('redux props', () => {\n  test('has success piece of state as prop', () => {\n    const success = true;\n    const wrapper = setup({ success });\n    const successProp = wrapper.instance().props.success;\n    expect(successProp).toBe(success);\n  });\n  test('`guessWord` action creator is a function prop', () => {\n    const wrapper = setup();\n    const guessWordProp = wrapper.instance().props.guessWord;\n    expect(guessWordProp).toBeInstanceOf(Function);\n  })\n});\n\n// Challenge #3: Give Up Button\ntest('calls `giveUp` prop upon \"Give Up\" button click', () => {\n  // create a mock function so we can see whether it's called on click\n  const giveUpMock = jest.fn();\n\n  // set up Input, with giveUpMock as a prop\n  const wrapper = shallow(<UnconnectedInput giveUp={giveUpMock} />);\n\n  // simulate click on giveUp button\n  const giveUpButton = findByTestAttr(wrapper, 'give-up-button');\n  giveUpButton.simulate('click', { preventDefault() {} });\n  \n  // expect the mock to have been called once\n  expect(giveUpMock.mock.calls.length).toBe(1);\n});\n// END: Challenge #3: Give Up Button\n\ndescribe('`guessWord` action creator', () => {\n  let guessWordMock;\n  let wrapper;\n  const guessedWord = 'train';\n  beforeEach(() => {\n    // create a mock function for `guessWord`\n    guessWordMock = jest.fn();\n\n    // set up Input, with guessWordMock as a prop\n    wrapper = shallow(<UnconnectedInput guessWord={guessWordMock} />);\n\n    // simulate the input\n    wrapper.instance().inputBox.current = { value: guessedWord };\n\n    // simulate click on submit button\n    const submit = findByTestAttr(wrapper, 'submit-button');\n    submit.simulate('click', { preventDefault() {} });\n  });\n  test('`guessWord` was called once', () => {\n    const guessWordCallCount = guessWordMock.mock.calls.length;\n    expect(guessWordCallCount).toBe(1);\n  });\n  test('`guessWord` was called with input value as argument', () => {\n    const guessedWordArg = guessWordMock.mock.calls[0][0];\n    expect(guessedWordArg).toBe(guessedWord);\n  });\n  test('input box clears on submit', () => {\n    expect(wrapper.instance().inputBox.current.value).toBe('');\n  })\n\n});\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/NewWordButton.js",
    "content": "// Challenge #2: Reset Game\n\nimport React from 'react';\nimport PropTypes from 'prop-types';\n\n/**\n * Functional react component for reset button.\n * @function\n * @param {object} props - React props.\n * @returns {JSX.Element} - Rendered component (or null if `success` prop is false).\n */\nconst NewWordButton = (props) => {\n  if (props.display) {\n    return (\n      <button \n        data-test=\"component-new-word-button\" \n        className=\"btn btn-primary spacer-bottom\"\n        onClick={props.resetAction}>\n        New word\n      </button>\n    );\n  } else {\n    return (\n      <div data-test=\"component-new-word-button\" />\n    );\n  }\n};\n\nNewWordButton.propTypes = {\n  display: PropTypes.bool.isRequired,\n  resetAction: PropTypes.func,\n};\n\nexport default NewWordButton;\n\n// END: Challenge #2: Reset Game\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/NewWordButton.test.js",
    "content": "// Challenge #2: Reset Game\n\nimport React from 'react';\nimport { shallow } from 'enzyme';\n\nimport { findByTestAttr, checkProps } from '../test/testUtils';\nimport NewWordButton from './NewWordButton';\n\nconst defaultProps = { display: false };\n\n/**\n* Factory function to create a ShallowWrapper for the NewWordButton component.\n* @function setup\n* @param {object} props - Component props specific to this setup.\n* @returns {ShallowWrapper}\n*/\nconst setup = (props={}) => {\n  const setupProps = { ...defaultProps, ...props };\n  return shallow(<NewWordButton {...setupProps} />);\n}\n\ndescribe('render', () => {\n  test('renders without error', () => {\n    const wrapper = setup();\n    const component = findByTestAttr(wrapper, 'component-new-word-button');\n    expect(component.length).toBe(1);\n  });\n  test('renders no text when `display` prop is false', () => {\n    const wrapper = setup({ display: false });\n    const component = findByTestAttr(wrapper, 'component-new-word-button');\n    expect(component.text()).toBe('');\n  });\n  test('renders non-empty text when `display` prop is true', () => {\n    const wrapper = setup({ display: true, resetAction: () => {} });\n    const component = findByTestAttr(wrapper, 'component-new-word-button');\n    expect(component.text().length).not.toBe(0);\n  });\n});\ntest('does not throw warning with expected props', () => {\n  const expectedProps = { display: false, resetAction: () => {} };\n  checkProps(NewWordButton, expectedProps);\n});\ntest('calls `resetAction` prop upon button click', () => {\n  // create a mock function so we can see whether it's called on click\n  const resetActionMock = jest.fn();\n  const wrapper = setup({ display: true, resetAction: resetActionMock });\n\n  // find the button (which is the top level element of this component)\n  const resetButton = findByTestAttr(wrapper, 'component-new-word-button');\n  resetButton.simulate('click');\n\n  // expect the mock to have been called once\n  expect(resetActionMock.mock.calls.length).toBe(1);\n});\n\n// END: Challenge #2: Reset Game\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/SecretWordReveal.js",
    "content": "// Challenge #3: Give Up Button\nimport React from 'react';\nimport PropTypes from 'prop-types';\n\n/**\n * Functional react component for \"you gave up\" message.\n * @function\n * @param {object} props - React props.\n * @returns {JSX.Element} - Rendered component (or null if `display` prop is false).\n */\nconst SecretWordReveal = (props) => {\n  if (props.display) {\n    return (\n      <div data-test=\"component-secret-word-reveal\" className=\"alert alert-danger\">\n        <span data-test=\"reveal-message\">\n          The secret word was \"{props.secretWord}\"<br />\n          Better luck next time!\n        </span>\n      </div>\n    );\n  } else {\n    return (\n      <div data-test=\"component-secret-word-reveal\" />\n    );\n  }\n};\n\nSecretWordReveal.propTypes = {\n  display: PropTypes.bool.isRequired,\n  // not \"isRequired\" because it's *not* required if display is false\n  secretWord: PropTypes.string,\n};\n\nexport default SecretWordReveal;\n\n// END: Challenge #3: Give Up Button\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/SecretWordReveal.test.js",
    "content": "// Challenge #3: Give Up Button\n\nimport React from 'react';\nimport { shallow } from 'enzyme';\n\nimport { findByTestAttr, checkProps } from '../test/testUtils';\nimport SecretWordReveal from './SecretWordReveal';\n\nconst secretWord = 'party';\nconst defaultProps = { display: false, secretWord };\n\n/**\n* Factory function to create a ShallowWrapper for the SecretWordReveal component.\n* @function setup\n* @param {object} props - Component props specific to this setup.\n* @returns {ShallowWrapper}\n*/\nconst setup = (props={}) => {\n  const setupProps = { ...defaultProps, ...props };\n  return shallow(<SecretWordReveal {...setupProps} />)\n}\n\ntest('renders without error', () => {\n  const wrapper = setup();\n  const component = findByTestAttr(wrapper, 'component-secret-word-reveal');\n  expect(component.length).toBe(1);\n});\ntest('renders no text when `display` prop is false', () => {\n  const wrapper = setup({ display: false });\n  const component = findByTestAttr(wrapper, 'component-secret-word-reveal');\n  expect(component.text()).toBe('');\n});\ntest('renders message containing secret word when `display` prop is true', () => {\n  const wrapper = setup({ display: true });\n  const message = findByTestAttr(wrapper, 'reveal-message');\n  expect(message.text()).toContain(secretWord);\n});\ntest('does not throw warning with expected props', () => {\n  const expectedProps = { display: false, secretWord };\n  checkProps(SecretWordReveal, expectedProps);\n});\n\n// END: Challenge #3: Give Up Button\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/ServerError.js",
    "content": "// Challenge #5: Server Error\nimport React from 'react';\n\nexport default (props) => {\n  return (\n    <div data-test=\"component-server-error\" className=\"alert alert-danger\">\n      There was an error retrieving the secret word. Please try again later.\n    </div>\n  )\n}\n// END: Challenge #5: Server Error"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/ServerError.test.js",
    "content": "// Challenge #5: Server Error\nimport React from 'react';\nimport { shallow } from 'enzyme';\n\nimport { findByTestAttr } from '../test/testUtils';\nimport ServerError from './ServerError';\n\n// no need for setup function here: no props or state\n\ntest('renders without error', () => {\n  const wrapper = shallow(<ServerError />);\n  const component = findByTestAttr(wrapper, 'component-server-error');\n  expect(component.length).toBe(1);\n});\ntest('renders non-empty text', () => {\n  const wrapper = shallow(<ServerError />);\n  const component = findByTestAttr(wrapper, 'component-server-error');\n  expect(component.text().length).not.toBe(0);\n});\n\n// END: Challenge #5: Server Error"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/TotalGuesses.js",
    "content": "// Challenge #1: Number of Guesses\n\nimport React from 'react';\nimport PropTypes from 'prop-types';\n\n/**\n * Functional react component for count of total guesses.\n * @function\n * @param {object} props - React props.\n * @returns {JSX.Element} - Rendered component.\n */\nconst TotalGuesses = (props) => {\n  return (\n    <h4 data-test=\"component-total-guesses\">\n      Total Guesses: {props.guessCount}\n    </h4>\n  );\n};\n\nTotalGuesses.propTypes = {\n  guessCount: PropTypes.number.isRequired,\n};\n\nexport default TotalGuesses;\n\n// END: Challenge #1: Number of Guesses\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/TotalGuesses.test.js",
    "content": "// Challenge #1: Number of Guesses\n\nimport React from 'react';\nimport { shallow } from 'enzyme';\n\nimport { findByTestAttr, checkProps } from '../test/testUtils';\nimport TotalGuesses from './TotalGuesses';\n\nconst defaultProps = { guessCount: 0 };\n\n/**\n* Factory function to create a ShallowWrapper for the TotalGuesses component.\n* @function setup\n* @param {object} props - Component props specific to this setup.\n* @returns {ShallowWrapper}\n*/\nconst setup = (props={}) => {\n  const setupProps = { ...defaultProps, ...props };\n  return shallow(<TotalGuesses {...setupProps} />)\n}\n\ntest('renders without error', () => {\n  const wrapper = setup();\n  const component = findByTestAttr(wrapper, 'component-total-guesses');\n  expect(component.length).toBe(1);\n});\ntest('renders the number of guesses', () => {\n  const guessCount = 8;\n  const wrapper = setup({ guessCount });\n  const component = findByTestAttr(wrapper, 'component-total-guesses');\n  expect(component.text()).toContain(guessCount.toString());\n});\n\n// END: Challenge #1: Number of Guesses\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/actions/index.js",
    "content": "import axios from 'axios';\n\nimport { getLetterMatchCount } from '../helpers';\nimport { wordnikKey } from '../config.js';\n\nexport const WORDNIK_URL = `https://api.wordnik.com/v4/words.json/randomWord?hasDictionaryDef=true&minCorpusCount=1000&minDictionaryCount=100&maxDictionaryCount=-1&minLength=5&maxLength=5&api_key=${wordnikKey}`;\n\nexport const actionTypes = {\n  CORRECT_GUESS: 'CORRECT_GUESS',\n  GUESS_WORD: 'GUESS_WORD',\n  SET_SECRET_WORD: 'SET_SECRET_WORD',\n  RESET_GAME: 'RESET_GAME',\n  GIVE_UP: 'GIVE_UP',\n  USER_ENTERING: 'USER_ENTERING',\n  USER_ENTERED: 'USER_ENTERED',\n  SERVER_ERROR: 'SERVER_ERROR',\n};\n\n/**\n * Returns Redux Thunk function that dispatches GUESS_WORD action\n *     and (conditionally) CORRECT_GUESS action\n * @function guessWord\n * @param {string} guessedWord - Guessed word.\n * @returns {function} - Redux Thunk function.\n*/\nexport const guessWord = (guessedWord) => {\n  return function(dispatch, getState) {\n    const secretWord = getState().secretWord;\n    const letterMatchCount = getLetterMatchCount(guessedWord, secretWord);\n\n    dispatch({\n      type: actionTypes.GUESS_WORD,\n      payload: { guessedWord, letterMatchCount }\n    });\n\n    if (guessedWord === secretWord) {\n      dispatch({ type: actionTypes.CORRECT_GUESS });\n    }\n\n  };\n};\n\n// Challenge #2: Reset Game\n/**\n * Dispatch axios action to get secret word from random word server.\n * Separate this out so it can be used in getSecretWord and resetGame.\n * @function getSecretWordDispatch\n * @param {dispatch} dispatch - Redux Thunk dispatch.\n * \n */\nconst getSecretWordDispatch = (dispatch) => {\n  return axios.get('http://localhost:3030')\n    .then(response => {\n      dispatch({\n        type: actionTypes.SET_SECRET_WORD,\n        payload: response.data\n      });\n    })\n    // Challenge #5: Server Error\n    // note: axios rejects promise if status is 4xx or 5xx\n    .catch(error => {\n      dispatch ({ type: actionTypes.SERVER_ERROR });\n    })\n    // END: Challenge #5: Server Error\n};\n\n// Challenge #6: Wordnik\n/**\n * Dispatch axios action to get secret word from Wordnik.\n * Separate this out so it can be used in getSecretWord and resetGame.\n * @function getSecretWordWordnikDispatch\n * @param {dispatch} dispatch - Redux Thunk dispatch.\n * \n */\nconst getSecretWordWordnikDispatch = (dispatch) => {\n  return axios.get(WORDNIK_URL)\n    .then(response => {\n      dispatch({\n        type: actionTypes.SET_SECRET_WORD,\n        // NOTE: to be true to the rules of jotto here,\n        // we would reject any word with duplicate letters\n        // and try again. However, my commitment to Jotto is\n        // not that strong right now. :p\n        payload: response.data.word\n      });\n    })\n    .catch(err => {\n      dispatch({ type: actionTypes.SERVER_ERROR })\n    });\n  }\n// END: Challenge #6: Wordnik\n\n/**\n * Returns Redux Thunk function that dispatches GET_SECRET_WORD action\n *     after axios promise resolves\n * @function getSecretWord\n * @returns {function} - Redux Thunk function.\n*/\nexport const getSecretWord = () => {\n  return getSecretWordWordnikDispatch; // Challenge #6: Wordnik\n};\n\n/**\n * Action creator to reset game and get a new secret word.\n * @function resetGame\n * @returns {function} - Redux Thunk function that dispatches RESET_GAME action and calls getSecretWord().\n*/\nexport const resetGame = () => {\n  return (dispatch) => {\n    dispatch({ type: actionTypes.RESET_GAME });\n    return getSecretWordWordnikDispatch(dispatch); // Challenge #6: Wordnik\n  }\n};\n// END: Challenge #2: Reset Game\n\n// Challenge #3: Give Up Button\n/**\n * Simple action creator that returns GIVE_UP action type.\n * @function giveUp\n * @returns {object} - GIVE_UP action type.\n*/\nexport const giveUp = () => {\n  return { type: actionTypes.GIVE_UP };\n};\n// END: Challenge #3: Give Up Button\n\n// Challenge #4: Enter Secret Word\n/**\n * Action creator to dispatch USER_ENTERED and SET_SECRET_WORD actions.\n * @function setUserSecretWord\n * @param {string} userSecretWord - Secret word entered by user.\n * @returns {function} - Redux Thunk function.\n */\nexport const setUserSecretWord = (userSecretWord) => {\n  return (dispatch) => {\n    dispatch({ type: actionTypes.SET_SECRET_WORD, payload: userSecretWord });\n    dispatch({ type: actionTypes.USER_ENTERED });\n  }\n};\n\n/**\n * Action creator that returns USER_ENTERING action type.\n * @function setUserEntering\n * @returns {object} - Action with type USER_ENTERING.\n */\nexport const setUserEntering = () => (\n  { type: actionTypes.USER_ENTERING }\n);\n\n// END: Challenge #4: Enter Secret Word\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/actions/index.test.js",
    "content": "import moxios from 'moxios';\n\nimport { storeFactory } from '../../test/testUtils';\nimport { getSecretWord } from './';\n\ndescribe('getSecretWord action creator', () => {\n  beforeEach(() => {\n    moxios.install();\n  });\n  afterEach(() => {\n    moxios.uninstall();\n  });\n  test('adds response word to state', () => {\n    const secretWord = 'party';\n    const store = storeFactory();\n\n    moxios.wait(() => {\n      const request = moxios.requests.mostRecent();\n      request.respondWith({\n        status: 200,\n\n        // Challenge #6: Wordnik\n        // NOTE: this is the only thing in the tests that needs to change\n        // since the shape of the response is different from wordnik\n        // Otherwise, the tests simply work!\n        response: { word: secretWord },\n        // END: Challenge #6: Wordnik\n      });\n    });\n\n    return store.dispatch(getSecretWord())\n      .then(() => {\n        const newState = store.getState();\n        expect(newState.secretWord).toBe(secretWord);\n      })\n  });\n  describe('updates serverError state to `true`', () => {\n    // NOTE: there's currently no way to simulate server nonresponse with moxios\n    test('when server returns 4xx status', () => {\n      const store = storeFactory();\n\n      moxios.wait(() => {\n        const request = moxios.requests.mostRecent();\n        request.respondWith({\n          status: 404,\n        });\n      });\n  \n      return store.dispatch(getSecretWord())\n        .then(() => {\n          const newState = store.getState();\n          expect(newState.serverError).toBe(true);\n        })\n    });\n    test('when server returns 5xx status', () => {\n      const store = storeFactory();\n\n      moxios.wait(() => {\n        const request = moxios.requests.mostRecent();\n        request.respondWith({\n          status: 500,\n        });\n      });\n  \n      return store.dispatch(getSecretWord())\n        .then(() => {\n          const newState = store.getState();\n          expect(newState.serverError).toBe(true);\n        });\n    });\n  })\n});\n\n\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/configureStore.js",
    "content": "import { createStore, applyMiddleware } from 'redux';\nimport ReduxThunk from 'redux-thunk';\nimport rootReducer from './reducers';\n\nexport const middlewares = [ReduxThunk];\nconst createStoreWithMiddleware = applyMiddleware(...middlewares)(createStore);\n\nexport default createStoreWithMiddleware(rootReducer);\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/helpers/index.js",
    "content": "/**\n * @method getLetterMatchCount\n * @param {string} guessedWord - Guessed word.\n * @param {string} secretWord - Secret word.\n * @returns {number} - Number of letters matched between guessed word and secret word.\n */\n export function getLetterMatchCount(guessedWord, secretWord) {\n   const secretLetterSet = new Set(secretWord.split(''));\n   const guessedLetterSet = new Set(guessedWord.split(''));\n   return [...secretLetterSet].filter(letter => guessedLetterSet.has(letter)).length;\n};\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/helpers/index.test.js",
    "content": "import { getLetterMatchCount } from './';\n\ndescribe('getLetterMatchCount', () => {\n  const secretWord = 'party';\n  test('returns correct count when there are no matching letters', () => {\n    const letterMatchCount = getLetterMatchCount('bones', secretWord);\n    expect(letterMatchCount).toBe(0);\n  });\n  test('returns the correct count where there are 3 matching letters', () => {\n    const letterMatchCount = getLetterMatchCount('train', secretWord);\n    expect(letterMatchCount).toBe(3);\n  });\n  test('returns correct count when there are duplicate letters in the guess', () => {\n    const letterMatchCount = getLetterMatchCount('parka', secretWord);\n    expect(letterMatchCount).toBe(3);\n  });\n});\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/index.css",
    "content": "body {\n  margin: 0;\n  padding: 0;\n  font-family: sans-serif;\n}\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/index.js",
    "content": "import React from 'react';\nimport ReactDOM from 'react-dom';\nimport { Provider } from 'react-redux';\n\nimport './index.css';\nimport App from './App';\nimport registerServiceWorker from './registerServiceWorker';\nimport store from './configureStore';\n\nReactDOM.render(\n  <Provider store={store}>\n    <App />\n  </Provider>, \n  document.getElementById('root'));\nregisterServiceWorker();\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/integration.test.js",
    "content": "import { storeFactory } from '../test/testUtils';\nimport { guessWord } from './actions';\nimport { setUserSecretWord } from './actions';\n\n/* Challenge #3 NOTE: \n   It's a sign that these tests weren't optimally designed that we had to\n   `giveUp: false` to every `expectedState`. How would you refactor the tests to\n   be more robust when adding new pieces of state? \n*/\n\ndescribe('guessWord action dispatcher', () => {\n  const secretWord = 'party';\n  const unsuccessfulGuess = 'train';\n  describe('no guessed words', () => {\n    let store;\n    const initialState = { secretWord };\n    beforeEach(() => {\n      store = storeFactory(initialState);\n    });\n    test('updates state correctly for unsuccessful guess', () => {\n      store.dispatch(guessWord(unsuccessfulGuess));\n      const newState = store.getState()\n      const expectedState = {\n        ...initialState,\n        success: false,\n        // Challenge #3, 4 and 5\n        gaveUp: false,\n        userEnter: null,\n        serverError: false,\n        // END: Challenge #3, 4 and 5\n        guessedWords: [{\n          guessedWord: unsuccessfulGuess,\n          letterMatchCount: 3\n        }]\n      };\n      expect(newState).toEqual(expectedState);\n    });\n    test('updates state correctly for successful guess', () => {\n      store.dispatch(guessWord(secretWord));\n      const newState = store.getState()\n      const expectedState = {\n        secretWord,\n        success: true,\n        // Challenge #3, 4 and 5\n        gaveUp: false,\n        userEnter: null,\n        serverError: false,\n        // END: Challenge #3, 4 and 5\n        guessedWords: [{\n          guessedWord: secretWord,\n          letterMatchCount: 5,\n        }],\n      };\n      expect(newState).toEqual(expectedState);\n    });\n  });\n  describe('some guessed words', () => {\n    const guessedWords = [ { guessedWord: 'agile', letterMatchCount: 1 } ];\n    const initialState = { guessedWords, secretWord }\n    let store;\n    beforeEach(() => {\n      store = storeFactory(initialState);\n    })\n    test('updates state correctly for unsuccessful guess', () => {\n      store.dispatch(guessWord(unsuccessfulGuess));\n      const newState = store.getState();\n      const expectedState = {\n        secretWord,\n        success: false,\n        // Challenge #3, 4 and 5\n        gaveUp: false,\n        userEnter: null,\n        serverError: false,\n        // END: Challenge #3, 4 and 5\n        guessedWords: [...guessedWords, { guessedWord: unsuccessfulGuess, letterMatchCount: 3 }]\n      };\n      expect(newState).toEqual(expectedState);\n    });\n    test('updates state correctly for successful guess', () => {\n      store.dispatch(guessWord(secretWord));\n      const newState = store.getState();\n      const expectedState = {\n        secretWord,\n        success: true,\n        // Challenge #3, 4 and 5\n        gaveUp: false,\n        userEnter: null,\n        serverError: false,\n        // END: Challenge #3, 4 and 5\n        guessedWords: [...guessedWords,\n          { guessedWord: secretWord, letterMatchCount: 5 }]\n      };\n      expect(newState).toEqual(expectedState);\n    });\n  });\n});\n\n// Challenge #4: Enter Secret Word\ndescribe('setUserSecretWord action dispatcher', () => {\n  // this is in the integration test section because it\n  // involves the setUserSecretWord action creator and two reducers\n  let store;\n  let newState;\n  \n  // this represents the word the user entered\n  const userSecretWord = 'lunch';\n\n  // this represents the word we got from the server\n  const initialState = { secretWord: 'party' };\n\n  // here I will run the action in the beforeEach, and\n  // check on each relevant piece of state separately\n  beforeEach(() => {\n    store = storeFactory(initialState);\n    store.dispatch(setUserSecretWord(userSecretWord));\n    newState = store.getState();\n  });\n\n  test('updates `secretWord` state correctly after entered word', () => {\n    expect(newState.secretWord).toBe(userSecretWord);\n  });\n  test('updates `userEnter` state correctly after entered word', () => {\n    expect(newState.userEnter).toBe('done');\n  });\n});\n// END: Challenge #4: Enter Secret Word"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/reducers/gaveUpReducer.js",
    "content": "// Challenge #3: Give Up Button\n\n/* NOTE: This is not the optimal way to track whether or not the user has given up. \n With two boolean pieces of state (success aveUp), we have four possibilities:\n \n success=false aveUp=false (user is playing the game)\n success=true aveUp=false (user gave up)\n success=false aveUp=true (user guessed correctly)\n success=true aveUp=true (will never logically happen)\n\n If I were starting from scratch, I would have one piece of state, called, say, 'status'\n with three possibilities: inProgress, victory, gaveUp\n\n To refactor to that new scheme now would make this challenge solution more \n confusing than necessary, however, so we'll live with the inefficiency.\n*/\n\nimport { actionTypes } from '../actions';\n\n/**\n * @function gaveUp\n * @param {boolean} state - Whether the user has given up.\n * @param {object} action - Action to be reduced.\n * @returns {boolean} - aveUp state.\n */\nexport default (state=false, action) => {\n  switch(action.type) {\n    case (actionTypes.GIVE_UP):\n      return true;\n    case (actionTypes.RESET_GAME):\n      return false;\n    default:\n      return state;\n  }\n}\n\n// END: Challenge #3: Give Up Button"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/reducers/gaveUpReducer.test.js",
    "content": "// Challenge #3: Give Up Button\nimport { actionTypes } from '../actions';\nimport gaveUpReducer from './gaveUpReducer';\n\ntest('returns default initial state of `false` when no action is passed', () => {\n  const newState = gaveUpReducer(undefined, {});\n  expect(newState).toBe(false);\n});\ntest('returns state of true upon receiving an action of type `GIVE_UP`', () => {\n  const newState = gaveUpReducer(false, { type: actionTypes.GIVE_UP });\n  expect(newState).toBe(true);\n});\n\ntest('returns state of false upon receiving an action of type `RESET_GAME`', () => {\n  // start with giveUp true, since giveUp is false by default\n  const newState = gaveUpReducer(true, { type: actionTypes.RESET_GAME });\n  expect(newState).toBe(false);\n});\n\n// END: Challenge #3: Give Up Button"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/reducers/guessedWordsReducer.js",
    "content": "import { actionTypes } from '../actions';\n\n/**\n * @function guessedWordsReducer\n * @param {array} state - Array of guessed words.\n * @param {object} action - action to be reduced.\n * @returns {array} - new guessedWords state.\n */\n export default (state=[], action) => {\n  switch(action.type) {\n    case actionTypes.GUESS_WORD:\n      return [...state, action.payload];\n    // Challenge #2: Reset Game\n    case (actionTypes.RESET_GAME):\n      return [];\n    // END: Challenge #2: Reset Game\n    default:\n      return state;\n  }\n}\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/reducers/guessedWordsReducer.test.js",
    "content": "// Challenge #2: Reset Game\nimport { actionTypes } from '../actions';\nimport guessedWordsReducer from './guessedWordsReducer';\n\n// Note: Adding guessed words is tested via integration tests in Input.test.js\n\ntest('returns state of `[]` upon receiving an action of type `RESET_GAME`', () => {\n  // start with non-zero guessed words\n  const initialState = [{ guessedWord: 'train', letterMatchCount: 3 }];\n  const newState = guessedWordsReducer(initialState, { type: actionTypes.RESET_GAME });\n  expect(newState).toEqual([]);\n});\n// END: Challenge #2: Reset Game\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/reducers/index.js",
    "content": "import { combineReducers } from 'redux';\nimport success from './successReducer';\nimport guessedWords from './guessedWordsReducer';\nimport secretWord from './secretWordReducer';\nimport userEnter from './userEnterReducer';\n\n// Challenge #3: Give Up Button\nimport gaveUp from './gaveUpReducer';\n// END: Challenge #3: Give Up Button\n\n// Challenge #5: Server Error\nimport serverError from './serverErrorReducer';\n// END: Challenge #5: Server Error\n\n\nexport default combineReducers({\n  success,\n  guessedWords,\n  secretWord,\n  // Challenge #3: Give Up Button\n  gaveUp,\n  // END: Challenge #3: Give Up Button\n  // Challenge #4: Enter Secret Word\n  userEnter,\n  // END: Challenge #4: Enter Secret Word\n  // Challenge 5: Server Error\n  serverError,\n  // END: Challenge #5: Server Error\n});\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/reducers/secretWordReducer.js",
    "content": "import { actionTypes } from '../actions';\n\n/**\n * @function secretWordReducer\n * @param {string} state - State before reducer.\n * @param {object} action - Action sent to reducer.\n * @returns {string} - New state (secret word payload from action).\n */\nexport default (state=null, action) => {\n  switch (action.type) {\n    case actionTypes.SET_SECRET_WORD:\n      return action.payload;\n    default:\n      return state;\n  }\n}\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/reducers/serverErrorReducer.js",
    "content": "// Challenge #5: Server Error\nimport { actionTypes } from '../actions';\n\n/**\n * @function serverErrorReducer\n * @param {string} state - State before reducer.\n * @param {object} action - Action sent to reducer.\n * @returns {string} - New state (depending on action type).\n */\nexport default (state=false, action) => {\n  switch (action.type) {\n    case actionTypes.SERVER_ERROR:\n      return true;\n    default:\n      return state;\n  }\n}\n// END: Challenge #5: Server Error\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/reducers/serverErrorReducer.test.js",
    "content": "// Challenge #5: Server Error\nimport { actionTypes } from '../actions';\nimport serverErrorReducer from './serverErrorReducer';\n\ntest('returns default initial state of `false` when no action is passed', () => {\n  const newState = serverErrorReducer(undefined, {});\n  expect(newState).toBe(false);\n});\ntest('returns state of `true` upon receiving an action of type `SERVER_ERROR`', () => {\n  const newState = serverErrorReducer(undefined, { type: actionTypes.SERVER_ERROR });\n  expect(newState).toBe(true);\n});\n// END: Challenge #5: Server Error"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/reducers/successReducer.js",
    "content": "import { actionTypes } from '../actions';\n\n/**\n * @function successReducer\n * @param {boolean} state - Whether the user has guessed correctly.\n * @param {object} action - Action to be reduced.\n * @returns {boolean} - New success state.\n */\nexport default (state=false, action) => {\n  switch(action.type) {\n    case (actionTypes.CORRECT_GUESS):\n      return true;\n    // Challenge #2: Reset Game\n    case (actionTypes.RESET_GAME):\n      return false;\n    // END: Challenge #2: Reset Game\n    default:\n      return state;\n  }\n}\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/reducers/successReducer.test.js",
    "content": "import { actionTypes } from '../actions';\nimport successReducer from './successReducer';\n\ntest('returns default initial state of `false` when no action is passed', () => {\n  const newState = successReducer(undefined, {});\n  expect(newState).toBe(false);\n});\ntest('returns state of true upon receiving an action of type `CORRECT_GUESS`', () => {\n  const newState = successReducer(undefined, { type: actionTypes.CORRECT_GUESS });\n  expect(newState).toBe(true);\n});\n\n// Challenge #2: Reset Game\ntest('returns state of false upon receiving an action of type `RESET_GAME`', () => {\n  // start with success true, since success is false by default\n  const newState = successReducer(true, { type: actionTypes.RESET_GAME });\n  expect(newState).toBe(false);\n});\n// END: Challenge #2: Reset Game\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/reducers/userEnterReducer.js",
    "content": "// Challenge #4: Enter Secret Word\nimport { actionTypes } from '../actions';\n\n/**\n * @function userEnterReducer\n * @param {string} state - State before reducer.\n * @param {object} action - Action sent to reducer.\n * @returns {string} - New state (depending on action type).\n */\nexport default (state=null, action) => {\n  switch (action.type) {\n    case actionTypes.USER_ENTERING:\n      return 'inProgress';\n    case actionTypes.USER_ENTERED:\n      return 'done';\n    case actionTypes.RESET_GAME:\n      return null;\n    default:\n      return state;\n  }\n}\n// END: Challenge #4: Enter Secret Word\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/reducers/userEnterReducer.test.js",
    "content": "// Challenge #4: Enter Secret Word\nimport { actionTypes } from '../actions';\nimport userEnterReducer from './userEnterReducer';\n\ntest('returns default initial state of `null` when no action is passed', () => {\n  const newState = userEnterReducer(undefined, {});\n  expect(newState).toBeNull();\n});\ntest('returns state of \"inProgress\" upon receiving an action of type `USER_ENTERING`', () => {\n  const newState = userEnterReducer(undefined, { type: actionTypes.USER_ENTERING });\n  expect(newState).toBe('inProgress');\n});\ntest('returns state of \"done\" upon receiving an action of type `USER_ENTERED`', () => {\n  // state is most likely to be 'inProgress' at this point\n  const newState = userEnterReducer('inProgress', { type: actionTypes.USER_ENTERED });\n  expect(newState).toBe('done');\n});\ntest('returns state of `null` upon receiving an action of type `RESET_GAME`', () => {\n  // state is most likely to be 'done' at this point\n  const newState = userEnterReducer('done', { type: actionTypes.RESET_GAME });\n  expect(newState).toBeNull();\n});\n// END: Challenge #4: Enter Secret Word\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/registerServiceWorker.js",
    "content": "// In production, we register a service worker to serve assets from local cache.\n\n// This lets the app load faster on subsequent visits in production, and gives\n// it offline capabilities. However, it also means that developers (and users)\n// will only see deployed updates on the \"N+1\" visit to a page, since previously\n// cached resources are updated in the background.\n\n// To learn more about the benefits of this model, read https://goo.gl/KwvDNy.\n// This link also includes instructions on opting out of this behavior.\n\nconst isLocalhost = Boolean(\n  window.location.hostname === 'localhost' ||\n    // [::1] is the IPv6 localhost address.\n    window.location.hostname === '[::1]' ||\n    // 127.0.0.1/8 is considered localhost for IPv4.\n    window.location.hostname.match(\n      /^127(?:\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/\n    )\n);\n\nexport default function register() {\n  if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {\n    // The URL constructor is available in all browsers that support SW.\n    const publicUrl = new URL(process.env.PUBLIC_URL, window.location);\n    if (publicUrl.origin !== window.location.origin) {\n      // Our service worker won't work if PUBLIC_URL is on a different origin\n      // from what our page is served on. This might happen if a CDN is used to\n      // serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374\n      return;\n    }\n\n    window.addEventListener('load', () => {\n      const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;\n\n      if (isLocalhost) {\n        // This is running on localhost. Lets check if a service worker still exists or not.\n        checkValidServiceWorker(swUrl);\n\n        // Add some additional logging to localhost, pointing developers to the\n        // service worker/PWA documentation.\n        navigator.serviceWorker.ready.then(() => {\n          console.log(\n            'This web app is being served cache-first by a service ' +\n              'worker. To learn more, visit https://goo.gl/SC7cgQ'\n          );\n        });\n      } else {\n        // Is not local host. Just register service worker\n        registerValidSW(swUrl);\n      }\n    });\n  }\n}\n\nfunction registerValidSW(swUrl) {\n  navigator.serviceWorker\n    .register(swUrl)\n    .then(registration => {\n      registration.onupdatefound = () => {\n        const installingWorker = registration.installing;\n        installingWorker.onstatechange = () => {\n          if (installingWorker.state === 'installed') {\n            if (navigator.serviceWorker.controller) {\n              // At this point, the old content will have been purged and\n              // the fresh content will have been added to the cache.\n              // It's the perfect time to display a \"New content is\n              // available; please refresh.\" message in your web app.\n              console.log('New content is available; please refresh.');\n            } else {\n              // At this point, everything has been precached.\n              // It's the perfect time to display a\n              // \"Content is cached for offline use.\" message.\n              console.log('Content is cached for offline use.');\n            }\n          }\n        };\n      };\n    })\n    .catch(error => {\n      console.error('Error during service worker registration:', error);\n    });\n}\n\nfunction checkValidServiceWorker(swUrl) {\n  // Check if the service worker can be found. If it can't reload the page.\n  fetch(swUrl)\n    .then(response => {\n      // Ensure service worker exists, and that we really are getting a JS file.\n      if (\n        response.status === 404 ||\n        response.headers.get('content-type').indexOf('javascript') === -1\n      ) {\n        // No service worker found. Probably a different app. Reload the page.\n        navigator.serviceWorker.ready.then(registration => {\n          registration.unregister().then(() => {\n            window.location.reload();\n          });\n        });\n      } else {\n        // Service worker found. Proceed as normal.\n        registerValidSW(swUrl);\n      }\n    })\n    .catch(() => {\n      console.log(\n        'No internet connection found. App is running in offline mode.'\n      );\n    });\n}\n\nexport function unregister() {\n  if ('serviceWorker' in navigator) {\n    navigator.serviceWorker.ready.then(registration => {\n      registration.unregister();\n    });\n  }\n}\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/src/setupTests.js",
    "content": "import Enzyme, { shallow } from 'enzyme';\nimport EnzymeAdapter from 'enzyme-adapter-react-16';\n\nEnzyme.configure({\n  adapter: new EnzymeAdapter(),\n  disableLifecycleMethods: true,\n});\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/SOLUTIONS for Jotto Redux Challenges/test/testUtils.js",
    "content": "import checkPropTypes from 'check-prop-types';\nimport { createStore, applyMiddleware } from 'redux';\n\nimport rootReducer from '../src/reducers';\nimport { middlewares } from '../src/configureStore';\n\n/**\n * Create a testing store with imported reducers, middleware, and initial state.\n *  globals: rootReducer, middlewares.\n * @param {object} initialState - Initial state for store.\n * @function storeFactory\n * @returns {Store} - Redux store.\n */\nexport const storeFactory = (initialState) => {\n  const createStoreWithMiddleware = applyMiddleware(...middlewares)(createStore)\n  return createStoreWithMiddleware(rootReducer, initialState);\n}\n\n/**\n * Return node(s) with the given data-test attribute.\n * @param {ShallowWrapper} wrapper - Enzyme shallow wrapper.\n * @param {string} val - Value of data-test attribute for search.\n * @returns {ShallowWrapper}\n */\nexport const findByTestAttr = (wrapper, val) => {\n  return wrapper.find(`[data-test=\"${val}\"]`);\n}\n\nexport const checkProps = (component, conformingProps) => {\n  const propError = checkPropTypes(\n    component.propTypes,\n    conformingProps,\n    'prop',\n    component.name);\n  expect(propError).toBeUndefined();\n}\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/jotto-redux-class-based/.gitignore",
    "content": "# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.\n\n# dependencies\n/node_modules\n/.pnp\n.pnp.js\n\n# testing\n/coverage\n\n# production\n/build\n\n# misc\n.DS_Store\n.env.local\n.env.development.local\n.env.test.local\n.env.production.local\n\nnpm-debug.log*\nyarn-debug.log*\nyarn-error.log*\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/jotto-redux-class-based/README.md",
    "content": "# Jotto\n### A React / Redux app used to demonstrate testing\n\n## Branches\n\n*  `master`\n\n  This branch represents the project at the end of the instructional videos, without any of the challenges completed.\n\n* `jotto-challenges`\n\n  [This branch](https://github.com/flyrightsister/udemy-react-testing-projects/tree/jotto-challenges/jotto) contains solutions to the challenges. You can also find challenge solutions in the [SOLUTIONS for Jotto Redux Challenges](https://github.com/flyrightsister/udemy-react-testing-projects/tree/master/SOLUTIONS%20for%20Jotto%20Redux%20Challenges) folder.\n\n## Challenges\n\n### 1. Number of Guesses\n  ![Number of Guesses Wireframe](https://github.com/flyrightsister/udemy-react-testing-projects/blob/master/jotto-redux/readme-images/number-of-guesses_wireframe.png)\n\n  * _Note_: Try to accomplish this _without_ adding a new piece of state!\n  * Add “guess number” column to the \"guessed words\" table\n    * The first guess should show 1, second guess 2, etc.\n  * Add a component that displays total guesses as shown in wireframe\n\n### 2. Reset Game\n  ![Reset Game Wireframe](https://github.com/flyrightsister/udemy-react-testing-projects/blob/master/jotto-redux/readme-images/new-game_wireframe.png)\n  * Create a “New word” button component\n    * only display after successful guess\n  * Upon click, reset the game with a new word from the server\n  * _Note_: This can be done with a connected component (which lends itself to state testing similar to `Input.js`) or with an unconnected component which receives the action creator from the parent `App.js` component (which will require unit testing for action creators and reducers instead, as using a store with an unconnected component is not covered in this course). The solution in the `jotto-challenges` branch covers the second approach.\n\n### 3. “Give up” Button\n  ![Give Up Button Wireframe](https://github.com/flyrightsister/udemy-react-testing-projects/blob/master/jotto-redux/readme-images/give-up-button_wireframe.png)\n  ![After Give Up Click Wireframe](https://github.com/flyrightsister/udemy-react-testing-projects/blob/master/jotto-redux/readme-images/after-give-up_wireframe.png)  \n  \n  * Create a “Give up” button\n    * only display when word has not been guessed correctly\n  * Upon click:\n    * Show secret word\n    * Display \"better luck next time\" message\n    * Display “new word” button component\n\n### 4. User inputs secret word\n  ![Enter Secret Word Button Wireframe](https://github.com/flyrightsister/udemy-react-testing-projects/blob/master/jotto-redux/readme-images/enter-secret-word_wireframe.png)  \n  ![Secret Word Entry Form Wireframe](https://github.com/flyrightsister/udemy-react-testing-projects/blob/master/jotto-redux/readme-images/secret-word-entry-form_wireframe.png)  \n\n  * _Note: This one is quite involved, with a new piece of state, Redux Thunk, and testing that an action creator receives the correct argument. Not for the faint of heart! It is great for using existing tests to see whether new code breaks old functionality._\n  * Add a button for the user to input the secret word\n    * This way, the user can play against a friend\n  * After submission, the game should use the user’s secret word, not a word from the server\n  * This button should disapppear once the user has nonzero `guessedWords`\n    * Should disappear whether the word came from the server or user input\n\n### 5. Random Word Server Error\n  ![Random Word Server Error Wireframe](https://github.com/flyrightsister/udemy-react-testing-projects/blob/master/jotto-redux/readme-images/random-word-server-error_wireframe.png) \n\n  * Display an error if:\n    * There’s a problem contacting the “random word” server\n    * The server responds with status 4xx or 5xx\n\n### 6. Use Wordnik to get secret word\n  * Get a [Wordnik auth token](http://developer.wordnik.com/)\n  * Use the [words/randomWord](http://developer.wordnik.com/docs.html) endpoint (instead of the random word server that came with this course)\n \n## Credits\nThis project was bootstrapped with [Create React App](https://github.com/facebookincubator/create-react-app).\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/jotto-redux-class-based/package.json",
    "content": "{\n  \"name\": \"jotto\",\n  \"version\": \"0.1.0\",\n  \"private\": true,\n  \"dependencies\": {\n    \"axios\": \"^0.19.0\",\n    \"check-prop-types\": \"^1.1.2\",\n    \"enzyme\": \"^3.10.0\",\n    \"enzyme-adapter-react-16\": \"^1.14.0\",\n    \"jest-enzyme\": \"^7.1.1\",\n    \"moxios\": \"^0.4.0\",\n    \"prop-types\": \"^15.7.2\",\n    \"react\": \"^16.9.0\",\n    \"react-dom\": \"^16.9.0\",\n    \"react-redux\": \"^7.1.1\",\n    \"react-scripts\": \"3.1.1\",\n    \"redux\": \"^4.0.4\",\n    \"redux-thunk\": \"^2.3.0\"\n  },\n  \"scripts\": {\n    \"start\": \"react-scripts start\",\n    \"build\": \"react-scripts build\",\n    \"test\": \"react-scripts test\",\n    \"eject\": \"react-scripts eject\"\n  },\n  \"eslintConfig\": {\n    \"extends\": \"react-app\"\n  },\n  \"browserslist\": {\n    \"production\": [\n      \">0.2%\",\n      \"not dead\",\n      \"not op_mini all\"\n    ],\n    \"development\": [\n      \"last 1 chrome version\",\n      \"last 1 firefox version\",\n      \"last 1 safari version\"\n    ]\n  }\n}\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/jotto-redux-class-based/public/index.html",
    "content": "<!DOCTYPE html>\n<html lang=\"en\">\n  <head>\n    <meta charset=\"utf-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\">\n    <meta name=\"theme-color\" content=\"#000000\">\n    <!--\n      manifest.json provides metadata used when your web app is added to the\n      homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/\n    -->\n    <link rel=\"manifest\" href=\"%PUBLIC_URL%/manifest.json\">\n    <link rel=\"shortcut icon\" href=\"%PUBLIC_URL%/favicon.ico\">\n    <link rel=\"stylesheet\" href=\"https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css\" integrity=\"sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB\" crossorigin=\"anonymous\">\n    <!--\n      Notice the use of %PUBLIC_URL% in the tags above.\n      It will be replaced with the URL of the `public` folder during the build.\n      Only files inside the `public` folder can be referenced from the HTML.\n\n      Unlike \"/favicon.ico\" or \"favicon.ico\", \"%PUBLIC_URL%/favicon.ico\" will\n      work correctly both with client-side routing and a non-root public URL.\n      Learn how to configure a non-root public URL by running `npm run build`.\n    -->\n    <title>React App</title>\n  </head>\n  <body>\n    <noscript>\n      You need to enable JavaScript to run this app.\n    </noscript>\n    <div id=\"root\"></div>\n    <!--\n      This HTML file is a template.\n      If you open it directly in the browser, you will see an empty page.\n\n      You can add webfonts, meta tags, or analytics to this file.\n      The build step will place the bundled scripts into the <body> tag.\n\n      To begin the development, run `npm start` or `yarn start`.\n      To create a production bundle, use `npm run build` or `yarn build`.\n    -->\n  </body>\n</html>\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/jotto-redux-class-based/public/manifest.json",
    "content": "{\n  \"short_name\": \"React App\",\n  \"name\": \"Create React App Sample\",\n  \"icons\": [\n    {\n      \"src\": \"favicon.ico\",\n      \"sizes\": \"64x64 32x32 24x24 16x16\",\n      \"type\": \"image/x-icon\"\n    }\n  ],\n  \"start_url\": \"./index.html\",\n  \"display\": \"standalone\",\n  \"theme_color\": \"#000000\",\n  \"background_color\": \"#ffffff\"\n}\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/jotto-redux-class-based/src/App.css",
    "content": ""
  },
  {
    "path": "LEGACY-class-based-redux-components/jotto-redux-class-based/src/App.js",
    "content": "import React, { Component } from 'react';\nimport { connect } from 'react-redux';\nimport './App.css';\n\nimport GuessedWords from './GuessedWords';\nimport Congrats from './Congrats';\nimport Input from './Input';\nimport { getSecretWord } from './actions';\n\nexport class UnconnectedApp extends Component {\n  /**\n   * @method componentDidMount\n   * @returns {undefined}\n   */\n  componentDidMount() {\n    // get the secret word\n    this.props.getSecretWord();\n  }\n\n  render() {\n    return (\n      <div className=\"container\">\n        <h1>Jotto</h1>\n        <Congrats success={this.props.success} />\n        <Input />\n        <GuessedWords guessedWords={this.props.guessedWords} />\n      </div>\n    );\n  }\n}\n\nconst mapStateToProps = (state) => {\n  const { success, guessedWords, secretWord } = state;\n  return { success, guessedWords, secretWord };\n}\n\nexport default connect(mapStateToProps, { getSecretWord })(UnconnectedApp);\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/jotto-redux-class-based/src/App.test.js",
    "content": "import React from 'react';\nimport { shallow } from 'enzyme';\n\nimport { storeFactory } from '../test/testUtils';\nimport App, { UnconnectedApp } from './App';\n\n/**\n * @function setup\n * @param {object} state - State for this setup.\n * @returns {ShallowWrapper}\n */\nconst setup = (state={}) => {\n  const store = storeFactory(state);\n  const wrapper = shallow(<App store={store} />).dive().dive();\n  return wrapper;\n}\n\ndescribe('redux properties', () => {\n  test('has access to `success` state', () => {\n    const success = true;\n    const wrapper = setup({ success });\n    const successProp = wrapper.instance().props.success;\n    expect(successProp).toBe(success);\n  });\n  test('has access to `secretWord` state', () => {\n    const secretWord = 'party';\n    const wrapper = setup({ secretWord });\n    const secretWordProp = wrapper.instance().props.secretWord;\n    expect(secretWordProp).toBe(secretWord);\n  });\n  test('has access to `guessedWords` state', () => {\n    const guessedWords = [{ guessedWord: 'train', letterMatchCount: 3 }];\n    const wrapper = setup({ guessedWords });\n    const guessedWordsProp = wrapper.instance().props.guessedWords;\n    expect(guessedWordsProp).toEqual(guessedWords);\n  });\n  test('`getSecretWord` action creator is a function on the props', () => {\n    const wrapper = setup();\n    const getSecretWordProp = wrapper.instance().props.getSecretWord;\n    expect(getSecretWordProp).toBeInstanceOf(Function);\n  });\n});\n\ntest('`getSecretWord` runs on App mount', () => {\n  const getSecretWordMock = jest.fn();\n\n  const props = {\n    getSecretWord: getSecretWordMock,\n    success: false,\n    guessedWords: [],\n  }\n\n  // set up app component with getSecretWordMock as the getSecretWord prop\n  const wrapper = shallow(<UnconnectedApp {...props} />);\n\n  // run lifecycle method\n  wrapper.instance().componentDidMount();\n\n  // check to see if mock ran\n  const getSecretWordCallCount = getSecretWordMock.mock.calls.length;\n\n  expect(getSecretWordCallCount).toBe(1);\n\n});\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/jotto-redux-class-based/src/Congrats.js",
    "content": "import React from 'react';\nimport PropTypes from 'prop-types';\n\n/**\n * Functional react component for congratulatory message.\n * @function\n * @param {object} props - React props.\n * @returns {JSX.Element} - Rendered component (or null if `success` prop is false).\n */\nconst Congrats = (props) => {\n  if (props.success) {\n    return (\n      <div data-test=\"component-congrats\" className=\"alert alert-success\">\n        <span data-test=\"congrats-message\">\n          Congratulations! You guessed the word!\n        </span>\n      </div>\n    );\n  } else {\n    return (\n      <div data-test=\"component-congrats\" />\n    );\n  }\n};\n\nCongrats.propTypes = {\n  success: PropTypes.bool.isRequired,\n};\n\nexport default Congrats;\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/jotto-redux-class-based/src/Congrats.test.js",
    "content": "import React from 'react';\nimport { shallow } from 'enzyme';\n\nimport { findByTestAttr, checkProps } from '../test/testUtils';\nimport Congrats from './Congrats';\n\nconst defaultProps = { success: false };\n\n/**\n* Factory function to create a ShallowWrapper for the Congrats component.\n* @function setup\n* @param {object} props - Component props specific to this setup.\n* @returns {ShallowWrapper}\n*/\nconst setup = (props={}) => {\n  const setupProps = { ...defaultProps, ...props };\n  return shallow(<Congrats {...setupProps} />)\n}\n\ntest('renders without error', () => {\n  const wrapper = setup();\n  const component = findByTestAttr(wrapper, 'component-congrats');\n  expect(component.length).toBe(1);\n});\ntest('renders no text when `success` prop is false', () => {\n  const wrapper = setup({ success: false });\n  const component = findByTestAttr(wrapper, 'component-congrats');\n  expect(component.text()).toBe('');\n});\ntest('renders non-empty congrats message when `success` prop is true', () => {\n  const wrapper = setup({ success: true });\n  const message = findByTestAttr(wrapper, 'congrats-message');\n  expect(message.text().length).not.toBe(0);\n});\ntest('does not throw warning with expected props', () => {\n  const expectedProps = { success: false };\n  checkProps(Congrats, expectedProps);\n});\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/jotto-redux-class-based/src/GuessedWords.js",
    "content": "import React from 'react';\nimport PropTypes from 'prop-types';\n\nconst GuessedWords = (props) => {\n  let contents\n  if (props.guessedWords.length === 0) {\n    contents = (\n      <span data-test=\"guess-instructions\">\n        Try to guess the secret word!\n      </span>\n    );\n  } else {\n    const guessedWordsRows = props.guessedWords.map((word, index) => (\n      <tr data-test=\"guessed-word\" key={ index }>\n        <td>{ word.guessedWord }</td>\n        <td>{ word.letterMatchCount }</td>\n      </tr>\n    ));\n    contents = (\n      <div data-test=\"guessed-words\">\n        <h3>Guessed Words</h3>\n        <table className=\"table table-sm\">\n          <thead className=\"thead-light\">\n            <tr><th>Guess</th><th>Matching Letters</th></tr>\n          </thead>\n          <tbody>\n            { guessedWordsRows }\n          </tbody>\n        </table>\n      </div>\n    );\n  }\n  return (\n    <div data-test=\"component-guessed-words\">\n      { contents }\n    </div>\n  );\n};\n\nGuessedWords.propTypes = {\n  guessedWords: PropTypes.arrayOf(\n    PropTypes.shape({\n      guessedWord: PropTypes.string.isRequired,\n      letterMatchCount: PropTypes.number.isRequired,\n    })\n  ).isRequired,\n};\n\nexport default GuessedWords;\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/jotto-redux-class-based/src/GuessedWords.test.js",
    "content": "import React from 'react';\nimport { shallow } from 'enzyme';\nimport { findByTestAttr, checkProps } from '../test/testUtils';\nimport GuessedWords from './GuessedWords';\n\nconst defaultProps = {\n  guessedWords: [{ guessedWord: 'train', letterMatchCount: 3 }],\n};\n\n/**\n* Factory function to create a ShallowWrapper for the GuessedWords component.\n* @function setup\n* @param {object} props - Component props specific to this setup.\n* @returns {ShallowWrapper}\n*/\nconst setup = (props={}) => {\n  const setupProps = { ...defaultProps, ...props };\n  return shallow(<GuessedWords {...setupProps } />)\n};\n\ntest('does not throw warning with expected props', () => {\n  checkProps(GuessedWords, defaultProps);\n});\n\ndescribe('if there are no words guessed', () => {\n  let wrapper\n  beforeEach(() => {\n    wrapper = setup({ guessedWords: [] });\n  });\n  test('renders without error', () => {\n    const component = findByTestAttr(wrapper, 'component-guessed-words');\n    expect(component.length).toBe(1);\n  });\n  test('renders instructions to guess a word', () => {\n    const instructions = findByTestAttr(wrapper, 'guess-instructions');\n    expect(instructions.text().length).not.toBe(0);\n  });\n});\ndescribe('if there are words guessed', () => {\n  let wrapper;\n  const guessedWords = [\n    { guessedWord: 'train', letterMatchCount: 3 },\n    { guessedWord: 'agile', letterMatchCount: 1 },\n    { guessedWord: 'party', letterMatchCount: 5 },\n  ];\n  beforeEach(() => {\n    wrapper = setup({ guessedWords });\n  });\n  test ('renders without error', () => {\n    const component = findByTestAttr(wrapper, 'component-guessed-words');\n    expect(component.length).toBe(1);\n  });\n  test('renders \"guessed words\" section', () => {\n    const guessedWordsNode = findByTestAttr(wrapper, 'guessed-words');\n    expect(guessedWordsNode.length).toBe(1);\n  });\n  test('correct number of guessed words', () => {\n    const guessedWordNodes = findByTestAttr(wrapper, 'guessed-word');\n    expect(guessedWordNodes.length).toBe(guessedWords.length);\n  });\n});\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/jotto-redux-class-based/src/Input.js",
    "content": "import React, { Component } from 'react';\nimport { connect } from 'react-redux';\n\nimport { guessWord } from './actions';\n\nexport class UnconnectedInput extends Component {\n  /**\n   * @method constructor\n   * @param {object} props - Component props.\n   * @returns {undefined}\n   */\n  constructor(props) {\n    super(props);\n\n    // initialize state\n    this.state = { currentGuess: null }\n\n    // bind this for submitGuessedWord\n    this.submitGuessedWord = this.submitGuessedWord.bind(this);\n  }\n  submitGuessedWord(evt) {\n    evt.preventDefault();\n    const guessedWord = this.state.currentGuess;\n\n    if(guessedWord && guessedWord.length > 0) {\n      this.props.guessWord(guessedWord);\n      this.setState({ currentGuess: '' })\n    }\n  }\n  render() {\n    const contents = this.props.success\n      ? null\n      : (\n        <form className=\"form-inline\">\n          <input\n            data-test=\"input-box\"\n            className=\"mb-2 mx-sm-3\"\n            id=\"word-guess\"\n            type=\"text\"\n            value={this.state.currentGuess}\n            onChange={(evt) => this.setState({ currentGuess: evt.target.value })}\n            placeholder=\"enter guess\" />\n          <button\n            data-test=\"submit-button\"\n            onClick={(evt) => this.submitGuessedWord(evt)}\n            className=\"btn btn-primary mb-2\"\n            type=\"submit\">\n            Submit\n          </button>\n        </form>\n      );\n    return (\n      <div data-test=\"component-input\">\n        { contents }\n      </div>\n    )\n  }\n};\n\nconst mapStateToProps = ({ success }) => {\n  return { success };\n}\n\nexport default connect(mapStateToProps, { guessWord })(UnconnectedInput);\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/jotto-redux-class-based/src/Input.test.js",
    "content": "import React from 'react';\nimport { shallow } from 'enzyme';\n\nimport { findByTestAttr, storeFactory } from '../test/testUtils';\nimport Input, { UnconnectedInput } from './Input';\n\n/**\n* Factory function to create a ShallowWrapper for the Input component.\n* @function setup\n* @param {object} initialState - Initial state for this setup.\n* @returns {ShallowWrapper}\n*/\nconst setup = (initialState={}) => {\n  const store = storeFactory(initialState);\n  const wrapper = shallow(<Input store={store} />).dive().dive();\n  return wrapper;\n}\n\ndescribe('render', () => {\n  describe('word has not been guessed', () => {\n    let wrapper;\n    beforeEach(() => {\n      const initialState = { success: false };\n      wrapper = setup(initialState);\n    })\n    test('renders component without error', () => {\n      const component = findByTestAttr(wrapper, 'component-input');\n      expect(component.length).toBe(1);\n    });\n    test('renders input box', () => {\n      const inputBox = findByTestAttr(wrapper, 'input-box');\n      expect(inputBox.length).toBe(1);\n    });\n    test('renders submit button', () => {\n      const submitButton = findByTestAttr(wrapper, 'submit-button');\n      expect(submitButton.length).toBe(1);\n    });\n  });\n  describe('word has been guessed', () => {\n    let wrapper;\n    beforeEach(() => {\n      const initialState = { success: true };\n      wrapper = setup(initialState);\n    });\n    test('renders component without error', () => {\n      const component = findByTestAttr(wrapper, 'component-input');\n      expect(component.length).toBe(1);\n    });\n    test('does not render input box', () => {\n      const inputBox = findByTestAttr(wrapper, 'input-box');\n      expect(inputBox.length).toBe(0);\n    });\n    test('does not render submit button', () => {\n      const submit = findByTestAttr(wrapper, 'submit-button');\n      expect(submit.length).toBe(0);\n    });\n  });\n});\n\ndescribe('redux props', () => {\n  test('has success piece of state as prop', () => {\n    const success = true;\n    const wrapper = setup({ success });\n    const successProp = wrapper.instance().props.success;\n    expect(successProp).toBe(success);\n  });\n  test('`guessWord` action creator is a function prop', () => {\n    const wrapper = setup();\n    const guessWordProp = wrapper.instance().props.guessWord;\n    expect(guessWordProp).toBeInstanceOf(Function);\n  })\n});\n\ndescribe('`guessWord` action creator', () => {\n  let guessWordMock;\n  let wrapper;\n  const guessedWord = \"train\";\n  beforeEach(() => {\n    // create a mock function for `getSecretWord`\n    guessWordMock = jest.fn();\n\n    // set up Input, with guessWordMock as a prop\n    wrapper = shallow(<UnconnectedInput guessWord={guessWordMock} />);\n\n    // add value to input box\n    wrapper.setState({ currentGuess: guessedWord });\n\n    // simulate click on submit button\n    const submit = findByTestAttr(wrapper, 'submit-button');\n    submit.simulate('click', { preventDefault() {} });\n  });\n  test('`guessWord` was called once', () => {\n    const guessWordCallCount = guessWordMock.mock.calls.length;\n    expect(guessWordCallCount).toBe(1);\n  });\n  test('calls `guessWord with input value as argument`', () => {\n    const guessWordArg = guessWordMock.mock.calls[0][0];\n    expect(guessWordArg).toBe(guessedWord);\n  });\n  test('input box clears on submit', () => {\n    expect(wrapper.state('currentGuess')).toBe('');\n  })\n\n});\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/jotto-redux-class-based/src/actions/index.js",
    "content": "import axios from 'axios';\n\nimport { getLetterMatchCount } from '../helpers';\n\nexport const actionTypes = {\n  CORRECT_GUESS: 'CORRECT_GUESS',\n  GUESS_WORD: 'GUESS_WORD',\n  SET_SECRET_WORD: 'SET_SECRET_WORD',\n};\n\n/**\n * Returns Redux Thunk function that dispatches GUESS_WORD action\n *     and (conditionally) CORRECT_GUESS action\n * @function guessWord\n * @param {string} guessedWord - Guessed word.\n * @returns {function} - Redux Thunk function.\n*/\nexport const guessWord = (guessedWord) => {\n  return function(dispatch, getState) {\n    const secretWord = getState().secretWord;\n    const letterMatchCount = getLetterMatchCount(guessedWord, secretWord);\n\n    dispatch({\n      type: actionTypes.GUESS_WORD,\n      payload: { guessedWord, letterMatchCount }\n    });\n\n    if (guessedWord === secretWord) {\n      dispatch({ type: actionTypes.CORRECT_GUESS });\n    }\n\n  };\n};\n\n/**\n * Returns Redux Thunk function that initiates an axios request \n *    and dispatches the response as a 'SET_SECRET_WORD' action\n * @returns {function} - Redux Thunk function. \n */\nexport const getSecretWord = () => {\n  return (dispatch) => {\n    return axios.get('http://localhost:3030')\n      .then(response => {\n        dispatch({\n          type: actionTypes.SET_SECRET_WORD,\n          payload: response.data\n        });\n      });\n  }\n}\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/jotto-redux-class-based/src/actions/index.test.js",
    "content": "import moxios from 'moxios';\n\nimport { storeFactory } from '../../test/testUtils';\nimport { getSecretWord } from './';\n\ndescribe('getSecretWord action creator', () => {\n  beforeEach(() => {\n    moxios.install();\n  });\n  afterEach(() => {\n    moxios.uninstall();\n  });\n  test('adds response word to state', () => {\n    const secretWord = 'party';\n    const store = storeFactory();\n\n    moxios.wait(() => {\n      const request = moxios.requests.mostRecent();\n      request.respondWith({\n        status: 200,\n        response: secretWord,\n      });\n    });\n\n    return store.dispatch(getSecretWord())\n      .then(() => {\n        const newState = store.getState();\n        expect(newState.secretWord).toBe(secretWord);\n      })\n  });\n});\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/jotto-redux-class-based/src/configureStore.js",
    "content": "import { createStore, applyMiddleware } from 'redux';\nimport ReduxThunk from 'redux-thunk';\nimport rootReducer from './reducers';\n\nexport const middlewares = [ReduxThunk];\nconst createStoreWithMiddleware = applyMiddleware(...middlewares)(createStore);\n\nexport default createStoreWithMiddleware(rootReducer);\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/jotto-redux-class-based/src/helpers/index.js",
    "content": "/**\n * @method getLetterMatchCount\n * @param {string} guessedWord - Guessed word.\n * @param {string} secretWord - Secret word.\n * @returns {number} - Number of letters matched between guessed word and secret word.\n */\nexport function getLetterMatchCount(guessedWord, secretWord) {\n    const secretLetters = secretWord.split('');\n    const guessedLetterSet = new Set(guessedWord);\n    return secretLetters.filter(letter => guessedLetterSet.has(letter)).length;\n};\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/jotto-redux-class-based/src/helpers/index.test.js",
    "content": "import { getLetterMatchCount } from './';\n\ndescribe('getLetterMatchCount', () => {\n  const secretWord = 'party';\n  test('returns correct count when there are no matching letters', () => {\n    const letterMatchCount = getLetterMatchCount('bones', secretWord);\n    expect(letterMatchCount).toBe(0);\n  });\n  test('returns the correct count where there are 3 matching letters', () => {\n    const letterMatchCount = getLetterMatchCount('train', secretWord);\n    expect(letterMatchCount).toBe(3);\n  });\n  test('returns correct count when there are duplicate letters in the guess', () => {\n    const letterMatchCount = getLetterMatchCount('parka', secretWord);\n    expect(letterMatchCount).toBe(3);\n  });\n});\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/jotto-redux-class-based/src/index.css",
    "content": "body {\n  margin: 0;\n  padding: 0;\n  font-family: sans-serif;\n}\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/jotto-redux-class-based/src/index.js",
    "content": "import React from 'react';\nimport ReactDOM from 'react-dom';\nimport { Provider } from 'react-redux';\n\nimport './index.css';\nimport App from './App';\nimport registerServiceWorker from './registerServiceWorker';\nimport store from './configureStore';\n\nReactDOM.render(\n  <Provider store={store}>\n    <App />\n  </Provider>, \n  document.getElementById('root'));\nregisterServiceWorker();\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/jotto-redux-class-based/src/integration.test.js",
    "content": "import { storeFactory } from '../test/testUtils';\nimport { guessWord } from './actions';\n\ndescribe('guessWord action dispatcher', () => {\n  const secretWord = 'party';\n  const unsuccessfulGuess = 'train';\n  describe('no guessed words', () => {\n    let store;\n    const initialState = { secretWord };\n    beforeEach(() => {\n      store = storeFactory(initialState);\n    });\n    test('updates state correctly for unsuccessful guess', () => {\n      store.dispatch(guessWord(unsuccessfulGuess));\n      const newState = store.getState()\n      const expectedState = {\n        ...initialState,\n        success: false,\n        guessedWords: [{\n          guessedWord: unsuccessfulGuess,\n          letterMatchCount: 3\n        }]\n      };\n      expect(newState).toEqual(expectedState);\n    });\n    test('updates state correctly for successful guess', () => {\n      store.dispatch(guessWord(secretWord));\n      const newState = store.getState()\n      const expectedState = {\n        secretWord,\n        success: true,\n        guessedWords: [{\n          guessedWord: secretWord,\n          letterMatchCount: 5,\n        }],\n      };\n      expect(newState).toEqual(expectedState);\n    });\n  });\n  describe('some guessed words', () => {\n    const guessedWords = [ { guessedWord: 'agile', letterMatchCount: 1 } ];\n    const initialState = { guessedWords, secretWord }\n    let store;\n    beforeEach(() => {\n      store = storeFactory(initialState);\n    })\n    test('updates state correctly for unsuccessful guess', () => {\n      store.dispatch(guessWord(unsuccessfulGuess));\n      const newState = store.getState();\n      const expectedState = {\n        secretWord,\n        success: false,\n        guessedWords: [...guessedWords, { guessedWord: unsuccessfulGuess, letterMatchCount: 3 }]\n      };\n      expect(newState).toEqual(expectedState);\n    });\n    test('updates state correctly for successful guess', () => {\n      store.dispatch(guessWord(secretWord));\n      const newState = store.getState();\n      const expectedState = {\n        secretWord,\n        success: true,\n        guessedWords: [...guessedWords,\n          { guessedWord: secretWord, letterMatchCount: 5 }]\n      };\n      expect(newState).toEqual(expectedState);\n    });\n  });\n});\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/jotto-redux-class-based/src/reducers/guessedWordsReducer.js",
    "content": "import { actionTypes } from '../actions';\n\n/**\n * @function guessedWordsReducer\n * @param {array} state - Array of guessed words.\n * @param {object} action - action to be reduced.\n * @returns {array} - new guessedWords state.\n */\n export default (state=[], action) => {\n  switch(action.type) {\n    case actionTypes.GUESS_WORD:\n      return [...state, action.payload];\n    default:\n      return state;\n  }\n}\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/jotto-redux-class-based/src/reducers/index.js",
    "content": "import { combineReducers } from 'redux';\nimport success from './successReducer';\nimport guessedWords from './guessedWordsReducer';\nimport secretWord from './secretWordReducer';\n\nexport default combineReducers({\n  success,\n  guessedWords,\n  secretWord,\n});\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/jotto-redux-class-based/src/reducers/secretWordReducer.js",
    "content": "import { actionTypes } from '../actions';\n\n/**\n * @function secretWordReducer\n * @param {string} state - State before reducer.\n * @param {object} action - Action sent to reducer.\n * @returns {string} - New state (secret word payload from action).\n */\nexport default (state=null, action) => {\n  switch (action.type) {\n    case actionTypes.SET_SECRET_WORD:\n      return action.payload;\n    default:\n      return state;\n  }\n}\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/jotto-redux-class-based/src/reducers/successReducer.js",
    "content": "import { actionTypes } from '../actions';\n\n/**\n * @function successReducer\n * @param {array} state - Array of guessed words.\n * @param {object} action - action to be reduced.\n * @returns {boolean} - new success state.\n */\nexport default (state=false, action) => {\n  switch(action.type) {\n    case (actionTypes.CORRECT_GUESS):\n      return true;\n    default:\n      return state;\n  }\n}\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/jotto-redux-class-based/src/reducers/successReducer.test.js",
    "content": "import { actionTypes } from '../actions';\nimport successReducer from './successReducer';\n\ntest('returns default initial state of `false` when no action is passed', () => {\n  const newState = successReducer(undefined, {});\n  expect(newState).toBe(false);\n});\ntest('returns state of true upon receiving an action of type `CORRECT_GUESS`', () => {\n  const newState = successReducer(undefined, { type: actionTypes.CORRECT_GUESS });\n  expect(newState).toBe(true);\n});\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/jotto-redux-class-based/src/registerServiceWorker.js",
    "content": "// In production, we register a service worker to serve assets from local cache.\n\n// This lets the app load faster on subsequent visits in production, and gives\n// it offline capabilities. However, it also means that developers (and users)\n// will only see deployed updates on the \"N+1\" visit to a page, since previously\n// cached resources are updated in the background.\n\n// To learn more about the benefits of this model, read https://goo.gl/KwvDNy.\n// This link also includes instructions on opting out of this behavior.\n\nconst isLocalhost = Boolean(\n  window.location.hostname === 'localhost' ||\n    // [::1] is the IPv6 localhost address.\n    window.location.hostname === '[::1]' ||\n    // 127.0.0.1/8 is considered localhost for IPv4.\n    window.location.hostname.match(\n      /^127(?:\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/\n    )\n);\n\nexport default function register() {\n  if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {\n    // The URL constructor is available in all browsers that support SW.\n    const publicUrl = new URL(process.env.PUBLIC_URL, window.location);\n    if (publicUrl.origin !== window.location.origin) {\n      // Our service worker won't work if PUBLIC_URL is on a different origin\n      // from what our page is served on. This might happen if a CDN is used to\n      // serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374\n      return;\n    }\n\n    window.addEventListener('load', () => {\n      const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;\n\n      if (isLocalhost) {\n        // This is running on localhost. Lets check if a service worker still exists or not.\n        checkValidServiceWorker(swUrl);\n\n        // Add some additional logging to localhost, pointing developers to the\n        // service worker/PWA documentation.\n        navigator.serviceWorker.ready.then(() => {\n          console.log(\n            'This web app is being served cache-first by a service ' +\n              'worker. To learn more, visit https://goo.gl/SC7cgQ'\n          );\n        });\n      } else {\n        // Is not local host. Just register service worker\n        registerValidSW(swUrl);\n      }\n    });\n  }\n}\n\nfunction registerValidSW(swUrl) {\n  navigator.serviceWorker\n    .register(swUrl)\n    .then(registration => {\n      registration.onupdatefound = () => {\n        const installingWorker = registration.installing;\n        installingWorker.onstatechange = () => {\n          if (installingWorker.state === 'installed') {\n            if (navigator.serviceWorker.controller) {\n              // At this point, the old content will have been purged and\n              // the fresh content will have been added to the cache.\n              // It's the perfect time to display a \"New content is\n              // available; please refresh.\" message in your web app.\n              console.log('New content is available; please refresh.');\n            } else {\n              // At this point, everything has been precached.\n              // It's the perfect time to display a\n              // \"Content is cached for offline use.\" message.\n              console.log('Content is cached for offline use.');\n            }\n          }\n        };\n      };\n    })\n    .catch(error => {\n      console.error('Error during service worker registration:', error);\n    });\n}\n\nfunction checkValidServiceWorker(swUrl) {\n  // Check if the service worker can be found. If it can't reload the page.\n  fetch(swUrl)\n    .then(response => {\n      // Ensure service worker exists, and that we really are getting a JS file.\n      if (\n        response.status === 404 ||\n        response.headers.get('content-type').indexOf('javascript') === -1\n      ) {\n        // No service worker found. Probably a different app. Reload the page.\n        navigator.serviceWorker.ready.then(registration => {\n          registration.unregister().then(() => {\n            window.location.reload();\n          });\n        });\n      } else {\n        // Service worker found. Proceed as normal.\n        registerValidSW(swUrl);\n      }\n    })\n    .catch(() => {\n      console.log(\n        'No internet connection found. App is running in offline mode.'\n      );\n    });\n}\n\nexport function unregister() {\n  if ('serviceWorker' in navigator) {\n    navigator.serviceWorker.ready.then(registration => {\n      registration.unregister();\n    });\n  }\n}\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/jotto-redux-class-based/src/setupTests.js",
    "content": "import Enzyme, { shallow } from 'enzyme';\nimport EnzymeAdapter from 'enzyme-adapter-react-16';\n\nEnzyme.configure({\n  adapter: new EnzymeAdapter(),\n  disableLifecycleMethods: true,\n});\n"
  },
  {
    "path": "LEGACY-class-based-redux-components/jotto-redux-class-based/test/testUtils.js",
    "content": "import checkPropTypes from 'check-prop-types';\nimport { createStore, applyMiddleware } from 'redux';\n\nimport rootReducer from '../src/reducers';\nimport { middlewares } from '../src/configureStore';\n\n/**\n * Create a testing store with imported reducers, middleware, and initial state.\n *  globals: rootReducer, middlewares.\n * @param {object} initialState - Initial state for store.\n * @function storeFactory\n * @returns {Store} - Redux store.\n */\nexport const storeFactory = (initialState) => {\n  const createStoreWithMiddleware = applyMiddleware(...middlewares)(createStore)\n  return createStoreWithMiddleware(rootReducer, initialState);\n}\n\n/**\n * Return node(s) with the given data-test attribute.\n * @param {ShallowWrapper} wrapper - Enzyme shallow wrapper.\n * @param {string} val - Value of data-test attribute for search.\n * @returns {ShallowWrapper}\n */\nexport const findByTestAttr = (wrapper, val) => {\n  return wrapper.find(`[data-test=\"${val}\"]`);\n}\n\nexport const checkProps = (component, conformingProps) => {\n  const propError = checkPropTypes(\n    component.propTypes,\n    conformingProps,\n    'prop',\n    component.name);\n  expect(propError).toBeUndefined();\n}\n"
  },
  {
    "path": "README.md",
    "content": "# udemy-ENZYME\n\nCode for projects presented in Udemy [React Testing with Jest and Enzyme](https://www.udemy.com/course/react-testing-with-jest-and-enzyme/?couponCode=ENZYME-GITHUB) course\n"
  },
  {
    "path": "SOLUTIONS for Click Counter Challenges/.gitignore",
    "content": "# See https://help.github.com/ignore-files/ for more about ignoring files.\n\n# dependencies\n/node_modules\n\n# testing\n/coverage\n\n# production\n/build\n\n# misc\n.DS_Store\n.env.local\n.env.development.local\n.env.test.local\n.env.production.local\n\nnpm-debug.log*\nyarn-debug.log*\nyarn-error.log*\n"
  },
  {
    "path": "SOLUTIONS for Click Counter Challenges/.npmrc",
    "content": "fund=false\naudit=false\nloglevel=error\n"
  },
  {
    "path": "SOLUTIONS for Click Counter Challenges/README.md",
    "content": "This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).\n\n## Available Scripts\n\nIn the project directory, you can run:\n\n### `npm start`\n\nRuns the app in the development mode.<br />\nOpen [http://localhost:3000](http://localhost:3000) to view it in the browser.\n\nThe page will reload if you make edits.<br />\nYou will also see any lint errors in the console.\n\n### `npm test`\n\nLaunches the test runner in the interactive watch mode.<br />\nSee the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.\n\n### `npm run build`\n\nBuilds the app for production to the `build` folder.<br />\nIt correctly bundles React in production mode and optimizes the build for the best performance.\n\nThe build is minified and the filenames include the hashes.<br />\nYour app is ready to be deployed!\n\nSee the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.\n\n### `npm run eject`\n\n**Note: this is a one-way operation. Once you `eject`, you can’t go back!**\n\nIf you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.\n\nInstead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.\n\nYou don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.\n\n## Learn More\n\nYou can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).\n\nTo learn React, check out the [React documentation](https://reactjs.org/).\n\n### Code Splitting\n\nThis section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting\n\n### Analyzing the Bundle Size\n\nThis section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size\n\n### Making a Progressive Web App\n\nThis section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app\n\n### Advanced Configuration\n\nThis section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration\n\n### Deployment\n\nThis section has moved here: https://facebook.github.io/create-react-app/docs/deployment\n\n### `npm run build` fails to minify\n\nThis section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify\n"
  },
  {
    "path": "SOLUTIONS for Click Counter Challenges/package.json",
    "content": "{\n  \"name\": \"click-counter-functional\",\n  \"version\": \"0.1.0\",\n  \"private\": true,\n  \"dependencies\": {\n    \"@testing-library/jest-dom\": \"^4.2.4\",\n    \"@testing-library/react\": \"^9.5.0\",\n    \"@testing-library/user-event\": \"^7.2.1\",\n    \"enzyme\": \"^3.11.0\",\n    \"enzyme-adapter-react-16\": \"^1.15.2\",\n    \"jest-enzyme\": \"^7.1.2\",\n    \"react\": \"^16.13.1\",\n    \"react-dom\": \"^16.13.1\",\n    \"react-scripts\": \"3.4.1\"\n  },\n  \"scripts\": {\n    \"start\": \"react-scripts start\",\n    \"build\": \"react-scripts build\",\n    \"test\": \"react-scripts test\",\n    \"eject\": \"react-scripts eject\"\n  },\n  \"eslintConfig\": {\n    \"extends\": \"react-app\"\n  },\n  \"browserslist\": {\n    \"production\": [\n      \">0.2%\",\n      \"not dead\",\n      \"not op_mini all\"\n    ],\n    \"development\": [\n      \"last 1 chrome version\",\n      \"last 1 firefox version\",\n      \"last 1 safari version\"\n    ]\n  }\n}\n"
  },
  {
    "path": "SOLUTIONS for Click Counter Challenges/public/index.html",
    "content": "<!DOCTYPE html>\n<html lang=\"en\">\n  <head>\n    <meta charset=\"utf-8\" />\n    <link rel=\"icon\" href=\"%PUBLIC_URL%/favicon.ico\" />\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n    <meta name=\"theme-color\" content=\"#000000\" />\n    <meta\n      name=\"description\"\n      content=\"Web site created using create-react-app\"\n    />\n    <link rel=\"apple-touch-icon\" href=\"%PUBLIC_URL%/logo192.png\" />\n    <!--\n      manifest.json provides metadata used when your web app is installed on a\n      user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/\n    -->\n    <link rel=\"manifest\" href=\"%PUBLIC_URL%/manifest.json\" />\n    <!--\n      Notice the use of %PUBLIC_URL% in the tags above.\n      It will be replaced with the URL of the `public` folder during the build.\n      Only files inside the `public` folder can be referenced from the HTML.\n\n      Unlike \"/favicon.ico\" or \"favicon.ico\", \"%PUBLIC_URL%/favicon.ico\" will\n      work correctly both with client-side routing and a non-root public URL.\n      Learn how to configure a non-root public URL by running `npm run build`.\n    -->\n    <title>React App</title>\n  </head>\n  <body>\n    <noscript>You need to enable JavaScript to run this app.</noscript>\n    <div id=\"root\"></div>\n    <!--\n      This HTML file is a template.\n      If you open it directly in the browser, you will see an empty page.\n\n      You can add webfonts, meta tags, or analytics to this file.\n      The build step will place the bundled scripts into the <body> tag.\n\n      To begin the development, run `npm start` or `yarn start`.\n      To create a production bundle, use `npm run build` or `yarn build`.\n    -->\n  </body>\n</html>\n"
  },
  {
    "path": "SOLUTIONS for Click Counter Challenges/public/manifest.json",
    "content": "{\n  \"short_name\": \"React App\",\n  \"name\": \"Create React App Sample\",\n  \"icons\": [\n    {\n      \"src\": \"favicon.ico\",\n      \"sizes\": \"64x64 32x32 24x24 16x16\",\n      \"type\": \"image/x-icon\"\n    },\n    {\n      \"src\": \"logo192.png\",\n      \"type\": \"image/png\",\n      \"sizes\": \"192x192\"\n    },\n    {\n      \"src\": \"logo512.png\",\n      \"type\": \"image/png\",\n      \"sizes\": \"512x512\"\n    }\n  ],\n  \"start_url\": \".\",\n  \"display\": \"standalone\",\n  \"theme_color\": \"#000000\",\n  \"background_color\": \"#ffffff\"\n}\n"
  },
  {
    "path": "SOLUTIONS for Click Counter Challenges/public/robots.txt",
    "content": "# https://www.robotstxt.org/robotstxt.html\nUser-agent: *\nDisallow:\n"
  },
  {
    "path": "SOLUTIONS for Click Counter Challenges/src/App.css",
    "content": ".App {\n  text-align: center;\n}\n\n.App-logo {\n  height: 40vmin;\n  pointer-events: none;\n}\n\n@media (prefers-reduced-motion: no-preference) {\n  .App-logo {\n    animation: App-logo-spin infinite 20s linear;\n  }\n}\n\n.App-header {\n  background-color: #282c34;\n  min-height: 100vh;\n  display: flex;\n  flex-direction: column;\n  align-items: center;\n  justify-content: center;\n  font-size: calc(10px + 2vmin);\n  color: white;\n}\n\n.App-link {\n  color: #61dafb;\n}\n\n@keyframes App-logo-spin {\n  from {\n    transform: rotate(0deg);\n  }\n  to {\n    transform: rotate(360deg);\n  }\n}\n\n/* error styling for challenge #2 */\n.error {\n  font-size: 150%;\n  color: red;\n}\n\n/* for challenge #2 and #3 to show / hide error message */\n.hidden {\n  display: none;\n}"
  },
  {
    "path": "SOLUTIONS for Click Counter Challenges/src/App.js",
    "content": "import React from 'react';\nimport logo from './logo.svg';\nimport './App.css';\n\nfunction App() {\n  const [count, setCount] = React.useState(0);\n  const [error, setError] = React.useState(false);\n\n  return (\n    <div data-test=\"component-app\" className=\"App\">\n      <h1 data-test=\"counter-display\">\n        The counter is currently&nbsp;\n        <span data-test=\"count\">{count}</span>\n      </h1>\n      {/* Notes: \n      - using ternary on the error state to determine whether or not to hide \n      - the 'error' and 'hidden' classes are defined in App.css\n      */}\n      <div data-test=\"error-message\" className={`error ${error ? '' : 'hidden'}`}>\n        The counter cannot go below 0\n      </div>\n      <button\n        data-test=\"increment-button\"\n        onClick={() => {\n          if (error) { setError(false); }\n          setCount(count + 1)\n        }\n      }\n      >\n        Increment counter\n      </button>\n      <button\n        data-test=\"decrement-button\"\n        onClick={() => {\n          if (count > 0) {\n            setCount(count - 1)\n          } else {\n            setError(true);\n          }\n        }\n      }\n      >\n        Decrement counter\n      </button>\n    </div>\n  );\n}\n\nexport default App;\n"
  },
  {
    "path": "SOLUTIONS for Click Counter Challenges/src/App.test.js",
    "content": "import React from \"react\";\nimport Enzyme, { shallow } from \"enzyme\";\nimport EnzymeAdapter from \"enzyme-adapter-react-16\";\nimport App from \"./App\";\n\nEnzyme.configure({ adapter: new EnzymeAdapter() });\n\n/**\n * Factory function to create a ShallowWrapper for the App component.\n * @function setup\n * @param {object} props - Component props specific to this setup.\n * @returns {ShallowWrapper}\n */\nconst setup = (props = {}) => {\n  return shallow(<App {...props} />);\n};\n\n/**\n * Return ShallowWrapper containing node(s) with the given data-test value.\n * @param {ShallowWrapper} wrapper - Enzyme shallow wrapper to search within.\n * @param {string} val - Value of data-test c1scoL0ve!\n *\n */\nconst findByTestAttr = (wrapper, val) => {\n  return wrapper.find(`[data-test=\"${val}\"]`);\n};\n\ntest(\"renders without error\", () => {\n  const wrapper = setup();\n  const appComponent = findByTestAttr(wrapper, \"component-app\");\n  expect(appComponent.length).toBe(1);\n});\n\ntest(\"renders counter display\", () => {\n  const wrapper = setup();\n  const counterDisplay = findByTestAttr(wrapper, \"counter-display\");\n  expect(counterDisplay.length).toBe(1);\n});\n\ntest(\"counter starts at 0\", () => {\n  const wrapper = setup();\n  const count = findByTestAttr(wrapper, \"count\").text();\n  expect(count).toBe(\"0\"); // do this first with an integer and show failure!\n});\n\ndescribe(\"Increment\", () => {\n  // now we have enough tests to organize by function\n  test(\"renders increment button\", () => {\n    const wrapper = setup();\n    const button = findByTestAttr(wrapper, \"increment-button\");\n    expect(button.length).toBe(1);\n  });\n\n  test(\"counter increments when button is clicked\", () => {\n    const wrapper = setup();\n\n    // find button and click\n    const button = findByTestAttr(wrapper, \"increment-button\");\n    button.simulate(\"click\");\n\n    // check the counter\n    const count = findByTestAttr(wrapper, \"count\").text();\n    expect(count).toBe(\"1\");\n  });\n});\n\ndescribe(\"decrement button\", () => {\n  test(\"renders decrement button\", () => {\n    const wrapper = setup();\n    const button = findByTestAttr(wrapper, \"decrement-button\");\n    expect(button.length).toBe(1);\n  });\n\n  test(\"clicking decrement button decrements counter display when state is greater than 0\", () => {\n    const wrapper = setup();\n\n    // click the increment button so that the counter is greater than 0\n    const incButton = findByTestAttr(wrapper, \"increment-button\");\n    incButton.simulate(\"click\");\n\n    // find decrement button and click\n    const decButton = findByTestAttr(wrapper, \"decrement-button\");\n    decButton.simulate(\"click\");\n\n    // find display and test value\n    const count = findByTestAttr(wrapper, \"count\").text();\n    expect(count).toBe(\"0\");\n  });\n});\ndescribe(\"error when counter goes below 0\", () => {\n  test(\"error does not show when not needed\", () => {\n    // I plan to implement this by using a \"hidden\" class for the error div\n    // I plan to use the data-test value 'error-message' for the error div\n    const wrapper = setup();\n    const errorDiv = findByTestAttr(wrapper, \"error-message\");\n\n    // using enzyme's \".hasClass()\" method\n    // http://airbnb.io/enzyme/docs/api/ShallowWrapper/hasClass.html\n    const errorHasHiddenClass = errorDiv.hasClass(\"hidden\");\n    expect(errorHasHiddenClass).toBe(true);\n  });\n\n  describe(\"counter is 0 and decrement is clicked\", () => {\n    // using a describe here so I can use a \"beforeEach\" for shared setup\n\n    // scoping wrapper to the describe, so it can be used in beforeEach and the tests\n    let wrapper;\n    beforeEach(() => {\n      // no need to set counter value here; default value of 0 is good\n      wrapper = setup();\n\n      // find button and click\n      const button = findByTestAttr(wrapper, \"decrement-button\");\n      button.simulate(\"click\");\n    });\n    test(\"error shows\", () => {\n      // check the class of the error message\n      const errorDiv = findByTestAttr(wrapper, \"error-message\");\n      const errorHasHiddenClass = errorDiv.hasClass(\"hidden\");\n      expect(errorHasHiddenClass).toBe(false);\n    });\n    test(\"counter still displays 0\", () => {\n      const count = findByTestAttr(wrapper, \"count\").text();\n      expect(count).toBe(\"0\");\n    });\n    test(\"clicking increment clears the error\", () => {\n      // find and click the increment button\n      const incButton = findByTestAttr(wrapper, \"increment-button\");\n      incButton.simulate(\"click\");\n\n      // check the class of the error message\n      const errorDiv = findByTestAttr(wrapper, \"error-message\");\n      const errorHasHiddenClass = errorDiv.hasClass(\"hidden\");\n      expect(errorHasHiddenClass).toBe(true);\n    });\n  });\n});\n"
  },
  {
    "path": "SOLUTIONS for Click Counter Challenges/src/index.css",
    "content": "body {\n  margin: 0;\n  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',\n    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',\n    sans-serif;\n  -webkit-font-smoothing: antialiased;\n  -moz-osx-font-smoothing: grayscale;\n}\n\ncode {\n  font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',\n    monospace;\n}\n"
  },
  {
    "path": "SOLUTIONS for Click Counter Challenges/src/index.js",
    "content": "import React from 'react';\nimport ReactDOM from 'react-dom';\nimport './index.css';\nimport App from './App';\nimport * as serviceWorker from './serviceWorker';\n\nReactDOM.render(\n  <React.StrictMode>\n    <App />\n  </React.StrictMode>,\n  document.getElementById('root')\n);\n\n// If you want your app to work offline and load faster, you can change\n// unregister() to register() below. Note this comes with some pitfalls.\n// Learn more about service workers: https://bit.ly/CRA-PWA\nserviceWorker.unregister();\n"
  },
  {
    "path": "SOLUTIONS for Click Counter Challenges/src/registerServiceWorker.js",
    "content": "// In production, we register a service worker to serve assets from local cache.\n\n// This lets the app load faster on subsequent visits in production, and gives\n// it offline capabilities. However, it also means that developers (and users)\n// will only see deployed updates on the \"N+1\" visit to a page, since previously\n// cached resources are updated in the background.\n\n// To learn more about the benefits of this model, read https://goo.gl/KwvDNy.\n// This link also includes instructions on opting out of this behavior.\n\nconst isLocalhost = Boolean(\n  window.location.hostname === 'localhost' ||\n    // [::1] is the IPv6 localhost address.\n    window.location.hostname === '[::1]' ||\n    // 127.0.0.1/8 is considered localhost for IPv4.\n    window.location.hostname.match(\n      /^127(?:\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/\n    )\n);\n\nexport default function register() {\n  if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {\n    // The URL constructor is available in all browsers that support SW.\n    const publicUrl = new URL(process.env.PUBLIC_URL, window.location);\n    if (publicUrl.origin !== window.location.origin) {\n      // Our service worker won't work if PUBLIC_URL is on a different origin\n      // from what our page is served on. This might happen if a CDN is used to\n      // serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374\n      return;\n    }\n\n    window.addEventListener('load', () => {\n      const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;\n\n      if (isLocalhost) {\n        // This is running on localhost. Lets check if a service worker still exists or not.\n        checkValidServiceWorker(swUrl);\n\n        // Add some additional logging to localhost, pointing developers to the\n        // service worker/PWA documentation.\n        navigator.serviceWorker.ready.then(() => {\n          console.log(\n            'This web app is being served cache-first by a service ' +\n              'worker. To learn more, visit https://goo.gl/SC7cgQ'\n          );\n        });\n      } else {\n        // Is not local host. Just register service worker\n        registerValidSW(swUrl);\n      }\n    });\n  }\n}\n\nfunction registerValidSW(swUrl) {\n  navigator.serviceWorker\n    .register(swUrl)\n    .then(registration => {\n      registration.onupdatefound = () => {\n        const installingWorker = registration.installing;\n        installingWorker.onstatechange = () => {\n          if (installingWorker.state === 'installed') {\n            if (navigator.serviceWorker.controller) {\n              // At this point, the old content will have been purged and\n              // the fresh content will have been added to the cache.\n              // It's the perfect time to display a \"New content is\n              // available; please refresh.\" message in your web app.\n              console.log('New content is available; please refresh.');\n            } else {\n              // At this point, everything has been precached.\n              // It's the perfect time to display a\n              // \"Content is cached for offline use.\" message.\n              console.log('Content is cached for offline use.');\n            }\n          }\n        };\n      };\n    })\n    .catch(error => {\n      console.error('Error during service worker registration:', error);\n    });\n}\n\nfunction checkValidServiceWorker(swUrl) {\n  // Check if the service worker can be found. If it can't reload the page.\n  fetch(swUrl)\n    .then(response => {\n      // Ensure service worker exists, and that we really are getting a JS file.\n      if (\n        response.status === 404 ||\n        response.headers.get('content-type').indexOf('javascript') === -1\n      ) {\n        // No service worker found. Probably a different app. Reload the page.\n        navigator.serviceWorker.ready.then(registration => {\n          registration.unregister().then(() => {\n            window.location.reload();\n          });\n        });\n      } else {\n        // Service worker found. Proceed as normal.\n        registerValidSW(swUrl);\n      }\n    })\n    .catch(() => {\n      console.log(\n        'No internet connection found. App is running in offline mode.'\n      );\n    });\n}\n\nexport function unregister() {\n  if ('serviceWorker' in navigator) {\n    navigator.serviceWorker.ready.then(registration => {\n      registration.unregister();\n    });\n  }\n}\n"
  },
  {
    "path": "SOLUTIONS for Click Counter Challenges/src/serviceWorker.js",
    "content": "// This optional code is used to register a service worker.\n// register() is not called by default.\n\n// This lets the app load faster on subsequent visits in production, and gives\n// it offline capabilities. However, it also means that developers (and users)\n// will only see deployed updates on subsequent visits to a page, after all the\n// existing tabs open on the page have been closed, since previously cached\n// resources are updated in the background.\n\n// To learn more about the benefits of this model and instructions on how to\n// opt-in, read https://bit.ly/CRA-PWA\n\nconst isLocalhost = Boolean(\n  window.location.hostname === 'localhost' ||\n    // [::1] is the IPv6 localhost address.\n    window.location.hostname === '[::1]' ||\n    // 127.0.0.0/8 are considered localhost for IPv4.\n    window.location.hostname.match(\n      /^127(?:\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/\n    )\n);\n\nexport function register(config) {\n  if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {\n    // The URL constructor is available in all browsers that support SW.\n    const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);\n    if (publicUrl.origin !== window.location.origin) {\n      // Our service worker won't work if PUBLIC_URL is on a different origin\n      // from what our page is served on. This might happen if a CDN is used to\n      // serve assets; see https://github.com/facebook/create-react-app/issues/2374\n      return;\n    }\n\n    window.addEventListener('load', () => {\n      const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;\n\n      if (isLocalhost) {\n        // This is running on localhost. Let's check if a service worker still exists or not.\n        checkValidServiceWorker(swUrl, config);\n\n        // Add some additional logging to localhost, pointing developers to the\n        // service worker/PWA documentation.\n        navigator.serviceWorker.ready.then(() => {\n          console.log(\n            'This web app is being served cache-first by a service ' +\n              'worker. To learn more, visit https://bit.ly/CRA-PWA'\n          );\n        });\n      } else {\n        // Is not localhost. Just register service worker\n        registerValidSW(swUrl, config);\n      }\n    });\n  }\n}\n\nfunction registerValidSW(swUrl, config) {\n  navigator.serviceWorker\n    .register(swUrl)\n    .then(registration => {\n      registration.onupdatefound = () => {\n        const installingWorker = registration.installing;\n        if (installingWorker == null) {\n          return;\n        }\n        installingWorker.onstatechange = () => {\n          if (installingWorker.state === 'installed') {\n            if (navigator.serviceWorker.controller) {\n              // At this point, the updated precached content has been fetched,\n              // but the previous service worker will still serve the older\n              // content until all client tabs are closed.\n              console.log(\n                'New content is available and will be used when all ' +\n                  'tabs for this page are closed. See https://bit.ly/CRA-PWA.'\n              );\n\n              // Execute callback\n              if (config && config.onUpdate) {\n                config.onUpdate(registration);\n              }\n            } else {\n              // At this point, everything has been precached.\n              // It's the perfect time to display a\n              // \"Content is cached for offline use.\" message.\n              console.log('Content is cached for offline use.');\n\n              // Execute callback\n              if (config && config.onSuccess) {\n                config.onSuccess(registration);\n              }\n            }\n          }\n        };\n      };\n    })\n    .catch(error => {\n      console.error('Error during service worker registration:', error);\n    });\n}\n\nfunction checkValidServiceWorker(swUrl, config) {\n  // Check if the service worker can be found. If it can't reload the page.\n  fetch(swUrl, {\n    headers: { 'Service-Worker': 'script' },\n  })\n    .then(response => {\n      // Ensure service worker exists, and that we really are getting a JS file.\n      const contentType = response.headers.get('content-type');\n      if (\n        response.status === 404 ||\n        (contentType != null && contentType.indexOf('javascript') === -1)\n      ) {\n        // No service worker found. Probably a different app. Reload the page.\n        navigator.serviceWorker.ready.then(registration => {\n          registration.unregister().then(() => {\n            window.location.reload();\n          });\n        });\n      } else {\n        // Service worker found. Proceed as normal.\n        registerValidSW(swUrl, config);\n      }\n    })\n    .catch(() => {\n      console.log(\n        'No internet connection found. App is running in offline mode.'\n      );\n    });\n}\n\nexport function unregister() {\n  if ('serviceWorker' in navigator) {\n    navigator.serviceWorker.ready\n      .then(registration => {\n        registration.unregister();\n      })\n      .catch(error => {\n        console.error(error.message);\n      });\n  }\n}\n"
  },
  {
    "path": "SOLUTIONS for Click Counter Challenges/src/setupTests.js",
    "content": "// jest-dom adds custom jest matchers for asserting on DOM nodes.\n// allows you to do things like:\n// expect(element).toHaveTextContent(/react/i)\n// learn more: https://github.com/testing-library/jest-dom\nimport '@testing-library/jest-dom/extend-expect';\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/.npmrc",
    "content": "fund=false\naudit=false\nloglevel=error\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/README.md",
    "content": "# Jotto\n### A React app with hooks and contexts used to demonstrate testing\n\n## Branches\n\n*  `master`\n\n  This branch represents the project at the end of the instructional videos, without any of the challenges completed.\n\n* `jotto-hooks-challenges`\n\n  [This branch](https://github.com/flyrightsister/udemy-react-testing-projects/tree/jotto-challenges/jotto) contains solutions to the challenges.\n\n## Challenges\n\n### 1. Number of Guesses\n  ![Number of Guesses Wireframe](https://github.com/flyrightsister/udemy-react-testing-projects/blob/master/jotto-redux/readme-images/number-of-guesses_wireframe.png)\n\n  * _Note_: Try to accomplish this _without_ adding a new piece of state!\n  * Add “guess number” column to the \"guessed words\" table\n    * The first guess should show 1, second guess 2, etc.\n  * Add a component that displays total guesses as shown in wireframe\n\n### 2. Reset Game\n  ![Reset Game Wireframe](https://github.com/flyrightsister/udemy-react-testing-projects/blob/master/jotto-redux/readme-images/new-game_wireframe.png)\n  * Create a “New word” button component\n    * only display after successful guess\n  * Upon click, reset the game with a new word from the server\n  * _Notes_: This one is going to need access to `setGuessedWords` and `setSuccess` to reset those pieces of state upon click. It can import `getSecretWord` from `actions/hookActions`, but it will need `setSecretWord` from `App.js` to pass as a callback to `getSecretWord`. I recommend passing `setSecretWord` as a prop.\n\n  To test which components show up\n  after clicking the New Word Button, try running `mount` on `App` after you've mocked\n  `hookActions.getSecretWord` to run the callback function\n  argument with the secretWord value (to avoid making a\n  network call when `App` mounts). For example: \n  \n  ```\n  hookActions.getSecretWord = jest.fn(setSecretWord => setSecretWord('party'));\n  ```\n\n  Then you can find and click the new word button and test to see the state of various components. You might make a new integration test file for this, or you could keep these tests within NewWordButton.test.js -- your choice.\n\n### 3. “Give up” Button\n  ![Give Up Button Wireframe](https://github.com/flyrightsister/udemy-react-testing-projects/blob/master/jotto-redux/readme-images/give-up-button_wireframe.png)\n  ![After Give Up Click Wireframe](https://github.com/flyrightsister/udemy-react-testing-projects/blob/master/jotto-redux/readme-images/after-give-up_wireframe.png)  \n  \n  * Create a “Give up” button\n    * only display when word has not been guessed correctly\n  * Upon click:\n    * Show secret word\n    * Display \"better luck next time\" message\n    * Display “new word” button component\n    * Set `success` context to `true` (the other components should display as though `success` is true; that is, no Input and show New Word button. The exception is Congrats of course!)\n  * _Note_: This one is quite involved! One way to approach it: Update\n    the `App` component to have `givenUp` as part of its state,\n    and then display components depending on the values of\n    `givenUp` and `success`. \n    You will also need to\n    update the `NewWordButton` onClick to reset `givenUp`.\n\n    You can use the same method to check on components after click as you did with Challenge #2. \n\n### 4. User inputs secret word\n  ![Enter Secret Word Button Wireframe](https://github.com/flyrightsister/udemy-react-testing-projects/blob/master/jotto-redux/readme-images/enter-secret-word_wireframe.png)  \n  ![Secret Word Entry Form Wireframe](https://github.com/flyrightsister/udemy-react-testing-projects/blob/master/jotto-redux/readme-images/secret-word-entry-form_wireframe.png)  \n\n  * Add a button for the user to input the secret word\n    * This way, the user can play against a friend\n  * After submission, the game should use the user’s secret word, not a word from the server\n  * This button should disapppear once the user has nonzero `guessedWords`\n\n  * _Note: The entry form is another chance to practice with a state-controlled field._\n\n### 5. Random Word Server Error\n  ![Random Word Server Error Wireframe](https://github.com/flyrightsister/udemy-react-testing-projects/blob/master/jotto-redux/readme-images/random-word-server-error_wireframe.png) \n\n  * Display an error if:\n    * There’s a problem contacting the “random word” server\n    * The server responds with status 4xx or 5xx\n \n## Credits\nThis project was bootstrapped with [Create React App](https://github.com/facebookincubator/create-react-app).\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/package.json",
    "content": "{\n  \"name\": \"jotto-hooks\",\n  \"version\": \"0.1.0\",\n  \"private\": true,\n  \"dependencies\": {\n    \"axios\": \"^0.19.0\",\n    \"prop-types\": \"^15.7.2\",\n    \"react\": \"^16.9.0\",\n    \"react-dom\": \"^16.9.0\",\n    \"react-scripts\": \"3.1.1\"\n  },\n  \"scripts\": {\n    \"start\": \"react-scripts start\",\n    \"build\": \"react-scripts build\",\n    \"test\": \"react-scripts test\",\n    \"eject\": \"react-scripts eject\"\n  },\n  \"eslintConfig\": {\n    \"extends\": \"react-app\"\n  },\n  \"browserslist\": {\n    \"production\": [\n      \">0.2%\",\n      \"not dead\",\n      \"not op_mini all\"\n    ],\n    \"development\": [\n      \"last 1 chrome version\",\n      \"last 1 firefox version\",\n      \"last 1 safari version\"\n    ]\n  },\n  \"devDependencies\": {\n    \"check-prop-types\": \"^1.1.2\",\n    \"enzyme\": \"^3.10.0\",\n    \"enzyme-adapter-react-16\": \"^1.14.0\",\n    \"jest-enzyme\": \"^7.1.0\",\n    \"moxios\": \"^0.4.0\"\n  }\n}\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/public/index.html",
    "content": "<!DOCTYPE html>\n<html lang=\"en\">\n  <head>\n    <meta charset=\"utf-8\" />\n    <link rel=\"shortcut icon\" href=\"%PUBLIC_URL%/favicon.ico\" />\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n    <meta name=\"theme-color\" content=\"#000000\" />\n    <meta\n      name=\"description\"\n      content=\"Web site created using create-react-app\"\n    />\n    <link rel=\"apple-touch-icon\" href=\"logo192.png\" />\n    <!--\n      manifest.json provides metadata used when your web app is installed on a\n      user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/\n    -->\n    <link rel=\"manifest\" href=\"%PUBLIC_URL%/manifest.json\" />\n    <!--\n      Notice the use of %PUBLIC_URL% in the tags above.\n      It will be replaced with the URL of the `public` folder during the build.\n      Only files inside the `public` folder can be referenced from the HTML.\n\n      Unlike \"/favicon.ico\" or \"favicon.ico\", \"%PUBLIC_URL%/favicon.ico\" will\n      work correctly both with client-side routing and a non-root public URL.\n      Learn how to configure a non-root public URL by running `npm run build`.\n    -->\n    <link href=\"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css\" rel=\"stylesheet\" integrity=\"sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T\" crossorigin=\"anonymous\">\n    <script src=\"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js\" integrity=\"sha384-xrRywqdh3PHs8keKZN+8zzc5TX0GRTLCcmivcbNJWm2rs5C8PRhcEn3czEjhAO9o\" crossorigin=\"anonymous\"></script>\n    <title>React App</title>\n  </head>\n  <body>\n    <noscript>You need to enable JavaScript to run this app.</noscript>\n    <div id=\"root\"></div>\n    <!--\n      This HTML file is a template.\n      If you open it directly in the browser, you will see an empty page.\n\n      You can add webfonts, meta tags, or analytics to this file.\n      The build step will place the bundled scripts into the <body> tag.\n\n      To begin the development, run `npm start` or `yarn start`.\n      To create a production bundle, use `npm run build` or `yarn build`.\n    -->\n  </body>\n</html>\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/public/manifest.json",
    "content": "{\n  \"short_name\": \"React App\",\n  \"name\": \"Create React App Sample\",\n  \"icons\": [\n    {\n      \"src\": \"favicon.ico\",\n      \"sizes\": \"64x64 32x32 24x24 16x16\",\n      \"type\": \"image/x-icon\"\n    },\n    {\n      \"src\": \"logo192.png\",\n      \"type\": \"image/png\",\n      \"sizes\": \"192x192\"\n    },\n    {\n      \"src\": \"logo512.png\",\n      \"type\": \"image/png\",\n      \"sizes\": \"512x512\"\n    }\t    \n  ],\n  \"start_url\": \".\",\n  \"display\": \"standalone\",\n  \"theme_color\": \"#000000\",\n  \"background_color\": \"#ffffff\"\n}\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/public/robots.txt",
    "content": "# https://www.robotstxt.org/robotstxt.html\nUser-agent: *\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/App.css",
    "content": ".App {\n  text-align: center;\n}\n\n.App-logo {\n  animation: App-logo-spin infinite 20s linear;\n  height: 40vmin;\n  pointer-events: none;\n}\n\n.App-header {\n  background-color: #282c34;\n  min-height: 100vh;\n  display: flex;\n  flex-direction: column;\n  align-items: center;\n  justify-content: center;\n  font-size: calc(10px + 2vmin);\n  color: white;\n}\n\n.App-link {\n  color: #61dafb;\n}\n\n@keyframes App-logo-spin {\n  from {\n    transform: rotate(0deg);\n  }\n  to {\n    transform: rotate(360deg);\n  }\n}\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/App.js",
    "content": "import React from 'react';\nimport './App.css';\nimport hookActions from './actions/hookActions';\nimport languageContext from './contexts/languageContext';\nimport successContext from './contexts/successContext';\nimport guessedWordsContext from './contexts/guessedWordsContext';\n\nimport LanguagePicker from './LanguagePicker';\nimport Input from './Input';\nimport Congrats from './Congrats';\nimport GuessedWords from './GuessedWords';\nimport NewWordButton from './NewWordButton';\nimport SecretWordReveal from './SecretWordReveal';\nimport GiveUpButton from './GiveUpButton';\nimport EnterSecretWordButton from './EnterSecretWordButton';\nimport SecretWordEntry from './SecretWordEntry';\n\n/**\n * Reducer to update state, called automatically by dispatch\n * @param state {object} - existing state\n * @param action {object} - contains 'type' and 'payload' properties for the state update\n *                   for example: { type: \"setSecretWord\", payload: \"party\" }\n * @return {object} - new state\n */\nfunction reducer(state, action) {\n  switch(action.type) {\n    case \"setSecretWord\":\n      return { ...state, secretWord: action.payload };\n    case \"setLanguage\":\n      return { ...state, language: action.payload };\n    // Challenge #3: Give Up\n    case \"setGivenUp\":\n      return { ...state, givenUp: action.payload }\n    // END: Challenge #3: Give Up\n    // Challenge #4: Enter Secret Word\n    case \"setEnterSecretWord\":\n      return { ...state, enterSecretWord: action.payload }\n    // END: Challenge #4: Enter Secret Word\n    // Challenge #5: Server Error\n    case \"setServerError\":\n      return { ...state, serverError: action.payload }\n    // END: Challenge #5: Server Error\n    default:\n      throw new Error(`Invalid action type: ${action.type}`);\n  }\n\n}\n\nfunction App() {\n  \n  const [state, dispatch] = React.useReducer(\n    reducer,\n    { secretWord: null, language: 'en' }\n  )\n\n  const setSecretWord = (secretWord) =>\n    dispatch({ type: \"setSecretWord\", payload: secretWord });\n  const setLanguage = (language) =>\n    dispatch({ type: \"setLanguage\", payload: language });\n  // Challenge #3: Give Up\n  const setGivenUp = (givenUp) => \n    dispatch({ type: \"setGivenUp\", payload: givenUp })\n  // END: Challenge #3: Give Up\n\n  // Challenge #4: Enter Secret Word\n  const setEnterSecretWord = (enterSecretWord) => \n    dispatch({ type: \"setEnterSecretWord\", payload: enterSecretWord })\n  // END: Challenge #4: Enter Secret Word\n\n  // Challenge #5: Server Error\n  const setServerError = (isServerError) => \n    dispatch({ type: \"setEnterSecretWord\", payload: isServerError })\n  // END: Challenge #5: Server Error\n\n  React.useEffect(\n    () => { hookActions.getSecretWord(setSecretWord, setServerError) },\n    []\n  )\n\n  if(!state.secretWord) {\n    return (\n      <div className=\"container\" data-test=\"spinner\">\n        <div className=\"spinner-border\" role=\"status\">\n          <span className=\"sr-only\">Loading...</span>\n        </div>\n        <p>Loading secret word</p>\n      </div>\n    );\n  }\n\n  return (\n    <div className=\"container\" data-test=\"component-app\">\n      <h1>Jotto</h1>\n      <languageContext.Provider value={state.language}>\n        <LanguagePicker setLanguage={setLanguage} />\n        <guessedWordsContext.GuessedWordsProvider>\n          {/* Challenge #5: Server Error */}\n\n            {/* Challenge #4: Enter Secret Word */}\n            { state.enterSecretWord \n              ? <SecretWordEntry setEnterSecretWord={setEnterSecretWord} setSecretWord={setSecretWord} />\n              : (<div>\n                  <successContext.SuccessProvider>\n                    {/* Challenge #3: Give Up */}\n                    { state.givenUp \n                      ? <SecretWordReveal secretWord={state.secretWord}/>\n                      : <Congrats /> }\n                    {/* END: Challenge #3: Give Up */}\n\n                    {/* Challenge #2 and #3 */}\n                    <NewWordButton setSecretWord={setSecretWord} setGivenUp={setGivenUp} />\n                    { !state.givenUp ? <GiveUpButton setGivenUp={setGivenUp}/> : \"\" }\n                    <Input secretWord={state.secretWord} />\n                    {/* END: Challenge #2 and #3 */}\n\n                  </successContext.SuccessProvider>\n                  <GuessedWords />\n                  <EnterSecretWordButton setEnterSecretWord={setEnterSecretWord} />\n                </div>)\n                }\n              {/* END: Challenge #4: Enter Secret Word */}\n            {/* END: Challenge #5: Server Error */}\n          </guessedWordsContext.GuessedWordsProvider>\n      </languageContext.Provider>\n    </div>\n  );\n}\n\nexport default App;\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/App.test.js",
    "content": "import React from 'react';\nimport { mount } from 'enzyme';\nimport { findByTestAttr } from '../test/testUtils';\nimport App from './App';\n\nimport hookActions from './actions/hookActions';\n\nconst mockGetSecretWord = jest.fn();\n\n/**\n * Setup function for app component.\n * @param {string} secretWord - desired secretWord state value for test\n * @returns {ReactWrapper}\n */\nconst setup = (secretWord=\"party\") => {\n  mockGetSecretWord.mockClear();\n  hookActions.getSecretWord = mockGetSecretWord;\n\n  const mockUseReducer = jest.fn()\n    .mockReturnValue([\n      { secretWord, language: 'en' },\n      jest.fn()\n    ]);\n\n  React.useReducer = mockUseReducer;\n\n  // use mount, because useEffect not called on `shallow`\n  // https://github.com/airbnb/enzyme/issues/2086\n  return mount(<App />);\n}\n\ntest('App renders without error', () => {\n  const wrapper = setup();\n  const component = findByTestAttr(wrapper, 'component-app');\n  expect(component.length).toBe(1);\n});\n\ndescribe('getSecretWord calls', () => {\n  test('getSecretWord gets called on App mount', () => {\n    setup();\n\n    // check to see if secret word was updated\n    expect(mockGetSecretWord).toHaveBeenCalled();\n  });\n  test('secretWord does not update on App update', () => {\n    const wrapper = setup();\n    mockGetSecretWord.mockClear();\n\n    // wrapper.update() doesn't trigger update\n    // (issue forked from https://github.com/airbnb/enzyme/issues/2091)\n    wrapper.setProps();\n\n    expect(mockGetSecretWord).not.toHaveBeenCalled();\n  });\n});\n\ndescribe(\"secretWord is not null\", () => {\n  let wrapper;\n  beforeEach(() => {\n    wrapper = setup(\"party\");\n  });\n\n  test(\"renders app when secretWord is not null\", () => {\n    const appComponent = findByTestAttr(wrapper, \"component-app\");\n    expect(appComponent.exists()).toBe(true);\n  });\n  test(\"does not render spinner when secretWord is not null\", () => {\n    const spinnerComponent = findByTestAttr(wrapper, \"spinner\");\n    expect(spinnerComponent.exists()).toBe(false);\n  });\n\n});\n\ndescribe(\"secretWord is null\", () => {\n  let wrapper;\n  beforeEach(() => {\n    wrapper = setup(null);\n  });\n\n  test(\"does not render app when secretWord is null\", () => {\n    const appComponent = findByTestAttr(wrapper, \"component-app\");\n    expect(appComponent.exists()).toBe(false);\n  });\n  test(\"renders spinner when secretWord is null\", () => {\n    const spinnerComponent = findByTestAttr(wrapper, \"spinner\");\n    expect(spinnerComponent.exists()).toBe(true);\n  });\n});\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/Congrats.js",
    "content": "import React from 'react';\n\nimport successContext from './contexts/successContext';\nimport languageContext from './contexts/languageContext';\nimport stringsModule from './helpers/strings';\n\n/**\n * Functional react component for congratulatory message.\n * @function\n * @returns {JSX.Element} - Rendered component (or null if `success` prop is false).\n */\nconst Congrats = () => {\n  const [success] = successContext.useSuccess();\n  const language = React.useContext(languageContext);\n\n  if (success) {\n    return (\n      <div data-test=\"component-congrats\" className=\"alert alert-success\">\n        <span data-test=\"congrats-message\">\n          {stringsModule.getStringByLanguage(language, 'congrats')}\n        </span>\n      </div>\n    );\n  } else {\n    return (\n      <div data-test=\"component-congrats\" />\n    );\n  }\n};\n\nexport default Congrats;\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/Congrats.test.js",
    "content": "import React from 'react';\nimport { mount } from 'enzyme';\n\nimport { findByTestAttr } from '../test/testUtils';\nimport Congrats from './Congrats';\nimport languageContext from './contexts/languageContext';\nimport successContext from './contexts/successContext';\n\n\n/**\n* Factory function to create a ReactWrapper for the Congrats component.\n* @function setup\n* @param {object} testValues - contextValues specific to this setup.\n* @returns {ReactWrapper}\n*/\nconst setup = ({ success, language }) => {\n  language = language || 'en';\n  success = success || false;\n\n  return mount(\n    <languageContext.Provider value={language}>\n      <successContext.SuccessProvider value={[success, jest.fn()]}>\n        <Congrats />\n      </successContext.SuccessProvider>\n    </languageContext.Provider>\n  );\n}\n\ndescribe('language picker', () => {\n  test('correctly renders congrats string in English by default', () => {\n    const wrapper = setup({ success: true });\n    expect(wrapper.text()).toBe('Congratulations! You guessed the word!');\n  });\n  test('correctly renders congrats string in emoji', () => {\n    const wrapper = setup({ success: true, language: \"emoji\" });\n    expect(wrapper.text()).toBe('🎯🎉');\n  });\n});\n\ntest('renders without error', () => {\n  const wrapper = setup({});\n  const component = findByTestAttr(wrapper, 'component-congrats');\n  expect(component.length).toBe(1);\n});\ntest('renders no text when `success` is false', () => {\n  const wrapper = setup({ success: false });\n  const component = findByTestAttr(wrapper, 'component-congrats');\n  expect(component.text()).toBe('');\n});\ntest('renders non-empty congrats message when `success` is true', () => {\n  const wrapper = setup({ success: true });\n  const message = findByTestAttr(wrapper, 'congrats-message');\n  expect(message.text().length).not.toBe(0);\n});\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/EnterSecretWordButton.js",
    "content": "// Challenge #4: Enter Secret Word\nimport React from \"react\";\nimport PropTypes from \"prop-types\";\n\nimport stringsModule from \"./helpers/strings\";\nimport languageContext from \"./contexts/languageContext\";\nimport guessedWordsContext from \"./contexts/guessedWordsContext\";\n\n/**\n * Functional react component for reset button.\n * @function\n * @param {object} props - React props.\n * @returns {JSX.Element} - Rendered component (or null if `success` context is false).\n */\nexport default function EnterSecretWordButton({ setEnterSecretWord }) {\n  const language = React.useContext(languageContext);\n  \n  const [ guessedWords ] = guessedWordsContext.useGuessedWords();\n  if (guessedWords.length > 0) {\n    return(<div data-test=\"component-secret-word-entry\"></div>)\n  }\n  \n  return (\n    <button \n      data-test=\"component-enter-secret-word-button\"\n      className=\"btn btn-primary mb-2\"\n      onClick={() => setEnterSecretWord(true)}\n    >\n      {stringsModule.getStringByLanguage(language, \"enterSecretWord\")}\n    </button>\n  )\n}\n\nEnterSecretWordButton.propTypes = {\n  setEnterSecretWord: PropTypes.func.isRequired,\n}\n\n// END: Challenge #4: Enter Secret Word"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/EnterSecretWordButton.test.js",
    "content": "// Challenge #3: Give Up\n\nimport React from 'react';\nimport { mount } from 'enzyme';\n\nimport { findByTestAttr, checkProps } from '../test/testUtils';\nimport EnterSecretWordButton from './EnterSecretWordButton';\nimport languageContext from './contexts/languageContext';\nimport guessedWordsContext from './contexts/guessedWordsContext';\n\n\n// for testing that setEnterSecretWord is called with true on click\nconst mockSetEnterSecretWord = jest.fn()\n\n/**\n* Create ReactWrapper for EnterSecretWordButton component for testing\n* @param {object} testValues - Context and props values for this specific test.\n* @returns {ReactWrapper} - Wrapper for EnterSecretWordButton component and providers\n*/\nconst setup = ({ language }) => {\n  language = language || 'en';\n  \n  return mount(\n    <languageContext.Provider value={language}>\n      <guessedWordsContext.GuessedWordsProvider>\n        <EnterSecretWordButton setEnterSecretWord={mockSetEnterSecretWord} />\n      </guessedWordsContext.GuessedWordsProvider>\n    </languageContext.Provider>\n  );\n}\n\ndescribe('render', () => {\n  test('renders without error', () => {\n    // guessedWords length is 0 by default so we would expect it to render by default\n    // We test in integration_tests/enter_secret_word.test.js that it does not render\n    // when there are guessedWords\n    const wrapper = setup({});\n    const component = findByTestAttr(wrapper, 'component-enter-secret-word-button');\n    expect(component.length).toBe(1);\n  });\n});\ntest('does not throw warning with expected props', () => {\n  const expectedProps = { setEnterSecretWord: function() {} };\n  checkProps(EnterSecretWordButton, expectedProps);\n});\n\ntest('calls setEnterSecretWord with the argument \"true\" on click', () => {\n  const wrapper = setup({ });\n  const component = findByTestAttr(wrapper, 'component-enter-secret-word-button');\n  component.simulate('click');\n  expect(mockSetEnterSecretWord).toHaveBeenCalledWith(true);\n});\n\ndescribe('languagePicker', () => {\n  test('correctly renders button text string in english', () => {\n    const wrapper = setup({ language: \"en\", success: true });\n    const component = findByTestAttr(wrapper, 'component-enter-secret-word-button');\n    expect(component.text()).toBe('Enter your own secret word');\n  });\n  test('correctly renders button text string in emoji', () => {\n    const wrapper = setup({ language: \"emoji\", success: true });\n    const component = findByTestAttr(wrapper, 'component-enter-secret-word-button');\n    expect(component.text()).toBe('👩‍💻🤫🔤');\n  });\n})\n\n// END: Challenge #3: Give Up\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/GiveUpButton.js",
    "content": "// Challenge #3: Give Up\nimport React from \"react\";\nimport PropTypes from \"prop-types\";\n\nimport stringsModule from \"./helpers/strings\";\nimport languageContext from \"./contexts/languageContext\";\nimport successContext from \"./contexts/successContext\";\n\n/**\n * Functional react component for reset button.\n * @function\n * @param {object} props - React props.\n * @returns {JSX.Element} - Rendered component (or null if `success` context is false).\n */\nexport default function GiveUpButton({ setGivenUp }) {\n  const language = React.useContext(languageContext);\n  const [success, setSuccess] = successContext.useSuccess();\n\n  if (success) {\n    return <div data-test=\"component-give-up-button\" />\n  }\n  return (\n    <button \n      data-test=\"component-give-up-button\"\n      className=\"btn btn-danger mb-2\"\n      onClick={() => {setGivenUp(true); setSuccess(true)}}\n    >\n      {stringsModule.getStringByLanguage(language, \"giveUp\")}\n    </button>\n  )\n}\n\nGiveUpButton.propTypes = {\n  setGivenUp: PropTypes.func.isRequired,\n}\n\n// END: Challenge #3: Give Up"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/GiveUpButton.test.js",
    "content": "// Challenge #3: Give Up\n\nimport React from 'react';\nimport { mount } from 'enzyme';\n\nimport { findByTestAttr, checkProps } from '../test/testUtils';\nimport GiveUpButton from './GiveUpButton';\nimport languageContext from './contexts/languageContext';\nimport successContext from './contexts/successContext';\n\n\n// for testing that setGivenUp is called with true on click\nconst mockSetGivenUp = jest.fn()\n\n/**\n* Create ReactWrapper for GiveUpButton component for testing\n* @param {object} testValues - Context and props values for this specific test.\n* @returns {ReactWrapper} - Wrapper for GiveUpButton component and providers\n*/\nconst setup = ({ language }) => {\n  language = language || 'en';\n  \n  return mount(\n    <languageContext.Provider value={language}>\n      <successContext.SuccessProvider>\n        <GiveUpButton setGivenUp={mockSetGivenUp} />\n      </successContext.SuccessProvider>\n    </languageContext.Provider>\n  );\n}\n\ndescribe('render', () => {\n  test('renders without error', () => {\n    const wrapper = setup({});\n    const component = findByTestAttr(wrapper, 'component-give-up-button');\n    expect(component.length).toBe(1);\n  });\n});\ntest('does not throw warning with expected props', () => {\n  const expectedProps = { setGivenUp: function() {} };\n  checkProps(GiveUpButton, expectedProps);\n});\n\ntest('calls setGivenUp with the argument \"true\" on click', () => {\n  const wrapper = setup({ });\n  const component = findByTestAttr(wrapper, 'component-give-up-button');\n  component.simulate('click');\n  expect(mockSetGivenUp).toHaveBeenCalledWith(true);\n});\n\ndescribe('languagePicker', () => {\n  test('correctly renders button text string in english', () => {\n    const wrapper = setup({ language: \"en\", success: true });\n    const component = findByTestAttr(wrapper, 'component-give-up-button');\n    expect(component.text()).toBe('Give Up');\n  });\n  test('correctly renders button text string in emoji', () => {\n    const wrapper = setup({ language: \"emoji\", success: true });\n    const component = findByTestAttr(wrapper, 'component-give-up-button');\n    expect(component.text()).toBe('😩');\n  });\n})\n\n// END: Challenge #3: Give Up\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/GuessedWords.js",
    "content": "import React from 'react';\n\nimport guessedWordsContext from './contexts/guessedWordsContext';\nimport languageContext from './contexts/languageContext';\nimport stringsModule from './helpers/strings';\n\nconst GuessedWords = () => {\n  const [guessedWords] = guessedWordsContext.useGuessedWords();\n  const language = React.useContext(languageContext);\n  let contents\n  if (guessedWords.length === 0) {\n    contents = (\n      <span data-test=\"guess-instructions\">\n        {stringsModule.getStringByLanguage(language, 'guessPrompt')}\n      </span>\n    );\n  } else {\n    const guessedWordsRows = guessedWords.map((word, index) => (\n      <tr data-test=\"guessed-word\" key={ index }>\n        <td data-test=\"guessed-word-index\">{ index + 1 }</td>\n        <td>{ word.guessedWord }</td>\n        <td>{ word.letterMatchCount }</td>\n      </tr>\n    ));\n    contents = (\n      <div data-test=\"guessed-words\">\n        <h3>{stringsModule.getStringByLanguage(language, 'guessedWords')}</h3>\n        <table className=\"table table-sm\">\n          <thead className=\"thead-light\">\n            <tr>\n              {// Challenge #1: Number of Guesses\n              }\n              <th>{stringsModule.getStringByLanguage(language, 'numberColumnHeader')}</th>\n              {// END: Challenge #1: Number of Guesses\n              }\n              <th>{stringsModule.getStringByLanguage(language, 'guessColumnHeader')}</th>\n              <th>{stringsModule.getStringByLanguage(language, 'matchingLettersColumnHeader')}</th>\n            </tr>\n          </thead>\n          <tbody>\n            { guessedWordsRows }\n          </tbody>\n        </table>\n        {// Challenge #1: Number of Guesses\n        }\n        <div data-test='total-guesses'>{stringsModule.getStringByLanguage(language, 'totalGuesses')}: {guessedWords.length}</div>\n        {// END: Challenge #1: Number of Guesses\n        }\n      </div>\n    );\n  }\n  return (\n    <div data-test=\"component-guessed-words\">\n      { contents }\n    </div>\n  );\n};\n\nexport default GuessedWords;\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/GuessedWords.test.js",
    "content": "import React from 'react';\nimport { shallow } from 'enzyme';\nimport { findByTestAttr } from '../test/testUtils';\nimport GuessedWords from './GuessedWords';\n\nimport guessedWordsContext from './contexts/guessedWordsContext';\nimport { number } from 'prop-types';\n\n/**\n* Factory function to create a ShallowWrapper for the GuessedWords component.\n* @function setup\n* @param {array} guessedWords - guessedWords value specific to this setup.\n* @returns {ShallowWrapper}\n*/\nconst setup = (guessedWords=[]) => {\n  const mockUseGuessedWords = jest.fn().mockReturnValue([guessedWords, jest.fn()]);\n  guessedWordsContext.useGuessedWords = mockUseGuessedWords;\n  return shallow(<GuessedWords />)\n};\n\ndescribe('if there are no words guessed', () => {\n  let wrapper\n  beforeEach(() => {\n    wrapper = setup([]);\n  });\n  test('renders without error', () => {\n    const component = findByTestAttr(wrapper, 'component-guessed-words');\n    expect(component.length).toBe(1);\n  });\n  test('renders instructions to guess a word', () => {\n    const instructions = findByTestAttr(wrapper, 'guess-instructions');\n    expect(instructions.text().length).not.toBe(0);\n  });\n});\ndescribe('if there are words guessed', () => {\n  let wrapper;\n  const guessedWords = [\n    { guessedWord: 'train', letterMatchCount: 3 },\n    { guessedWord: 'agile', letterMatchCount: 1 },\n    { guessedWord: 'party', letterMatchCount: 5 },\n  ];\n  beforeEach(() => {\n    wrapper = setup(guessedWords);\n  });\n  test ('renders without error', () => {\n    const component = findByTestAttr(wrapper, 'component-guessed-words');\n    expect(component.length).toBe(1);\n  });\n  test('renders \"guessed words\" section', () => {\n    const guessedWordsNode = findByTestAttr(wrapper, 'guessed-words');\n    expect(guessedWordsNode.length).toBe(1);\n  });\n  test('correct number of guessed words', () => {\n    const guessedWordNodes = findByTestAttr(wrapper, 'guessed-word');\n    expect(guessedWordNodes.length).toBe(guessedWords.length);\n  });\n  // Challenge #1: Number of Guesses\n  test('includes guess word index for each word', () => {\n    const guessWordIndexes = findByTestAttr(wrapper, 'guessed-word-index');\n    const indexesText = guessWordIndexes.map(wrapper => wrapper.text());\n    const expectedText = guessedWords.map((word, index) => (index + 1).toString());\n    expect(indexesText).toEqual(expectedText);\n  });\n  test('number of guesses is displayed correctly', () => {\n    const numberOfGuessesDiv = findByTestAttr(wrapper, 'total-guesses');\n    expect(numberOfGuessesDiv.text()).toContain(guessedWords.length)\n  })\n  // END: Challenge #1: Number of Guesses\n});\n\ndescribe(\"languagePicker\", () => {\n  test(\"correctly renders guess instructions string in English by default\", () => {\n    const wrapper = setup([]);\n    const guessInstructions = findByTestAttr(wrapper, \"guess-instructions\");\n    expect(guessInstructions.text()).toBe('Try to guess the secret word!');\n  });\n  test(\"correctly renders guess instructions string in emoji\", () => {\n    const mockUseContext = jest.fn().mockReturnValue('emoji');\n    React.useContext = mockUseContext;\n    const wrapper = setup([]);\n    const guessInstructions = findByTestAttr(wrapper, \"guess-instructions\");\n    expect(guessInstructions.text()).toBe('🤔🤫🔤');\n  });\n});\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/Input.js",
    "content": "import React from 'react';\nimport PropTypes from 'prop-types';\n\nimport guessedWordsContext from './contexts/guessedWordsContext';\nimport successContext from './contexts/successContext';\nimport languageContext from './contexts/languageContext';\nimport stringsModule from './helpers/strings';\nimport { getLetterMatchCount } from './helpers';\n\nfunction Input({ secretWord }) {\n  const language = React.useContext(languageContext);\n  const [success, setSuccess] = successContext.useSuccess();\n  const [guessedWords, setGuessedWords] = guessedWordsContext.useGuessedWords();\n  const [ currentGuess, setCurrentGuess ] = React.useState(\"\");\n\n  if (success) { return null }\n\n  return (\n    <div data-test='component-input'>\n      <form className=\"form-inline\">\n        <input\n          data-test=\"input-box\"\n          className=\"mb-2 mx-sm-3\"\n          type=\"text\"\n          placeholder={stringsModule.getStringByLanguage(language, 'guessInputPlaceholder')}\n          value={currentGuess}\n          onChange={(event) => setCurrentGuess(event.target.value)}\n        />\n        <button\n          data-test=\"submit-button\"\n          onClick={(evt) => {\n            evt.preventDefault();\n            // update guessedWords\n            const letterMatchCount = getLetterMatchCount(currentGuess, secretWord);\n            const newGuessedWords = [...guessedWords, { guessedWord: currentGuess, letterMatchCount }];\n            setGuessedWords(newGuessedWords);\n\n            // check against secretWord and update success if needed\n            if (currentGuess === secretWord) {\n              setSuccess(true);\n            }\n            // clear input box\n            setCurrentGuess(\"\");\n          }}\n          className=\"btn btn-primary mb-2\">\n          {stringsModule.getStringByLanguage(language, 'submit')}\n        </button>\n      </form>\n    </div>\n  );\n}\n\nInput.propTypes = {\n  secretWord: PropTypes.string.isRequired,\n}\n\nexport default Input;\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/Input.test.js",
    "content": "import React from 'react';\nimport { mount } from 'enzyme';\n\nimport { findByTestAttr, checkProps } from '../test/testUtils';\nimport Input from './Input';\nimport languageContext from './contexts/languageContext';\nimport successContext from './contexts/successContext';\nimport guessedWordsContext from './contexts/guessedWordsContext';\n\n/**\n* Create ReactWrapper for Input component for testing\n* @param {object} testValues - Context and props values for this specific test.\n* @returns {ReactWrapper} - Wrapper for Input component and providers\n*/\nconst setup = ({ language, secretWord, success }) => {\n  language = language || \"en\";\n  secretWord = secretWord || \"party\";\n  success = success || false;\n\n  return mount(\n    <languageContext.Provider value={language} >\n      <successContext.SuccessProvider value={[success, jest.fn()]}>\n        <guessedWordsContext.GuessedWordsProvider>\n          <Input secretWord={secretWord} />\n        </guessedWordsContext.GuessedWordsProvider>\n      </successContext.SuccessProvider>\n    </languageContext.Provider>\n  );\n}\n\ntest('Input renders without error', () => {\n  const wrapper = setup({});\n  const inputComponent = findByTestAttr(wrapper, 'component-input');\n  expect(inputComponent.length).toBe(1);\n});\n\ntest('does not throw warning with expected props', () => {\n  checkProps(Input, { secretWord: \"party\" });\n});\n\ndescribe('state controlled input field', () => {\n  let mockSetCurrentGuess = jest.fn();\n  let wrapper;\n\n  beforeEach(() => {\n    mockSetCurrentGuess.mockClear();\n    React.useState = jest.fn(() => [\"\", mockSetCurrentGuess]);\n    wrapper = setup({});\n  });\n  test('state updates with value of input box upon change', () => {\n    const inputBox = findByTestAttr(wrapper, 'input-box');\n\n    const mockEvent = { target: { value: 'train' } };\n    inputBox.simulate(\"change\", mockEvent);\n\n    expect(mockSetCurrentGuess).toHaveBeenCalledWith('train');\n  });\n  test('field is cleared upon submit button click', () => {\n    const submitButton = findByTestAttr(wrapper, 'submit-button');\n\n    submitButton.simulate('click', { preventDefault() {} });\n    expect(mockSetCurrentGuess).toHaveBeenCalledWith(\"\");\n  })\n});\n\ndescribe('languagePicker', () => {\n  test('correctly renders submit string in english', () => {\n    const wrapper = setup({ language: \"en\" });\n    const submitButton = findByTestAttr(wrapper, 'submit-button');\n    expect(submitButton.text()).toBe('Submit');\n  });\n  test('correctly renders congrats string in emoji', () => {\n    const wrapper = setup({ language: \"emoji\" });\n    const submitButton = findByTestAttr(wrapper, 'submit-button');\n    expect(submitButton.text()).toBe('🚀');\n  });\n});\n\ntest('input component does not show when success is true', () => {\n  const wrapper = setup({ secretWord: \"party\", success: true });\n  expect(wrapper.isEmptyRender()).toBe(true);\n});\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/LanguagePicker.js",
    "content": "import React from 'react';\nimport propTypes from 'prop-types';\n\nfunction LanguagePicker({ setLanguage }) {\n  const languages = [\n    { code: 'en', symbol: '🇺🇸' },\n    { code: 'emoji', symbol: '😊' },\n  ];\n\n  const languageIcons = languages.map(lang =>\n    <span\n      data-test=\"language-icon\"\n      key={lang.code}\n      onClick={() => setLanguage(lang.code)}\n    >\n    {lang.symbol}\n    </span>\n  );\n\n  return (\n    <div data-test=\"component-language-picker\">\n      {languageIcons}\n    </div>\n  );\n}\n\nLanguagePicker.propTypes = {\n  setLanguage: propTypes.func.isRequired,\n}\n\nexport default LanguagePicker;\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/LanguagePicker.test.js",
    "content": "import React from 'react';\nimport { shallow } from 'enzyme';\n\nimport { findByTestAttr, checkProps } from '../test/testUtils';\nimport LanguagePicker from './LanguagePicker';\n\nconst mockSetLanguage = jest.fn();\n\nconst setup = () => {\n    return shallow(<LanguagePicker setLanguage={mockSetLanguage} />);\n}\n\ntest('renders without error', () => {\n  const wrapper = setup();\n  const component = findByTestAttr(wrapper, \"component-language-picker\");\n  expect(component.exists()).toBe(true);\n});\n\ntest('does not throw warning with expected props', () => {\n  checkProps(LanguagePicker, { setLanguage: jest.fn() });\n});\n\ntest('renders non-zero language icons', () => {\n  const wrapper = setup();\n  const languageIcons = findByTestAttr(wrapper, \"language-icon\");\n  expect(languageIcons.length).toBeGreaterThan(0);\n\n});\n\ntest('calls setLanguage prop upon click', () => {\n  const wrapper = setup();\n  const languageIcons = findByTestAttr(wrapper, \"language-icon\");\n\n  const firstIcon = languageIcons.first();\n  firstIcon.simulate(\"click\");\n\n  expect(mockSetLanguage).toHaveBeenCalled();\n});\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/NewWordButton.js",
    "content": "// Challenge #2: Reset Game\nimport React from \"react\";\nimport PropTypes from \"prop-types\";\n\nimport stringsModule from \"./helpers/strings\";\nimport languageContext from \"./contexts/languageContext\";\nimport hookactions from \"./actions/hookActions\"\n\nimport successContext from \"./contexts/successContext\";\nimport guessedWordsContext from \"./contexts/guessedWordsContext\";\n\n/**\n * Functional react component for reset button.\n * @function\n * @param {object} props - React props.\n * @returns {JSX.Element} - Rendered component (or null if `success` context is false).\n */\nexport default function NewWordButton(props) {\n  const language = React.useContext(languageContext);\n\n  const [ guessedWords, setGuessedWords ] = guessedWordsContext.useGuessedWords();\n  const [ success, setSuccess ] = successContext.useSuccess();\n  const resetGame = (setSecretWord, setGivenUp) => {\n\n    // reset the secret word\n    hookactions.getSecretWord(setSecretWord)\n\n    // reset the guessedWords array\n    setGuessedWords([]);\n\n    // reset success\n    setSuccess(false);\n\n    // Challenge #3: Give Up\n    // reset givenUp\n    setGivenUp(false);\n    // END: Challenge #3: Give Up\n\n  }\n\n  if (success) {\n    return (\n      <button \n        data-test=\"component-new-word-button\"\n        className=\"btn btn-primary mb-2\"\n        // Challenge #3: Give Up\n        onClick={() => resetGame(props.setSecretWord, props.setGivenUp)}\n        // END: Challenge #3: Give Up\n      >\n        {stringsModule.getStringByLanguage(language, \"newWord\")}\n      </button>\n    )\n  }\n  else {\n    return <div data-test=\"component-new-word-button\"></div>;\n  }\n}\n\nNewWordButton.propTypes = {\n  setSecretWord: PropTypes.func.isRequired,\n  \n  // Challenge #3: Give Up\n  setGivenUp: PropTypes.func.isRequired,\n  // END: Challenge #3: Give Up\n}\n\n// END: Challenge #2: Reset Game\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/NewWordButton.test.js",
    "content": "// Challenge #2: Reset Game\n\nimport React from 'react';\nimport { mount } from 'enzyme';\n\nimport { findByTestAttr, checkProps } from '../test/testUtils';\nimport NewWordButton from './NewWordButton';\nimport successContext from './contexts/successContext';\nimport languageContext from './contexts/languageContext';\nimport guessedWordsContext from './contexts/guessedWordsContext';\nimport hookActions from './actions/hookActions';\n\n\n// for testing that setSuccess is called with false on click\nconst mockSetSuccess = jest.fn()\n\n/**\n* Create ReactWrapper for NewWordButton component for testing\n* @param {object} testValues - Context and props values for this specific test.\n* @returns {ReactWrapper} - Wrapper for NewWordButton component and providers\n*/\nconst setup = ({ success, language, setSecretWord, setGivenUp }) => {\n  success = success || false;\n  setSecretWord = setSecretWord || function() {};\n  setGivenUp = setGivenUp || function() {};\n  language = language || 'en';\n  \n  return mount(\n    <guessedWordsContext.GuessedWordsProvider>\n      <languageContext.Provider value={language}>\n        <successContext.SuccessProvider value={[success, mockSetSuccess]}>\n          <NewWordButton setSecretWord={setSecretWord} setGivenUp={setGivenUp}/>\n        </successContext.SuccessProvider>\n      </languageContext.Provider>\n    </guessedWordsContext.GuessedWordsProvider>\n  );\n}\ndescribe('render', () => {\n  test('renders without error', () => {\n    const wrapper = setup({ success: true });\n    const component = findByTestAttr(wrapper, 'component-new-word-button');\n    expect(component.length).toBe(1);\n  });\n  test('renders no text when `success` context is false', () => {\n    const wrapper = setup({ success: false });\n    const component = findByTestAttr(wrapper, 'component-new-word-button');\n    expect(component.text().length).toBe(0);\n  });\n  test('renders non-empty text when `success` context is true', () => {\n    const wrapper = setup({ success: true });\n    const component = findByTestAttr(wrapper, 'component-new-word-button');\n    expect(component.text().length).not.toBe(0);\n  });\n});\ntest('does not throw warning with expected props', () => {\n  const expectedProps = { setSecretWord: function() {}, setGivenUp: function() {} };\n  checkProps(NewWordButton, expectedProps);\n});\n\ndescribe('actions on click', () => {\n  // this just that resetAction was called, and not the effects\n  const mockGetSecretWord = jest.fn();\n  const mockSetGivenUp = jest.fn();\n  let mockResetAction;\n  beforeEach(() => {\n    hookActions.getSecretWord = mockGetSecretWord;\n\n    const wrapper = setup({success: true, setSecretWord: jest.fn(), setGivenUp: mockSetGivenUp });\n    const component = findByTestAttr(wrapper, 'component-new-word-button');\n    component.simulate('click');\n  });\n  test('calls getSecretWord on click', () => {\n    expect(mockGetSecretWord).toHaveBeenCalledTimes(1);\n  });\n  test('resets success to false on click', () => {\n    expect(mockSetSuccess).toHaveBeenCalledWith(false);\n  });\n  test('resets givenUp to false on click', () => {\n    expect(mockSetGivenUp).toHaveBeenCalledWith(false);\n  });\n});\n\ndescribe('languagePicker', () => {\n  test('correctly renders button text string in english', () => {\n    const wrapper = setup({ language: \"en\", success: true });\n    const component = findByTestAttr(wrapper, 'component-new-word-button');\n    expect(component.text()).toBe('New Word');\n  });\n  test('correctly renders button text string in emoji', () => {\n    const wrapper = setup({ language: \"emoji\", success: true });\n    const component = findByTestAttr(wrapper, 'component-new-word-button');\n    expect(component.text()).toBe('✨🔤');\n  });\n});\n\n// END: Challenge #2: Reset Game\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/SecretWordEntry.js",
    "content": "// Challenge #4: Enter Secret Word\nimport React from \"react\";\nimport PropTypes from \"prop-types\";\n\nimport stringsModule from \"./helpers/strings\";\nimport languageContext from \"./contexts/languageContext\";\n\n/**\n * Functional react component for reset button.\n * @function\n * @param {object} props - React props.\n * @returns {JSX.Element} - Rendered component (or null if `success` context is false).\n */\nexport default function SecretWordEntry({ setEnterSecretWord, setSecretWord }) {\n  const language = React.useContext(languageContext);\n  const[ customSecretWord, setCustomSecretWord ] = React.useState();\n  \n  return (\n    <div \n      data-test=\"component-secret-word-entry\"\n    >\n      <form className=\"form-inline\">\n        <input \n          data-test=\"secret-word-input-box\"\n          type=\"text\"\n          value={customSecretWord}\n          onChange={(evt) => setCustomSecretWord(evt.target.value)}\n          />\n        <button \n          data-test=\"submit-secret-word-button\"\n          className=\"btn btn-primary mb-2\"\n          onClick={(evt) => {\n            evt.preventDefault();\n            setEnterSecretWord(false);\n            setSecretWord(customSecretWord);\n            setCustomSecretWord(\"\");\n          }\n        }\n        >\n          {stringsModule.getStringByLanguage(language, \"enterSecretWord\")}\n        </button>\n      </form>\n    </div>\n  )\n}\n\nSecretWordEntry.propTypes = {\n  setEnterSecretWord: PropTypes.func.isRequired,\n  setSecretWord: PropTypes.func.isRequired,\n}\n\n// END: Challenge #4: Enter Secret Word"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/SecretWordEntry.test.js",
    "content": "import React from 'react';\nimport { mount } from 'enzyme';\n\nimport { findByTestAttr, checkProps } from '../test/testUtils';\nimport SecretWordEntry from './SecretWordEntry';\nimport languageContext from './contexts/languageContext';\nimport successContext from './contexts/successContext';\nimport guessedWordsContext from './contexts/guessedWordsContext';\n\n/**\n* Create ReactWrapper for SecretWordEntry component for testing\n* @param {object} testValues - Context and props values for this specific test.\n* @returns {ReactWrapper} - Wrapper for SecretWordEntry component and providers\n*/\nconst setup = ({ language, setEnterSecretWord, setSecretWord }) => {\n  language = language || \"en\";\n  setEnterSecretWord = setEnterSecretWord || function() {};\n  setSecretWord = setSecretWord || function() {};\n\n  return mount(\n    <languageContext.Provider value={language} >\n      <SecretWordEntry setEnterSecretWord={setEnterSecretWord} setSecretWord={setSecretWord} />\n    </languageContext.Provider>\n  );\n}\n\ntest('SecretWordEntry renders without error', () => {\n  const wrapper = setup({});\n  const SecretWordEntryComponent = findByTestAttr(wrapper, 'component-secret-word-entry');\n  expect(SecretWordEntryComponent.length).toBe(1);\n});\n\ntest('does not throw warning with expected props', () => {\n  checkProps(SecretWordEntry, { setEnterSecretWord: function() {}, setSecretWord: function() {} });\n});\n\ntest('state updates with value of secret word input box upon change', () => {\n  const mockSetCustomSecretWord = jest.fn();\n  React.useState = jest.fn(() => [\"\", mockSetCustomSecretWord]);\n  const wrapper = setup({ });\n  const secretWordInputBox = findByTestAttr(wrapper, 'secret-word-input-box');\n\n  const mockEvent = { target: { value: 'train' } };\n  secretWordInputBox.simulate(\"change\", mockEvent);\n\n  expect(mockSetCustomSecretWord).toHaveBeenCalledWith('train');\n});\n\ndescribe('submit calls the correct functions', () => {\n  const mockSetEnterSecretWord = jest.fn();\n  const mockSetSecretWord = jest.fn();\n  const mockSetCustomSecretWord = jest.fn();\n  let wrapper;\n\n  beforeEach(() => {\n    mockSetEnterSecretWord.mockClear();\n    mockSetSecretWord.mockClear();\n    React.useState = jest.fn(() => [\"train\", mockSetCustomSecretWord]);\n    wrapper = setup({ setEnterSecretWord: mockSetEnterSecretWord, setSecretWord: mockSetSecretWord});\n\n    // simulate entering 'train' into the custom secret word box\n    const secretWordInputBox = findByTestAttr(wrapper, 'secret-word-input-box');\n    const mockEvent = { target: { value: 'train' } };\n    secretWordInputBox.simulate(\"change\", mockEvent);\n  \n    // simulate clicking the button\n    const submitButton = findByTestAttr(wrapper, 'submit-secret-word-button');\n    submitButton.simulate('click');\n  });\n  test(\"expect setSecretWord to be called with 'train'\", () => {\n    expect(mockSetSecretWord).toHaveBeenCalledWith(\"train\");\n  });\n  test(\"expect setEnterSecretWord to be called with false\", () => {\n    expect(mockSetEnterSecretWord).toHaveBeenCalledWith(false);\n  });\n  test(\"expect custom secret word state to be reset to empty string\", () => {\n    expect(mockSetCustomSecretWord).toHaveBeenCalledWith(\"\");\n  });\n});\n\ndescribe('languagePicker', () => {\n  test('correctly renders submit string in english', () => {\n    const wrapper = setup({ language: \"en\" });\n    const submitButton = findByTestAttr(wrapper, 'submit-secret-word-button');\n    expect(submitButton.text()).toBe('Enter your own secret word');\n  });\n  test('correctly renders congrats string in emoji', () => {\n    const wrapper = setup({ language: \"emoji\" });\n    const submitButton = findByTestAttr(wrapper, 'submit-secret-word-button');\n    expect(submitButton.text()).toBe('👩‍💻🤫🔤');\n  });\n});\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/SecretWordReveal.js",
    "content": "// Challenge #3: Give Up\nimport React from \"react\";\nimport PropTypes from \"prop-types\";\n\nimport stringsModule from \"./helpers/strings\";\nimport languageContext from \"./contexts/languageContext\";\n\n/**\n * Functional react component for revealed secret word\n *    (for use after the player has given up)\n * @function\n * @param {object} props - React props.\n * @returns {JSX.Element} - Rendered component with secret word\n */\nexport default function SecretWordReveal({ secretWord }) {\n  const language = React.useContext(languageContext);\n\n  return (\n    <div data-test=\"component-secret-word-reveal\" className=\"alert alert-danger\">\n      <p>{stringsModule.getStringByLanguage(language, \"secretWordWas\")} \"{secretWord}\"</p>\n      <p>{stringsModule.getStringByLanguage(language, \"betterLuck\")}</p>\n    </div>\n  )\n}\n\nSecretWordReveal.propTypes = {\n  secretWord: PropTypes.string.isRequired,\n}\n\n// END: Challenge #3: Give Up\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/SecretWordReveal.test.js",
    "content": "// Challenge #3: Give Up\n\nimport React from 'react';\nimport { mount } from 'enzyme';\nimport { findByTestAttr, checkProps } from '../test/testUtils';\nimport SecretWordReveal from './SecretWordReveal';\nimport languageContext from './contexts/languageContext';\n\n/**\n* Create ReactWrapper for SecretWordReveal component for testing\n* @param {object} testValues - Props values for this specific test.\n* @returns {ReactWrapper} - Wrapper for SecretWordReveal\n*/\nconst setup = ({ language, secretWord }) => {\n  language = language || 'en';\n  secretWord = secretWord || 'party';\n  \n  return mount(\n    <languageContext.Provider value={language}>\n      <SecretWordReveal secretWord={secretWord}/>\n    </languageContext.Provider>\n  );\n}\n\ntest('renders without error', () => {\n  const wrapper = setup({});\n  const component = findByTestAttr(wrapper, 'component-secret-word-reveal');\n  expect(component.length).toBe(1);\n});\n\ntest('secret word is included in text', () => {\n  // explicitly specifying 'party' here (rather than using default\n  // from `setup`) for ease in understanding test\n  const wrapper = setup({ secretWord: 'party' });\n  const component = findByTestAttr(wrapper, 'component-secret-word-reveal');\n  expect(component.text()).toContain('party');\n});\n\ntest('does not throw warning with expected props', () => {\n  const expectedProps = { secretWord: 'party' };\n  checkProps(SecretWordReveal, expectedProps);\n});\n\ndescribe('languagePicker', () => {\n  test('correctly renders `better luck` string in english', () => {\n    const wrapper = setup({ language: \"en\" });\n    const component = findByTestAttr(wrapper, 'component-secret-word-reveal');\n    expect(component.text()).toContain('Better luck next time!');\n  });\n  test('correctly renders `better luck` string in emoji', () => {\n    const wrapper = setup({ language: \"emoji\" });\n    const component = findByTestAttr(wrapper, 'component-secret-word-reveal');\n    expect(component.text()).toContain('🍀✨🔤');\n  });\n});\n\n// END: Challenge #3: Give Up\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/ServerError.js",
    "content": "// Challenge #5: Server Error\nimport React from \"react\";\n\nimport stringsModule from \"./helpers/strings\";\nimport languageContext from \"./contexts/languageContext\";\n\n/**\n * Functional react component for revealed secret word\n *    (for use after the player has given up)\n * @function\n * @param {object} props - React props.\n * @returns {JSX.Element} - Rendered component with secret word\n */\nexport default function ServerError(props) {\n  const language = React.useContext(languageContext);\n\n  return (\n    <div data-test=\"component-server-error\" className=\"alert alert-danger\">\n      {stringsModule.getStringByLanguage(language, \"serverError\")}\n    </div>\n  )\n}\n\n// Challenge #5: Server Error\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/ServerError.test.js",
    "content": "// Challenge #5: Server Error\n\nimport React from 'react';\nimport { mount } from 'enzyme';\nimport { findByTestAttr, checkProps } from '../test/testUtils';\nimport ServerError from './ServerError';\nimport languageContext from './contexts/languageContext';\n\n/**\n* Create ReactWrapper for ServerError component for testing\n* @param {object} testValues - Props values for this specific test.\n* @returns {ReactWrapper} - Wrapper for ServerError\n*/\nconst setup = ({ language }) => {\n  language = language || 'en';\n  \n  return mount(\n    <languageContext.Provider value={language}>\n      <ServerError />\n    </languageContext.Provider>\n  );\n}\n\ntest('renders without error', () => {\n  const wrapper = setup({});\n  const component = findByTestAttr(wrapper, 'component-server-error');\n  expect(component.length).toBe(1);\n});\n\ndescribe('languagePicker', () => {\n  test('correctly renders `better luck` string in english', () => {\n    const wrapper = setup({ language: \"en\" });\n    const component = findByTestAttr(wrapper, 'component-server-error');\n    expect(component.text()).toContain('There was an error retrieving the secret word. Please try again later.');\n  });\n  test('correctly renders `better luck` string in emoji', () => {\n    const wrapper = setup({ language: \"emoji\" });\n    const component = findByTestAttr(wrapper, 'component-server-error');\n    expect(component.text()).toContain('🚨. ⏲.');\n  });\n});\n\n// END: Challenge #5: Server Error\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/actions/hookActions.js",
    "content": "import axios from 'axios';\n\nexport const getSecretWord = async (setSecretWord, setServerError) => {\n  // Challenge #5: Server Error\n  try {\n    const response = await axios.get('http://localhost:3030');\n    setSecretWord(response.data);\n  }\n  catch {\n    setServerError(true);\n  }\n  // END: Challenge #5: Server Error\n}\n\n// default export for mocking convenience\nexport default {\n  getSecretWord,\n}\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/actions/hookActions.test.js",
    "content": "import moxios from 'moxios';\n\nimport { getSecretWord } from './hookActions';\n\ndescribe('moxios tests', () => {\n  beforeEach(() => {\n    moxios.install();\n  });\n  afterEach(() => {\n    moxios.uninstall();\n  });\n\n  describe('non-error response', () => {\n    // create mocks for callback args\n    const mockSetSecretWord = jest.fn();\n    const mockSetServerError = jest.fn();\n    const secretWord = 'party';\n      \n    beforeEach(async () => {\n      moxios.wait(() => {\n        const request = moxios.requests.mostRecent();\n        request.respondWith({\n          status: 200,\n          response: secretWord,\n        });\n      });\n      \n      await getSecretWord(mockSetSecretWord, mockSetServerError);\n      \n    });\n    test('calls the getSecretWord callback on axios response', async () => {\n     // see whether mock was run with the correct argument\n      expect(mockSetSecretWord).toHaveBeenCalledWith(secretWord);\n    });\n    test('does not call the setServerError callback on axios response', async () => {\n     // see whether mock was run with the correct argument\n      expect(mockSetServerError).not.toHaveBeenCalled();\n    });\n  });\n\n  // Challenge #5: Server Error\n  describe('5xx error response', () => {\n    // create mocks for callback args\n    const mockSetSecretWord = jest.fn();\n    const mockSetServerError = jest.fn();\n      \n    beforeEach(async () => {\n      moxios.wait(() => {\n        const request = moxios.requests.mostRecent();\n        request.respondWith({\n          status: 500,\n        });\n      });\n      \n      await getSecretWord(mockSetSecretWord, mockSetServerError);\n      \n    });\n    test('calls the getSecretWord callback on axios response', async () => {\n     // see whether mock was run with the correct argument\n      expect(mockSetServerError).toHaveBeenCalledWith(true);\n    });\n    test('does not call the setServerError callback on axios response', async () => {\n     // see whether mock was run with the correct argument\n      expect(mockSetSecretWord).not.toHaveBeenCalled();\n    });\n  });\n  describe('4xx error response', () => {\n    // create mocks for callback args\n    const mockSetSecretWord = jest.fn();\n    const mockSetServerError = jest.fn();\n      \n    beforeEach(async () => {\n      moxios.wait(() => {\n        const request = moxios.requests.mostRecent();\n        request.respondWith({\n          status: 404,\n        });\n      });\n      \n      await getSecretWord(mockSetSecretWord, mockSetServerError);\n      \n    });\n    test('calls the getSecretWord callback on axios response', async () => {\n     // see whether mock was run with the correct argument\n      expect(mockSetServerError).toHaveBeenCalledWith(true);\n    });\n    test('does not call the setServerError callback on axios response', async () => {\n     // see whether mock was run with the correct argument\n      expect(mockSetSecretWord).not.toHaveBeenCalled();\n    });\n  });\n  // Challenge #5: Server Error\n});\n\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/contexts/guessedWordsContext.js",
    "content": "import React from 'react'\n\n// no default value\nconst guessedWordsContext = React.createContext();\n\n/**\n * @function useGuessedWords\n * @returns {Array} guessedWordsContext value, which is a state of [value, setter].\n * \n */\nexport function useGuessedWords() {\n  // useContext is a hook that returns the context value\n  // In this case, the context value is an [value, setter] array for the context state\n  // useContext also subscribes to changes, and will update any time the context value updates\n  //     we've memoized this so that it will only update when the guessedWords value updates\n  const context = React.useContext(guessedWordsContext)\n\n  // throw an error if the context doesn't exist -- means we aren't in a provider\n  if (!context) {\n    throw new Error('useGuessedWords must be used within a GuessedWordsProvider')\n  }\n\n  // otherwise return the context\n  return context\n}\n\n/**\n * @function GuessedWordsProvider\n * @param {object} props - props to pass through from declared component\n * @returns {JSX.Element} Provider component \n */\nexport function GuessedWordsProvider(props) {\n  // create state that will be used within the provider\n  // initial state value is false \n  const [guessedWords, setGuessedWords] = React.useState([])\n\n  // value for the context provider will be array of [value, setter] for guessedWords state\n  // useMemo just ensures that the provider value will only update when guessedWords updates\n  // No need to test this -- React tests useMemo for us!\n  const value = React.useMemo(() => [guessedWords, setGuessedWords], [guessedWords])\n\n  // Return a Provider component with the [value, setter] array as the value, passing through the props\n  return <guessedWordsContext.Provider value={value} {...props} />\n}\n\nexport default { GuessedWordsProvider, useGuessedWords }"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/contexts/guessedWordsContext.test.js",
    "content": "import React from 'react';\nimport { shallow } from 'enzyme';\n\nimport { GuessedWordsProvider, useGuessedWords } from './GuessedWordsContext';\n\n// a functional component that calls useGuessedWords for our tests\nconst FunctionalComponent = () => {\n  useGuessedWords();\n  return <div />;\n}\n\ntest('useGuessedWords throws error when not wrapped in GuessedWordsProvider', () => {\n  expect(() => {\n    shallow(<FunctionalComponent />)\n  }).toThrow('useGuessedWords must be used within a GuessedWordsProvider');\n});\n\ntest('useGuessedWords does not throw error when wrapped in GuessedWordsProvider', () => {\n  expect(() => {\n    shallow(\n      <GuessedWordsProvider>\n        <FunctionalComponent />\n      </GuessedWordsProvider>\n    )\n  }).not.toThrow()\n});\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/contexts/languageContext.js",
    "content": "import React from 'react';\n\nexport default React.createContext('en');\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/contexts/successContext.js",
    "content": "import React from 'react';\n\nconst successContext = React.createContext();\n\n\n/**\n* @function useSuccess\n* @returns {array} successContext value, which is a state of [value, setter].\n*\n*/\nfunction useSuccess() {\n  const context = React.useContext(successContext);\n\n  if(!context) {\n    throw new Error('useSuccess must be used within a SuccessProvider');\n  }\n\n  return context;\n}\n\n/**\n* @function SuccessProvider\n* @param {object} props - props to pass through from declared component\n* @returns {JSX.Element} Provider component\n*/\nfunction SuccessProvider(props) {\n    const [success, setSuccess] = React.useState(false);\n\n    const value = React.useMemo(() => [success, setSuccess], [success]);\n\n    return <successContext.Provider value={value} {...props} />\n}\n\nexport default { SuccessProvider, useSuccess }\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/contexts/successContext.test.js",
    "content": "import React from 'react';\nimport { shallow, mount } from 'enzyme';\n\nimport successContext from './successContext';\n\n// a functional component that calls useSuccess for our tests\nconst FunctionalComponent = () => {\n  successContext.useSuccess();\n  return <div />;\n}\n\ntest('useSuccess throws error when not wrapped in SuccessProvider', () => {\n  expect(() => {\n    shallow(<FunctionalComponent />);\n  }).toThrow('useSuccess must be used within a SuccessProvider');\n});\n\ntest('useSuccess does not throw error when wrapped in SuccessProvider', () => {\n  expect(() => {\n    mount(\n      <successContext.SuccessProvider>\n        <FunctionalComponent />\n      </successContext.SuccessProvider>\n    )\n  }).not.toThrow();\n})\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/helpers/index.js",
    "content": "/**\n * @method getLetterMatchCount\n * @param {string} guessedWord - Guessed word.\n * @param {string} secretWord - Secret word.\n * @returns {number} - Number of letters matched between guessed word and secret word.\n */\nexport function getLetterMatchCount(guessedWord, secretWord) {\n    const secretLetters = secretWord.split('');\n    const guessedLetterSet = new Set(guessedWord);\n    return secretLetters.filter(letter => guessedLetterSet.has(letter)).length;\n};\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/helpers/index.test.js",
    "content": "import { getLetterMatchCount } from './';\n\ndescribe('getLetterMatchCount', () => {\n  const secretWord = 'party';\n  test('returns correct count when there are no matching letters', () => {\n    const letterMatchCount = getLetterMatchCount('bones', secretWord);\n    expect(letterMatchCount).toBe(0);\n  });\n  test('returns the correct count where there are 3 matching letters', () => {\n    const letterMatchCount = getLetterMatchCount('train', secretWord);\n    expect(letterMatchCount).toBe(3);\n  });\n  test('returns correct count when there are duplicate letters in the guess', () => {\n    const letterMatchCount = getLetterMatchCount('parka', secretWord);\n    expect(letterMatchCount).toBe(3);\n  });\n});\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/helpers/strings.js",
    "content": "const languageStrings = {\n  en: {\n    congrats: 'Congratulations! You guessed the word!',\n    submit: 'Submit',\n    guessPrompt: 'Try to guess the secret word!',\n    guessInputPlaceholder: 'enter guess',\n    guessColumnHeader: 'Guessed Words',\n    // Challenge #1: Number of Guesses\n    numberColumnHeader: '#',\n    totalGuesses: 'Total Guesses',\n    // END: Challenge #1: Number of Guesses\n    guessedWords: 'Guesses',\n    matchingLettersColumnHeader: 'Matching Letters',\n    // Challenge #2: Reset Game\n    newWord: 'New Word',\n    // END: Challenge #2: Reset Game\n    // Challenge #3: Give up\n    giveUp: 'Give Up',\n    secretWordWas: 'The secret word was',\n    betterLuck: 'Better luck next time!',\n    // END: Challenge #3: Give up\n    // Challenge #4: Enter Secret Word\n    enterSecretWord: 'Enter your own secret word',\n    // END: Challenge #4: Enter Secret Word\n    // Challenge #5: Server Error\n    serverError: 'There was an error retrieving the secret word. Please try again later.',\n    // END: Challenge #5: Server Error\n  },\n  emoji: {\n    congrats: '🎯🎉',\n    submit: '🚀',\n    guessPrompt: '🤔🤫🔤',\n    guessInputPlaceholder: '⌨️🤔',\n    guessedWords: '🤷‍🔤',\n    guessColumnHeader: '🤷‍',\n    // Challenge #1: Number of Guesses\n    numberColumnHeader: '🔢',\n    totalGuesses: '🔢🤷‍♀️',\n    // END: Challenge #1: Number of Guesses\n    matchingLettersColumnHeader: '✅',\n    // Challenge #2: Reset Game\n    newWord: '✨🔤',\n    // END: Challenge #2: Reset Game\n    // Challenge #3: Give up\n    giveUp: '😩',\n    secretWordWas: '🤫🔤',\n    betterLuck: '🍀✨🔤',\n    // END: Challenge #3: Give up\n    // Challenge #4: Enter Secret Word\n    enterSecretWord: '👩‍💻🤫🔤',\n    // END: Challenge #4: Enter Secret Word\n    // Challenge #5: Server Error\n    serverError: '🚨. ⏲.',\n    // END: Challenge #5: Server Error\n  }\n}\n\nfunction getStringByLanguage(languageCode, stringKey, strings=languageStrings) {\n  if (!strings[languageCode] || !strings[languageCode][stringKey]) {\n    console.warn(`Could not get string [${stringKey}] for [${languageCode}]`);\n\n    // fall back to english\n    return strings.en[stringKey];\n  }\n\n  return strings[languageCode][stringKey];\n}\n\n// for future mocking\nexport default {\n  getStringByLanguage,\n}\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/helpers/strings.test.js",
    "content": "import stringsModule from './strings';\nconst { getStringByLanguage } = stringsModule;\n\nconst strings = {\n  en: { submit: 'submit' },\n  emoji: { submit: '🚀' },\n  mermish: {},\n}\n\ndescribe('language string testing', () => {\n  const mockWarn = jest.fn();\n  let originalWarn;\n\n  beforeEach(() => {\n    originalWarn = console.warn;\n    console.warn = mockWarn;\n  });\n\n  afterEach(() => {\n    console.warn = originalWarn;\n  });\n\n  test('returns correct submit string for english', () => {\n    const string = getStringByLanguage('en', 'submit', strings);\n    expect(string).toBe('submit');\n    expect(mockWarn).not.toHaveBeenCalled();\n  });\n  test('returns the correct submit string for emoji', () => {\n    const string = getStringByLanguage('emoji', 'submit', strings);\n    expect(string).toBe('🚀');\n    expect(mockWarn).not.toHaveBeenCalled();\n  });\n  test('returns english submit string when language does not exist', () => {\n    const string = getStringByLanguage('notALanguage', 'submit', strings);\n    expect(string).toBe('submit');\n    expect(mockWarn).toHaveBeenCalledWith(\"Could not get string [submit] for [notALanguage]\");\n  });\n  test('returns english submit string when submit key does not exist for language', () => {\n    const string = getStringByLanguage('mermish', 'submit', strings);\n    expect(string).toBe('submit');\n    expect(mockWarn).toHaveBeenCalledWith(\"Could not get string [submit] for [mermish]\");\n  });\n});\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/index.css",
    "content": "body {\n  margin: 0;\n  font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", \"Roboto\", \"Oxygen\",\n    \"Ubuntu\", \"Cantarell\", \"Fira Sans\", \"Droid Sans\", \"Helvetica Neue\",\n    sans-serif;\n  -webkit-font-smoothing: antialiased;\n  -moz-osx-font-smoothing: grayscale;\n}\n\ncode {\n  font-family: source-code-pro, Menlo, Monaco, Consolas, \"Courier New\",\n    monospace;\n}\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/index.js",
    "content": "import React from 'react';\nimport ReactDOM from 'react-dom';\nimport './index.css';\nimport App from './App';\nimport * as serviceWorker from './serviceWorker';\n\nReactDOM.render(<App />, document.getElementById('root'));\n\n// If you want your app to work offline and load faster, you can change\n// unregister() to register() below. Note this comes with some pitfalls.\n// Learn more about service workers: https://bit.ly/CRA-PWA\nserviceWorker.unregister();\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/integration_tests/enter_secret_word.test.js",
    "content": "// Challenge #4: Enter Secret Word\nimport React from 'react';\nimport { mount } from 'enzyme';\n\nimport App from '../App';\nimport { findByTestAttr } from '../../test/testUtils';\nimport hookActions from '../actions/hookActions';\n\n/**\n* Create ReactWrapper for App component for testing.\n* Use `mount` so that all children components are available\n* @returns {ReactWrapper} - Wrapper for App component and providers\n*/\nconst setup = () => {\n  // mock getSecretWord so that it sets the secret word without network calls\n  hookActions.getSecretWord = jest.fn(setSecretWord => setSecretWord('party'));\n  return mount(<App />);\n}\n\ndescribe(\"zero guessed words and Enter Secret Word not clicked\", () => {\n  test('Enter Secret Word button shows', () => {\n    const wrapper = setup();\n    const enterSecretWordButton = findByTestAttr(wrapper, 'component-enter-secret-word-button');\n    expect(enterSecretWordButton.length).toBe(1);\n  });\n  test('Secret word entry does not show', () => {\n    const wrapper = setup();\n    const secretWordEntryComponent = findByTestAttr(wrapper, 'component-secret-word-entry');\n    expect(secretWordEntryComponent.length).toBe(0);\n  });\n});\n\ndescribe(\"enterSecretWord is true\", () => {\n  let wrapper;\n  let giveUpButton;\n  beforeEach(() => {\n    // find and click the \"enter secret word\" button to set enterSecretWord to true\n    wrapper = setup();\n    giveUpButton = findByTestAttr(wrapper, 'component-enter-secret-word-button');\n    giveUpButton.simulate('click');\n  });\n  test('Secret word entry shows', () => {\n    const secretWordEntryComponent = findByTestAttr(wrapper, 'component-secret-word-entry');\n    expect(secretWordEntryComponent.length).toBe(1);\n  });\n  test('no other components show', () => {\n    expect(wrapper.children.length).toBe(1);\n  })\n});\n\n// END: Challenge #4: Enter Secret Word\n\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/integration_tests/giveup.test.js",
    "content": "// Challenge #3: Give Up\nimport React from 'react';\nimport { mount } from 'enzyme';\nimport hookActions from '../actions/hookActions';\n\nimport App from '../App';\nimport { findByTestAttr } from '../../test/testUtils';\n\n/**\n* Create ReactWrapper for App component for testing.\n* Use `mount` so that all children components are available\n* @returns {ReactWrapper} - Wrapper for App component and providers\n*/\nconst setup = () => {\n  // mock getSecretWord so that it sets the secret word without network calls\n  hookActions.getSecretWord = jest.fn(setSecretWord => setSecretWord('party'));\n  return mount(<App />);\n}\n\ndescribe(\"givenUp is false and word not guessed\", () => {\n  // givenUp should be false by default\n  test('Give Up button shows', () => {\n    const wrapper = setup();\n    const giveUpButton = findByTestAttr(wrapper, 'component-give-up-button');\n    expect(giveUpButton.length).toBe(1);\n  });\n  test('secret word is not revealed', () => {\n    const wrapper = setup();\n    const secretWordReveal = findByTestAttr(wrapper, 'component-secret-word-reveal');\n    expect(secretWordReveal.length).toBe(0);\n  });\n  test('Input component shows', () => {\n    const wrapper = setup();\n    const inputComponent = findByTestAttr(wrapper, 'component-input');\n    expect(inputComponent.length).toBe(1);\n  });\n  test('New Word button does not show', () => {\n    const wrapper = setup();\n    const newWordButton = findByTestAttr(wrapper, 'component-new-word-button');\n    expect(newWordButton.text().length).toBe(0);\n  });\n});\n\ndescribe(\"givenUp is true\", () => {\n  let wrapper;\n  let giveUpButton;\n  beforeEach(() => {\n    // find and click the give up button to set givenUp to true\n    wrapper = setup();\n    giveUpButton = findByTestAttr(wrapper, 'component-give-up-button');\n    giveUpButton.simulate('click');\n  });\n  test('Give Up button no longer shows', () => {\n    const giveUpButton = findByTestAttr(wrapper, 'component-give-up-button');\n    expect(giveUpButton.length).toBe(0);\n  });\n  test('secret word is revealed', () => {\n    const secretWordReveal = findByTestAttr(wrapper, 'component-secret-word-reveal');\n    expect(secretWordReveal.length).toBe(1);\n  });\n  test('Input component no longer shows', () => {\n    const inputComponent = findByTestAttr(wrapper, 'component-input');\n    expect(inputComponent.length).toBe(0);\n  });\n  test('New Word button shows', () => {\n    const newWordButton = findByTestAttr(wrapper, 'component-new-word-button');\n    expect(newWordButton.length).toBe(1);\n  });\n  test('Congrats does not show', () => {\n    const congratsComponent = findByTestAttr(wrapper, 'component-congrats');\n    expect(congratsComponent.length).toBe(0);\n\n  })\n});\n\n// END: Challenge #3: Give Up\n\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/integration_tests/guesses.test.js",
    "content": "import React from 'react';\nimport { mount } from 'enzyme';\nimport { findByTestAttr } from '../../test/testUtils';\n\nimport guessedWordsContext from '../contexts/guessedWordsContext';\nimport successContext from '../contexts/successContext';\nimport Input from '../Input';\nimport GuessedWords from '../GuessedWords';\n\nfunction setup(guessedWordsStrings=[], secretWord=\"party\") {\n  const wrapper = mount(\n    <guessedWordsContext.GuessedWordsProvider>\n      <successContext.SuccessProvider>\n        <Input secretWord={secretWord} />\n        <GuessedWords />\n      </successContext.SuccessProvider>\n    </guessedWordsContext.GuessedWordsProvider>\n  );\n\n  const inputBox = findByTestAttr(wrapper, 'input-box');\n  const submitButton = findByTestAttr(wrapper, 'submit-button');\n\n  // prepopulate guessedWords context by simulating word guessedWords\n  guessedWordsStrings.map(word => {\n    const mockEvent = { target: { value: word } };\n    inputBox.simulate(\"change\", mockEvent);\n    submitButton.simulate(\"click\");\n  })\n  return [wrapper, inputBox, submitButton];\n}\n\ndescribe('test word guesses', () => {\n  let wrapper;\n  let inputBox;\n  let submitButton;\n\n  describe('non-empty guessedWords', () => {\n    beforeEach(() => {\n      [wrapper, inputBox, submitButton] = setup([\"agile\"], \"party\");\n    });\n    describe('correct guess', () => {\n      beforeEach(() => {\n        const mockEvent = { target: { value: \"party\" } };\n        inputBox.simulate(\"change\", mockEvent);\n        submitButton.simulate(\"click\");\n      });\n      test(\"Input component contains no children\", () => {\n        const inputComponent = findByTestAttr(wrapper, \"component-input\");\n        expect(inputComponent.children().length).toBe(0);\n      });\n      test('GuessedWords table row count reflects updated guess', () => {\n        const guessedWordsTableRows = findByTestAttr(wrapper, \"guessed-word\");\n        expect(guessedWordsTableRows.length).toBe(2);\n      });\n    });\n    describe('incorrect guess', () => {\n      beforeEach(() => {\n        const mockEvent = { target: { value: \"train\" } };\n        inputBox.simulate(\"change\", mockEvent);\n        submitButton.simulate(\"click\");\n      });\n      test(\"Input box remains\", () => {\n        expect(inputBox.exists()).toBe(true);\n      });\n      test('GuessedWords table row count reflects updated guess', () => {\n        const guessedWordsTableRows = findByTestAttr(wrapper, \"guessed-word\");\n        expect(guessedWordsTableRows.length).toBe(2);\n      });\n    });\n  });\n  describe(\"empty guessWords\", () => {\n    beforeEach(() => {\n      [ wrapper, inputBox, submitButton ] = setup([], \"party\");\n    });\n    test('guessedWords shows correct guesses after incorrect guess', () => {\n      const mockEvent = {target: { value: \"train\" }};\n      inputBox.simulate(\"change\", mockEvent);\n      submitButton.simulate(\"click\");\n      const guessedWordsTableRows = findByTestAttr(wrapper, \"guessed-word\");\n      expect(guessedWordsTableRows.length).toBe(1)\n    });\n  });\n});\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/integration_tests/resetgame.test.js",
    "content": "// Challenge #2: Reset Game\nimport React from 'react';\nimport { mount } from 'enzyme';\nimport hookActions from '../actions/hookActions';\n\nimport App from '../App';\nimport { findByTestAttr } from '../../test/testUtils';\n\n/**\n* Create ReactWrapper for App component for testing.\n* Use `mount` so that all children components are available\n* @returns {ReactWrapper} - Wrapper for App component and providers\n*/\nconst setup = () => {\n  // mock getSecretWord so that it sets the secret word without network calls\n  hookActions.getSecretWord = jest.fn(setSecretWord => setSecretWord('party'));\n  return mount(<App />);\n}\n\ndescribe(\"after New Word button is clicked\", () => {\n  let wrapper;\n  let newWordButton;\n  beforeEach(() => {\n    wrapper = setup();\n    const inputBox = findByTestAttr(wrapper, 'input-box');\n    const submitButton = findByTestAttr(wrapper, 'submit-button');\n        \n    // guess the word to display the New Word button\n    const mockEvent = { target: { value: \"party\" } };\n    inputBox.simulate(\"change\", mockEvent);\n    submitButton.simulate(\"click\");\n    \n    // find and click the New Word button\n    newWordButton = findByTestAttr(wrapper, 'component-new-word-button');\n    newWordButton.simulate('click');\n  });\n  test('New Word Button button no longer shows', () => {\n    const newWordButtonComponent = findByTestAttr(wrapper, 'ccomponent-new-word-button');\n    expect(newWordButtonComponent.length).toBe(0);\n  });\n  test('Congrats component no longer shows', () => {\n    const congratsComponent = findByTestAttr(wrapper, 'component-congrats');\n    expect(congratsComponent.text().length).toBe(0);\n  });\n  test('Input component shows', () => {\n    const inputComponent = findByTestAttr(wrapper, 'component-input');\n    expect(inputComponent.text().length).not.toBe(0);\n  });\n});\n\n// END: Challenge #2: Reset Game\n\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/serviceWorker.js",
    "content": "// This optional code is used to register a service worker.\n// register() is not called by default.\n\n// This lets the app load faster on subsequent visits in production, and gives\n// it offline capabilities. However, it also means that developers (and users)\n// will only see deployed updates on subsequent visits to a page, after all the\n// existing tabs open on the page have been closed, since previously cached\n// resources are updated in the background.\n\n// To learn more about the benefits of this model and instructions on how to\n// opt-in, read https://bit.ly/CRA-PWA\n\nconst isLocalhost = Boolean(\n  window.location.hostname === 'localhost' ||\n    // [::1] is the IPv6 localhost address.\n    window.location.hostname === '[::1]' ||\n    // 127.0.0.1/8 is considered localhost for IPv4.\n    window.location.hostname.match(\n      /^127(?:\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/\n    )\n);\n\nexport function register(config) {\n  if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {\n    // The URL constructor is available in all browsers that support SW.\n    const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);\n    if (publicUrl.origin !== window.location.origin) {\n      // Our service worker won't work if PUBLIC_URL is on a different origin\n      // from what our page is served on. This might happen if a CDN is used to\n      // serve assets; see https://github.com/facebook/create-react-app/issues/2374\n      return;\n    }\n\n    window.addEventListener('load', () => {\n      const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;\n\n      if (isLocalhost) {\n        // This is running on localhost. Let's check if a service worker still exists or not.\n        checkValidServiceWorker(swUrl, config);\n\n        // Add some additional logging to localhost, pointing developers to the\n        // service worker/PWA documentation.\n        navigator.serviceWorker.ready.then(() => {\n          console.log(\n            'This web app is being served cache-first by a service ' +\n              'worker. To learn more, visit https://bit.ly/CRA-PWA'\n          );\n        });\n      } else {\n        // Is not localhost. Just register service worker\n        registerValidSW(swUrl, config);\n      }\n    });\n  }\n}\n\nfunction registerValidSW(swUrl, config) {\n  navigator.serviceWorker\n    .register(swUrl)\n    .then(registration => {\n      registration.onupdatefound = () => {\n        const installingWorker = registration.installing;\n        if (installingWorker == null) {\n          return;\n        }\n        installingWorker.onstatechange = () => {\n          if (installingWorker.state === 'installed') {\n            if (navigator.serviceWorker.controller) {\n              // At this point, the updated precached content has been fetched,\n              // but the previous service worker will still serve the older\n              // content until all client tabs are closed.\n              console.log(\n                'New content is available and will be used when all ' +\n                  'tabs for this page are closed. See https://bit.ly/CRA-PWA.'\n              );\n\n              // Execute callback\n              if (config && config.onUpdate) {\n                config.onUpdate(registration);\n              }\n            } else {\n              // At this point, everything has been precached.\n              // It's the perfect time to display a\n              // \"Content is cached for offline use.\" message.\n              console.log('Content is cached for offline use.');\n\n              // Execute callback\n              if (config && config.onSuccess) {\n                config.onSuccess(registration);\n              }\n            }\n          }\n        };\n      };\n    })\n    .catch(error => {\n      console.error('Error during service worker registration:', error);\n    });\n}\n\nfunction checkValidServiceWorker(swUrl, config) {\n  // Check if the service worker can be found. If it can't reload the page.\n  fetch(swUrl)\n    .then(response => {\n      // Ensure service worker exists, and that we really are getting a JS file.\n      const contentType = response.headers.get('content-type');\n      if (\n        response.status === 404 ||\n        (contentType != null && contentType.indexOf('javascript') === -1)\n      ) {\n        // No service worker found. Probably a different app. Reload the page.\n        navigator.serviceWorker.ready.then(registration => {\n          registration.unregister().then(() => {\n            window.location.reload();\n          });\n        });\n      } else {\n        // Service worker found. Proceed as normal.\n        registerValidSW(swUrl, config);\n      }\n    })\n    .catch(() => {\n      console.log(\n        'No internet connection found. App is running in offline mode.'\n      );\n    });\n}\n\nexport function unregister() {\n  if ('serviceWorker' in navigator) {\n    navigator.serviceWorker.ready.then(registration => {\n      registration.unregister();\n    });\n  }\n}\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/src/setupTests.js",
    "content": "import Enzyme, { shallow } from 'enzyme';\nimport EnzymeAdapter from 'enzyme-adapter-react-16';\n\nEnzyme.configure({\n  adapter: new EnzymeAdapter(),\n});\n"
  },
  {
    "path": "SOLUTIONS for Jotto Context Challenges/test/testUtils.js",
    "content": "import checkPropTypes from 'check-prop-types';\n\n/**\n * Return node(s) with the given data-test attribute.\n * @param {ShallowWrapper} wrapper - Enzyme shallow wrapper.\n * @param {string} val - Value of data-test attribute for search.\n * @returns {ShallowWrapper}\n */\nexport const findByTestAttr = (wrapper, val) => {\n  return wrapper.find(`[data-test=\"${val}\"]`);\n}\n\n/**\n* Throw error if conformingProps do not pass propTypes validation.\n* @param {React.Component} component - Component to check props against.\n* @param {object} conformingProps - Props we expect to conform to defined propTypes.\n*/\nexport const checkProps = (component, conformingProps) => {\n  const propError = checkPropTypes(\n    component.propTypes,\n    conformingProps,\n    'prop',\n    component.name);\n  expect(propError).toBeUndefined();\n}\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/.gitignore",
    "content": "# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.\n\n# dependencies\n/node_modules\n/.pnp\n.pnp.js\n\n# testing\n/coverage\n\n# production\n/build\n\n# misc\n.DS_Store\n.env.local\n.env.development.local\n.env.test.local\n.env.production.local\n\nnpm-debug.log*\nyarn-debug.log*\nyarn-error.log*\n\nconfig.js"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/.npmrc",
    "content": "fund=false\naudit=false\nloglevel=error\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/README.md",
    "content": "# Jotto\n\n### A React app to demonstrate testing\n\n## Challenges\n\n### 1. Number of Guesses\n\n![Number of Guesses Wireframe](https://github.com/bonnie/udemy-ENZYME/tree/master/jotto-mockups/number-of-guesses_wireframe.png)\n\n- _Note_: Try to accomplish this _without_ adding a new piece of state!\n- Add “guess number” column to the \"guessed words\" table\n  - The first guess should show 1, second guess 2, etc.\n- Add a component that displays total guesses as shown in wireframe\n\n### 2. Reset Game\n\n![Reset Game Wireframe](https://github.com/bonnie/udemy-ENZYME/tree/master/jotto-mockups/new-game_wireframe.png)\n\n- Create a “New word” button component\n  - only display after successful guess\n- Upon click, reset the game with a new word from the server\n- _Notes_: This one is going to need access to `setGuessedWords` and `setSuccess` to reset those pieces of state upon click. It can import `getSecretWord` from `actions/hookActions`, but it will need `setSecretWord` from `App.js` to pass as a callback to `getSecretWord`. I recommend passing `setSecretWord` as a prop.\n\nTo test which components show up\nafter clicking the New Word Button, try running `mount` on `App` after you've mocked\n`hookActions.getSecretWord` to run the callback function\nargument with the secretWord value (to avoid making a\nnetwork call when `App` mounts). For example:\n\n```\nhookActions.getSecretWord = jest.fn(setSecretWord => setSecretWord('party'));\n```\n\nThen you can find and click the new word button and test to see the state of various components. You might make a new integration test file for this, or you could keep these tests within NewWordButton.test.js -- your choice.\n\n### 3. “Give up” Button\n\n![Give Up Button Wireframe](https://github.com/bonnie/udemy-ENZYME/tree/master/jotto-mockups/give-up-button_wireframe.png)\n![After Give Up Click Wireframe](https://github.com/bonnie/udemy-ENZYME/tree/master/jotto-mockups/after-give-up_wireframe.png)\n\n- Create a “Give up” button\n  - only display when word has not been guessed correctly\n- Upon click:\n  - Show secret word\n  - Display \"better luck next time\" message\n  - Display “new word” button component\n  - Set `success` context to `true` (the other components should display as though `success` is true; that is, no Input and show New Word button. The exception is Congrats of course!)\n- _Note_: This one is quite involved! One way to approach it: Update\n  the `App` component to have `givenUp` as part of its state,\n  and then display components depending on the values of\n  `givenUp` and `success`.\n  You will also need to\n  update the `NewWordButton` onClick to reset `givenUp`.\n\n  You can use the same method to check on components after click as you did with Challenge #2.\n\n### 4. User inputs secret word\n\n![Enter Secret Word Button Wireframe](https://github.com/bonnie/udemy-ENZYME/tree/master/jotto-mockups/enter-secret-word_wireframe.png)  \n ![Secret Word Entry Form Wireframe](https://github.com/bonnie/udemy-ENZYME/tree/master/jotto-mockups/secret-word-entry-form_wireframe.png)\n\n- Add a button for the user to input the secret word\n  - This way, the user can play against a friend\n- After submission, the game should use the user’s secret word, not a word from the server\n- This button should disapppear once the user has nonzero `guessedWords`\n\n- _Note: The entry form is another chance to practice with a state-controlled field._\n\n### 5. Random Word Server Error\n\n![Random Word Server Error Wireframe](https://github.com/bonnie/udemy-ENZYME/tree/master/jotto-mockups/random-word-server-error_wireframe.png)\n\n- Display an error if:\n  - There’s a problem contacting the “random word” server\n  - The server responds with status 4xx or 5xx\n\n## Credits\n\nThis project was bootstrapped with [Create React App](https://github.com/facebookincubator/create-react-app).\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/package.json",
    "content": "{\n  \"name\": \"jotto\",\n  \"version\": \"0.1.0\",\n  \"private\": true,\n  \"dependencies\": {\n    \"@testing-library/jest-dom\": \"^5.11.9\",\n    \"@testing-library/react\": \"^11.2.5\",\n    \"@testing-library/user-event\": \"^12.8.3\",\n    \"axios\": \"^0.21.1\",\n    \"react\": \"^17.0.1\",\n    \"react-dom\": \"^17.0.1\",\n    \"react-redux\": \"^7.2.2\",\n    \"react-scripts\": \"4.0.3\",\n    \"redux\": \"^4.0.5\",\n    \"redux-thunk\": \"^2.3.0\",\n    \"web-vitals\": \"^1.1.0\"\n  },\n  \"scripts\": {\n    \"start\": \"react-scripts start\",\n    \"build\": \"react-scripts build\",\n    \"test\": \"react-scripts test\",\n    \"eject\": \"react-scripts eject\"\n  },\n  \"eslintConfig\": {\n    \"extends\": [\n      \"react-app\",\n      \"react-app/jest\"\n    ]\n  },\n  \"browserslist\": {\n    \"production\": [\n      \">0.2%\",\n      \"not dead\",\n      \"not op_mini all\"\n    ],\n    \"development\": [\n      \"last 1 chrome version\",\n      \"last 1 firefox version\",\n      \"last 1 safari version\"\n    ]\n  },\n  \"devDependencies\": {\n    \"@wojtekmaj/enzyme-adapter-react-17\": \"^0.4.1\",\n    \"check-prop-types\": \"^1.1.2\",\n    \"enzyme\": \"^3.11.0\",\n    \"moxios\": \"^0.4.0\"\n  },\n  \"jest\": {\n    \"resetMocks\": false\n  }\n}\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/public/index.html",
    "content": "<!DOCTYPE html>\n<html lang=\"en\">\n  <head>\n    <meta charset=\"utf-8\" />\n    <link rel=\"icon\" href=\"%PUBLIC_URL%/favicon.ico\" />\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n    <meta name=\"theme-color\" content=\"#000000\" />\n    <meta\n      name=\"description\"\n      content=\"Web site created using create-react-app\"\n    />\n    <link rel=\"apple-touch-icon\" href=\"%PUBLIC_URL%/logo192.png\" />\n    <!--\n      manifest.json provides metadata used when your web app is installed on a\n      user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/\n    -->\n    <link rel=\"manifest\" href=\"%PUBLIC_URL%/manifest.json\" />\n    <!--\n      Notice the use of %PUBLIC_URL% in the tags above.\n      It will be replaced with the URL of the `public` folder during the build.\n      Only files inside the `public` folder can be referenced from the HTML.\n\n      Unlike \"/favicon.ico\" or \"favicon.ico\", \"%PUBLIC_URL%/favicon.ico\" will\n      work correctly both with client-side routing and a non-root public URL.\n      Learn how to configure a non-root public URL by running `npm run build`.\n    -->\n    <link href=\"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css\" rel=\"stylesheet\" integrity=\"sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T\" crossorigin=\"anonymous\">\n    <script src=\"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js\" integrity=\"sha384-xrRywqdh3PHs8keKZN+8zzc5TX0GRTLCcmivcbNJWm2rs5C8PRhcEn3czEjhAO9o\" crossorigin=\"anonymous\"></script>\n    <title>React App</title>\n  </head>\n  <body>\n    <noscript>You need to enable JavaScript to run this app.</noscript>\n    <div id=\"root\"></div>\n    <!--\n      This HTML file is a template.\n      If you open it directly in the browser, you will see an empty page.\n\n      You can add webfonts, meta tags, or analytics to this file.\n      The build step will place the bundled scripts into the <body> tag.\n\n      To begin the development, run `npm start` or `yarn start`.\n      To create a production bundle, use `npm run build` or `yarn build`.\n    -->\n  </body>\n</html>\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/public/manifest.json",
    "content": "{\n  \"short_name\": \"React App\",\n  \"name\": \"Create React App Sample\",\n  \"icons\": [\n    {\n      \"src\": \"favicon.ico\",\n      \"sizes\": \"64x64 32x32 24x24 16x16\",\n      \"type\": \"image/x-icon\"\n    },\n    {\n      \"src\": \"logo192.png\",\n      \"type\": \"image/png\",\n      \"sizes\": \"192x192\"\n    },\n    {\n      \"src\": \"logo512.png\",\n      \"type\": \"image/png\",\n      \"sizes\": \"512x512\"\n    }\n  ],\n  \"start_url\": \".\",\n  \"display\": \"standalone\",\n  \"theme_color\": \"#000000\",\n  \"background_color\": \"#ffffff\"\n}\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/public/robots.txt",
    "content": "# https://www.robotstxt.org/robotstxt.html\nUser-agent: *\nDisallow:\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/App.css",
    "content": ".App {\n  text-align: center;\n}\n\n.App-logo {\n  height: 40vmin;\n  pointer-events: none;\n}\n\n@media (prefers-reduced-motion: no-preference) {\n  .App-logo {\n    animation: App-logo-spin infinite 20s linear;\n  }\n}\n\n.App-header {\n  background-color: #282c34;\n  min-height: 100vh;\n  display: flex;\n  flex-direction: column;\n  align-items: center;\n  justify-content: center;\n  font-size: calc(10px + 2vmin);\n  color: white;\n}\n\n.App-link {\n  color: #61dafb;\n}\n\n@keyframes App-logo-spin {\n  from {\n    transform: rotate(0deg);\n  }\n  to {\n    transform: rotate(360deg);\n  }\n}\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/App.js",
    "content": "import { useEffect } from \"react\";\nimport { useSelector, useDispatch } from \"react-redux\";\nimport \"./App.css\";\n\n// Challenge #1: Number of Guesses\nimport TotalGuesses from \"./TotalGuesses\";\n// END: Challenge #1: Number of Guesses\n\n// Challenge #2: Reset Game\nimport NewWordButton from \"./NewWordButton\";\n// END: Challenge #2: Reset Game\n\n// Challenge #3: Give up\nimport SecretWordReveal from \"./SecretWordReveal\";\n// END: Challenge #3: Give up\n\n// Challenge #4: Enter Secret Word\nimport EnterWordButton from \"./EnterWordButton\";\nimport EnterWordForm from \"./EnterWordForm\";\n// END: Challenge #4: Enter Secret Word\n\n// Challenge #2: Reset Game\nimport ServerError from \"./ServerError\";\n// END: Challenge #2: Reset Game\n\nimport Congrats from \"./Congrats\";\nimport GuessedWords from \"./GuessedWords\";\nimport Input from \"./Input\";\n\nimport {\n  getSecretWord,\n  // Challenge #2\n  resetGame,\n  // END: Challenge #2\n\n  // Challenge #4\n  setUserSecretWord,\n  setUserEntering,\n  // END: Challenge #2\n} from \"./actions\";\n\nfunction App() {\n  const success = useSelector((state) => state.success);\n  const guessedWords = useSelector((state) => state.guessedWords);\n  const secretWord = useSelector((state) => state.secretWord);\n\n  // Challenge #3\n  const gaveUp = useSelector((state) => state.gaveUp);\n  // END: Challenge #3\n\n  // Challenge #4\n  const userEnter = useSelector((state) => state.userEnter);\n  // END: Challenge #4\n\n  // Challenge #5\n  const serverError = useSelector((state) => state.serverError);\n  // END: Challenge #5\n\n  // so that we can dispatch an action\n  const dispatch = useDispatch();\n\n  useEffect(() => {\n    // get the secret word\n    dispatch(getSecretWord());\n  }, []);\n\n  // Challenge #4: Enter Secret Word\n  let contents;\n  // Challenge #5: Server Error\n  if (serverError) {\n    contents = <ServerError />;\n    // END: Challenge #5: Server Error\n  } else if (userEnter === \"inProgress\") {\n    contents = (\n      <EnterWordForm formAction={(word) => dispatch(setUserSecretWord(word))} />\n    );\n  } else {\n    contents = (\n      <div>\n        <Congrats success={success} />\n\n        {/* Challenge #3: Give Up Button */}\n        <SecretWordReveal display={gaveUp} secretWord={secretWord} />\n        {/* END: Challenge #3: Give Up Button */}\n\n        {/* Challenge #2 and #3 */}\n        <NewWordButton\n          display={success || gaveUp}\n          resetAction={() => dispatch(resetGame())}\n        />\n        {/* END: Challenge #2 and #3 */}\n\n        <Input />\n        <GuessedWords guessedWords={guessedWords} />\n\n        {/* Challenge #1: Number of guesses */}\n        <TotalGuesses guessCount={guessedWords.length} />\n        {/* END: Challenge #1: Number of guesses */}\n\n        {/* Challenge #4: Enter Secret Word */}\n        <EnterWordButton\n          display={guessedWords.length === 0}\n          buttonAction={() => dispatch(setUserEntering())}\n        />\n        {/* END: Challenge #4: Enter Secret Word */}\n      </div>\n    );\n  }\n  return (\n    <div data-test=\"component-app\" className=\"container\">\n      <h1>Jotto</h1>\n      {contents}\n    </div>\n  );\n  // END: Challenge #4: Enter Secret Word\n}\n\nexport default App;\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/App.test.js",
    "content": "import React from \"react\";\nimport { mount } from \"enzyme\";\nimport { Provider } from \"react-redux\";\n\nimport { findByTestAttr, storeFactory } from \"../test/testUtils\";\nimport App from \"./App\";\n\n// activate global mock to make sure getSecretWord doesn't make network call\njest.mock(\"./actions\");\nimport { getSecretWord as mockGetSecretWord } from \"./actions\";\n\n/**\n * Setup function for App component\n * @returns {Wrapper}\n */\nconst setup = () => {\n  const store = storeFactory();\n  return mount(\n    <Provider store={store}>\n      <App />\n    </Provider>\n  );\n};\n\ntest(\"renders without error\", () => {\n  const wrapper = setup();\n  const appComponent = findByTestAttr(wrapper, \"component-app\");\n  expect(appComponent).toHaveLength(1);\n});\n\ndescribe(\"get secret word\", () => {\n  beforeEach(() => {\n    mockGetSecretWord.mockClear();\n  });\n  test(\"getSecretWord runs on app mount\", () => {\n    const wrapper = setup();\n    expect(mockGetSecretWord).toHaveBeenCalledTimes(1);\n  });\n  test(\"getSecretWord does not run on app update\", () => {\n    const wrapper = setup();\n    mockGetSecretWord.mockClear();\n\n    // using setProps because wrapper.update() doesn't trigger useEffect\n    // https://github.com/enzymejs/enzyme/issues/2254\n    wrapper.setProps();\n\n    expect(mockGetSecretWord).toHaveBeenCalledTimes(0);\n  });\n});\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/Congrats.js",
    "content": "import React from 'react';\nimport PropTypes from 'prop-types';\n\n/**\n * Functional react component for congratulatory message.\n * @function\n * @param {object} props - React props.\n * @returns {JSX.Element} - Rendered component (or null if `success` prop is false).\n */\nconst Congrats = (props) => {\n  if (props.success) {\n    return (\n      <div data-test=\"component-congrats\" className=\"alert alert-success\">\n        <span data-test=\"congrats-message\">\n          Congratulations! You guessed the word!\n        </span>\n      </div>\n    );\n  } else {\n    return (\n      <div data-test=\"component-congrats\" />\n    );\n  }\n};\n\nCongrats.propTypes = {\n  success: PropTypes.bool.isRequired,\n};\n\nexport default Congrats;\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/Congrats.test.js",
    "content": "import React from 'react';\nimport { shallow } from 'enzyme';\n\nimport { findByTestAttr, checkProps } from '../test/testUtils';\nimport Congrats from './Congrats';\n\nconst defaultProps = { success: false };\n\n/**\n* Factory function to create a ShallowWrapper for the Congrats component.\n* @function setup\n* @param {object} props - Component props specific to this setup.\n* @returns {ShallowWrapper}\n*/\nconst setup = (props={}) => {\n  const setupProps = { ...defaultProps, ...props };\n  return shallow(<Congrats {...setupProps} />)\n}\n\ntest('renders without error', () => {\n  const wrapper = setup();\n  const component = findByTestAttr(wrapper, 'component-congrats');\n  expect(component.length).toBe(1);\n});\ntest('renders no text when `success` prop is false', () => {\n  const wrapper = setup({ success: false });\n  const component = findByTestAttr(wrapper, 'component-congrats');\n  expect(component.text()).toBe('');\n});\ntest('renders non-empty congrats message when `success` prop is true', () => {\n  const wrapper = setup({ success: true });\n  const message = findByTestAttr(wrapper, 'congrats-message');\n  expect(message.text().length).not.toBe(0);\n});\ntest('does not throw warning with expected props', () => {\n  const expectedProps = { success: false };\n  checkProps(Congrats, expectedProps);\n});\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/EnterWordButton.js",
    "content": "// Challenge #4: Enter Secret Word\nimport React from \"react\";\nimport PropTypes from \"prop-types\";\n\nconst EnterWordButton = (props) => {\n  if (props.display) {\n    return (\n      <button\n        data-test=\"component-enter-word-button\"\n        className=\"btn btn-primary spacer-bottom\"\n        onClick={props.buttonAction}\n      >\n        Enter your own secret word\n      </button>\n    );\n  } else {\n    return <div data-test=\"component-enter-word-button\" />;\n  }\n};\n\nEnterWordButton.propTypes = {\n  display: PropTypes.bool.isRequired,\n  buttonAction: PropTypes.func,\n};\n\nexport default EnterWordButton;\n\n// END: Challenge #4: Enter Secret Word\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/EnterWordButton.test.js",
    "content": "// Challenge #4: Enter Secret Word\nimport React from 'react';\nimport { shallow } from 'enzyme';\n\nimport { findByTestAttr, checkProps } from '../test/testUtils';\nimport EnterWordButton from './EnterWordButton';\n\nconst defaultProps = { display: true };\n\n/**\n* Factory function to create a ShallowWrapper for the EnterWordButton component.\n* @function setup\n* @param {object} props - Component props specific to this setup.\n* @returns {ShallowWrapper}\n*/\nconst setup = (props={}) => {\n  const setupProps = { ...defaultProps, ...props };\n  return shallow(<EnterWordButton {...setupProps} />)\n}\n\ndescribe('render', () => {\n\n  test('renders without error', () => {\n    const wrapper = setup();\n    const component = findByTestAttr(wrapper, 'component-enter-word-button');\n    expect(component.length).toBe(1);\n  });\n  test('renders no text when `display` prop is false', () => {\n    const wrapper = setup({ display: false });\n    const component = findByTestAttr(wrapper, 'component-enter-word-button');\n    expect(component.text()).toBe('');\n  });\n  test('renders non-empty text when `display` prop is true', () => {\n    const wrapper = setup({ display: true, buttonAction: () => {} });\n    const component = findByTestAttr(wrapper, 'component-enter-word-button');\n    expect(component.text().length).not.toBe(0);\n  });\n  test('does not throw warning with expected props', () => {\n    const expectedProps = { display: false };\n    checkProps(EnterWordButton, expectedProps);\n  });\n});\ntest('calls `buttonAction` prop upon button click', () => {\n  // create a mock function so we can see whether it's called on click\n  const buttonActionMock = jest.fn();\n  const wrapper = setup({ display: true, buttonAction: buttonActionMock });\n\n  // find the button (which is the top level element of this component)\n  const resetButton = findByTestAttr(wrapper, 'component-enter-word-button');\n  resetButton.simulate('click');\n\n  // expect the mock to have been called once\n  expect(buttonActionMock.mock.calls.length).toBe(1);\n});\n// END: Challenge #4: Enter Secret Word\n\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/EnterWordForm.js",
    "content": "// Challenge #4: Enter Secret Word\nimport React, { useState } from \"react\";\nimport PropTypes from \"prop-types\";\n\nexport const EnterWordForm = ({ formAction }) => {\n  const [secretWord, setSecretWord] = useState(\"\");\n\n  const submitForm = (evt) => {\n    evt.preventDefault();\n    // don't submit empty word\n    if (secretWord.length > 0) {\n      formAction(secretWord);\n    }\n  };\n\n  return (\n    <div data-test=\"component-enter-word-form\">\n      <p data-test=\"enter-word-instructions\">\n        Enter a secret word for someone else to guess!\n      </p>\n      <form className=\"form-inline\">\n        <input\n          data-test=\"enter-word-input\"\n          className=\"mb-2 mx-sm-3\"\n          type=\"text\"\n          value={secretWord}\n          onChange={(evt) => setSecretWord(evt.target.value)}\n          placeholder=\"enter secret word\"\n        />\n        <button\n          data-test=\"submit-button\"\n          onClick={submitForm}\n          className=\"btn btn-primary mb-2\"\n          type=\"submit\"\n        >\n          Submit\n        </button>\n      </form>\n    </div>\n  );\n};\n\nEnterWordForm.propTypes = {\n  formAction: PropTypes.func,\n};\n\nexport default EnterWordForm;\n// END: Challenge #4: Enter Secret Word\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/EnterWordForm.test.js",
    "content": "// Challenge #4: Enter Secret Word\nimport React from \"react\";\nimport { shallow } from \"enzyme\";\n\nimport { findByTestAttr, checkProps } from \"../test/testUtils\";\nimport EnterWordForm from \"./EnterWordForm\";\n\nconst defaultProps = { formAction: () => {} };\n\n/**\n * Factory function to create a ShallowWrapper for the EnterWordForm component.\n * @function setup\n * @param {object} props - Component props specific to this setup.\n * @returns {ShallowWrapper}\n */\nconst setup = (props = {}) => {\n  const setupProps = { ...defaultProps, ...props };\n  return shallow(<EnterWordForm {...setupProps} />);\n};\ndescribe(\"render\", () => {\n  // the condition for this to render is within the App\n  // component, so we don't need to test conditional rendering here\n  test(\"renders without error\", () => {\n    const wrapper = setup();\n    const component = findByTestAttr(wrapper, \"component-enter-word-form\");\n    expect(component.length).toBe(1);\n  });\n  test(\"renders instructions\", () => {\n    const wrapper = setup();\n    const instructions = findByTestAttr(wrapper, \"enter-word-instructions\");\n    expect(instructions.length).toBe(1);\n  });\n  test(\"renders submit button\", () => {\n    const wrapper = setup();\n    const submit = findByTestAttr(wrapper, \"submit-button\");\n    expect(submit.length).toBe(1);\n  });\n  test(\"renders input box\", () => {\n    const wrapper = setup();\n    const input = findByTestAttr(wrapper, \"enter-word-input\");\n    expect(input.length).toBe(1);\n  });\n  test(\"does not throw warning with expected props\", () => {\n    const expectedProps = { formAction: () => {} };\n    checkProps(EnterWordForm, expectedProps);\n  });\n});\n\ndescribe(\"submit click action\", () => {\n  let setUserSecretWordMock;\n  let wrapper;\n  const userSecretWord = \"lunch\";\n  beforeEach(() => {\n    // create a mock function for `setUserSecretWord`\n    setUserSecretWordMock = jest.fn();\n\n    // set up Input, with setUserSecretWordMock as a prop\n    wrapper = setup({ formAction: setUserSecretWordMock });\n\n    // simulate the input\n    const mockEvent = { target: { value: userSecretWord } };\n    const inputBox = findByTestAttr(wrapper, \"enter-word-input\");\n    inputBox.simulate(\"change\", mockEvent);\n\n    // simulate click on submit button\n    const submit = findByTestAttr(wrapper, \"submit-button\");\n    submit.simulate(\"click\", { preventDefault() {} });\n  });\n  test(\"`setUserSecretWord` was called once\", () => {\n    const setUserSecretWordCallCount = setUserSecretWordMock.mock.calls.length;\n    expect(setUserSecretWordCallCount).toBe(1);\n  });\n  test(\"`setUserSecretWord` was called with input value as argument\", () => {\n    const userSecretWordArg = setUserSecretWordMock.mock.calls[0][0];\n    expect(userSecretWordArg).toBe(userSecretWord);\n  });\n});\n\n// END: Challenge #4: Enter Secret Word\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/GuessedWords.js",
    "content": "import React from 'react';\nimport PropTypes from 'prop-types';\n\nconst GuessedWords = (props) => {\n  let contents\n  if (props.guessedWords.length === 0) {\n    contents = (\n      <span data-test=\"guess-instructions\">\n        Try to guess the secret word!\n      </span>\n    );\n  } else {\n    const guessedWordsRows = props.guessedWords.map((word, index) => (\n      <tr data-test=\"guessed-word\" key={ index }>\n        {/* Challenge #1: Number of Guesses */}\n        <td data-test=\"guessed-word-index\">{ index + 1 }</td>\n        {/* END: Challenge #1: Number of Guesses */}\n        <td>{ word.guessedWord }</td>\n        <td>{ word.letterMatchCount }</td>\n      </tr>\n    ));\n    contents = (\n      <div data-test=\"guessed-words\">\n        <h3>Guessed Words</h3>\n        <table className=\"table table-sm\">\n          <thead className=\"thead-light\">\n            <tr>\n              {/* Challenge #1: Number of Guesses */}\n              <th>#</th>\n              {/* Challenge #1: Number of Guesses */}\n              <th>Guess</th>\n              <th>Matching Letters</th>\n            </tr>\n          </thead>\n          <tbody>\n            { guessedWordsRows }\n          </tbody>\n        </table>\n      </div>\n    );\n  }\n  return (\n    <div data-test=\"component-guessed-words\">\n      { contents }\n    </div>\n  );\n};\n\nGuessedWords.propTypes = {\n  guessedWords: PropTypes.arrayOf(\n    PropTypes.shape({\n      guessedWord: PropTypes.string.isRequired,\n      letterMatchCount: PropTypes.number.isRequired,\n    })\n  ).isRequired,\n};\n\nexport default GuessedWords;\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/GuessedWords.test.js",
    "content": "import React from 'react';\nimport { shallow } from 'enzyme';\nimport { findByTestAttr, checkProps } from '../test/testUtils';\nimport GuessedWords from './GuessedWords';\n\nconst defaultProps = {\n  guessedWords: [{ guessedWord: 'train', letterMatchCount: 3 }],\n};\n\n/**\n* Factory function to create a ShallowWrapper for the GuessedWords component.\n* @function setup\n* @param {object} props - Component props specific to this setup.\n* @returns {ShallowWrapper}\n*/\nconst setup = (props={}) => {\n  const setupProps = { ...defaultProps, ...props };\n  return shallow(<GuessedWords {...setupProps } />)\n};\n\ntest('does not throw warning with expected props', () => {\n  checkProps(GuessedWords, defaultProps);\n});\n\ndescribe('if there are no words guessed', () => {\n  let wrapper\n  beforeEach(() => {\n    wrapper = setup({ guessedWords: [] });\n  });\n  test('renders without error', () => {\n    const component = findByTestAttr(wrapper, 'component-guessed-words');\n    expect(component.length).toBe(1);\n  });\n  test('renders instructions to guess a word', () => {\n    const instructions = findByTestAttr(wrapper, 'guess-instructions');\n    expect(instructions.text().length).not.toBe(0);\n  });\n});\ndescribe('if there are words guessed', () => {\n  let wrapper;\n  const guessedWords = [\n    { guessedWord: 'train', letterMatchCount: 3 },\n    { guessedWord: 'agile', letterMatchCount: 1 },\n    { guessedWord: 'party', letterMatchCount: 5 },\n  ];\n  beforeEach(() => {\n    wrapper = setup({ guessedWords });\n  });\n  test ('renders without error', () => {\n    const component = findByTestAttr(wrapper, 'component-guessed-words');\n    expect(component.length).toBe(1);\n  });\n  test('renders \"guessed words\" section', () => {\n    const guessedWordsNode = findByTestAttr(wrapper, 'guessed-words');\n    expect(guessedWordsNode.length).toBe(1);\n  });\n  test('correct number of guessed words', () => {\n    const guessedWordNodes = findByTestAttr(wrapper, 'guessed-word');\n    expect(guessedWordNodes.length).toBe(guessedWords.length);\n  });\n  // Challenge #1: Number of Guesses\n  test('includes guess word index for each word', () => {\n    const guessWordIndexes = findByTestAttr(wrapper, 'guessed-word-index');\n    const indexTextSet = new Set(guessWordIndexes.map(wrapper => wrapper.text()));\n    const expectedSet = new Set(guessedWords.map((word, index) => (index + 1).toString()));\n    expect(indexTextSet).toEqual(expectedSet);\n  });\n  // END: Challenge #1: Number of Guesses\n});\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/Input.js",
    "content": "import React from \"react\";\nimport PropTypes from \"prop-types\";\nimport { useSelector, useDispatch } from \"react-redux\";\n\n// Challenge #3: Give Up Button\nimport { guessWord, giveUp } from \"./actions\";\n// END: Challenge #3: Give Up Button\nfunction Input({ secretWord }) {\n  const [currentGuess, setCurrentGuess] = React.useState(\"\");\n  const dispatch = useDispatch();\n  const success = useSelector((state) => state.success);\n\n  // Challenge #3: Give up\n  const gaveUp = useSelector((state) => state.gaveUp);\n\n  if (success || gaveUp) {\n    // END: Challenge #3: Give up\n    return <div data-test=\"component-input\" />;\n  }\n\n  return (\n    <div data-test=\"component-input\">\n      <form className=\"form-inline\">\n        <input\n          data-test=\"input-box\"\n          className=\"mb-2 mx-sm-3\"\n          type=\"text\"\n          placeholder=\"enter guess\"\n          value={currentGuess}\n          onChange={(event) => setCurrentGuess(event.target.value)}\n        />\n        <button\n          data-test=\"submit-button\"\n          onClick={(evt) => {\n            evt.preventDefault();\n            dispatch(guessWord(currentGuess));\n            setCurrentGuess(\"\");\n          }}\n          className=\"btn btn-primary mb-2\"\n        >\n          Submit\n        </button>\n        {/* Challenge #3: Give Up Button */}\n        <button\n          data-test=\"give-up-button\"\n          onClick={(evt) => {\n            evt.preventDefault();\n            dispatch(giveUp());\n          }}\n          className=\"btn btn-danger mb-2\"\n        >\n          Give up\n        </button>\n        {/* END: Challenge #3: Give Up Button */}\n      </form>\n    </div>\n  );\n}\n\nInput.propTypes = {\n  secretWord: PropTypes.string.isRequired,\n};\n\nexport default Input;\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/Input.test.js",
    "content": "import React from 'react';\nimport { mount } from 'enzyme';\nimport { findByTestAttr, checkProps, storeFactory } from '../test/testUtils';\nimport { Provider } from 'react-redux';\n\nimport Input from './Input';\n\n// mock entire module for destructuring useState on import //////\n// const mockSetCurrentGuess = jest.fn();\n// jest.mock('react', () => ({\n//   ...jest.requireActual('react'),\n//   useState: (initialState) => [initialState, mockSetCurrentGuess]\n// }))\n\nconst setup = (initialState={}, secretWord='party') => {\n  const store = storeFactory(initialState);\n  return mount(<Provider store={store}><Input secretWord={secretWord} /></Provider>);\n}\n\ndescribe('render', () => {\n  describe('success is false', () => {\n    let wrapper;\n    beforeEach(() => {\n      wrapper = setup({ success: false });\n    })\n    test('Input renders without error', () => {\n      const inputComponent = findByTestAttr(wrapper, 'component-input');\n      expect(inputComponent.length).toBe(1);\n    });\n    test('input box displays', () => {\n      const inputBox = findByTestAttr(wrapper, 'input-box');\n      expect(inputBox.exists()).toBe(true);\n    });\n    test('submit button displays', () => {\n      const submitButton = findByTestAttr(wrapper, 'submit-button');\n      expect(submitButton.exists()).toBe(true);\n    });\n  });\n  describe('success is true', () => {\n    let wrapper;\n    beforeEach(() => {\n      wrapper = setup({ success: true });\n    })\n    test('Input renders without error', () => {\n      const inputComponent = findByTestAttr(wrapper, 'component-input');\n      expect(inputComponent.length).toBe(1);\n    });\n    test('input box does not display', () => {\n      const inputBox = findByTestAttr(wrapper, 'input-box');\n      expect(inputBox.exists()).toBe(false);\n    });\n    test('submit button does not display', () => {\n      const submitButton = findByTestAttr(wrapper, 'submit-button');\n      expect(submitButton.exists()).toBe(false);\n    });\n  });\n});\n\ntest('does not throw warning with expected props', () => {\n  checkProps(Input, { secretWord: 'party' });\n})\n\ndescribe('state controlled input field', () => {\n  let mockSetCurrentGuess = jest.fn();\n  let wrapper;\n\n  beforeEach(() => {\n    mockSetCurrentGuess.mockClear();\n    React.useState = () => [\"\", mockSetCurrentGuess];\n    wrapper = setup({ success: false });\n  });\n  test('state updates with value of input box upon change', () => {\n    const inputBox = findByTestAttr(wrapper, 'input-box');\n    const mockEvent = { target: { value: 'train' } };\n\n    inputBox.simulate(\"change\", mockEvent);\n    expect(mockSetCurrentGuess).toHaveBeenCalledWith('train');\n  });\n  test('field is cleared upon submit button click', () => {\n    const inputBox = findByTestAttr(wrapper, 'input-box');\n    const mockEvent = { target: { value: 'train' } };\n\n    inputBox.simulate(\"change\", mockEvent);\n    expect(mockSetCurrentGuess).toHaveBeenCalledWith('train');\n  });\n})\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/NewWordButton.js",
    "content": "// Challenge #2: Reset Game\n\nimport React from 'react';\nimport PropTypes from 'prop-types';\n\n/**\n * Functional react component for reset button.\n * @function\n * @param {object} props - React props.\n * @returns {JSX.Element} - Rendered component (or null if `success` prop is false).\n */\nconst NewWordButton = (props) => {\n  if (props.display) {\n    return (\n      <button \n        data-test=\"component-new-word-button\" \n        className=\"btn btn-primary spacer-bottom\"\n        onClick={props.resetAction}>\n        New word\n      </button>\n    );\n  } else {\n    return (\n      <div data-test=\"component-new-word-button\" />\n    );\n  }\n};\n\nNewWordButton.propTypes = {\n  display: PropTypes.bool.isRequired,\n  resetAction: PropTypes.func,\n};\n\nexport default NewWordButton;\n\n// END: Challenge #2: Reset Game\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/NewWordButton.test.js",
    "content": "// Challenge #2: Reset Game\n\nimport React from 'react';\nimport { shallow } from 'enzyme';\n\nimport { findByTestAttr, checkProps } from '../test/testUtils';\nimport NewWordButton from './NewWordButton';\n\nconst defaultProps = { display: false };\n\n/**\n* Factory function to create a ShallowWrapper for the NewWordButton component.\n* @function setup\n* @param {object} props - Component props specific to this setup.\n* @returns {ShallowWrapper}\n*/\nconst setup = (props={}) => {\n  const setupProps = { ...defaultProps, ...props };\n  return shallow(<NewWordButton {...setupProps} />);\n}\n\ndescribe('render', () => {\n  test('renders without error', () => {\n    const wrapper = setup();\n    const component = findByTestAttr(wrapper, 'component-new-word-button');\n    expect(component.length).toBe(1);\n  });\n  test('renders no text when `display` prop is false', () => {\n    const wrapper = setup({ display: false });\n    const component = findByTestAttr(wrapper, 'component-new-word-button');\n    expect(component.text()).toBe('');\n  });\n  test('renders non-empty text when `display` prop is true', () => {\n    const wrapper = setup({ display: true, resetAction: () => {} });\n    const component = findByTestAttr(wrapper, 'component-new-word-button');\n    expect(component.text().length).not.toBe(0);\n  });\n});\ntest('does not throw warning with expected props', () => {\n  const expectedProps = { display: false, resetAction: () => {} };\n  checkProps(NewWordButton, expectedProps);\n});\ntest('calls `resetAction` prop upon button click', () => {\n  // create a mock function so we can see whether it's called on click\n  const resetActionMock = jest.fn();\n  const wrapper = setup({ display: true, resetAction: resetActionMock });\n\n  // find the button (which is the top level element of this component)\n  const resetButton = findByTestAttr(wrapper, 'component-new-word-button');\n  resetButton.simulate('click');\n\n  // expect the mock to have been called once\n  expect(resetActionMock.mock.calls.length).toBe(1);\n});\n\n// END: Challenge #2: Reset Game\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/SecretWordReveal.js",
    "content": "// Challenge #3: Give Up Button\nimport React from \"react\";\nimport PropTypes from \"prop-types\";\n\n/**\n * Functional react component for \"you gave up\" message.\n * @function\n * @param {object} props - React props.\n * @returns {JSX.Element} - Rendered component (or null if `display` prop is false).\n */\nconst SecretWordReveal = ({ display, secretWord }) => {\n  if (display) {\n    return (\n      <div\n        data-test=\"component-secret-word-reveal\"\n        className=\"alert alert-danger\"\n      >\n        <span data-test=\"reveal-message\">\n          The secret word was \"{secretWord}\"<br />\n          Better luck next time!\n        </span>\n      </div>\n    );\n  } else {\n    return <div data-test=\"component-secret-word-reveal\" />;\n  }\n};\n\nSecretWordReveal.propTypes = {\n  display: PropTypes.bool.isRequired,\n  // not \"isRequired\" because it's *not* required if display is false\n  secretWord: PropTypes.string,\n};\n\nexport default SecretWordReveal;\n\n// END: Challenge #3: Give Up Button\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/SecretWordReveal.test.js",
    "content": "// Challenge #3: Give Up Button\n\nimport React from \"react\";\nimport { shallow } from \"enzyme\";\n\nimport { findByTestAttr, checkProps } from \"../test/testUtils\";\nimport SecretWordReveal from \"./SecretWordReveal\";\n\nconst secretWord = \"party\";\nconst defaultProps = { display: false, secretWord };\n\n/**\n * Factory function to create a ShallowWrapper for the SecretWordReveal component.\n * @function setup\n * @param {object} props - Component props specific to this setup.\n * @returns {ShallowWrapper}\n */\nconst setup = (props = {}) => {\n  const setupProps = { ...defaultProps, ...props };\n  return shallow(<SecretWordReveal {...setupProps} />);\n};\n\ntest(\"renders without error\", () => {\n  const wrapper = setup();\n  const component = findByTestAttr(wrapper, \"component-secret-word-reveal\");\n  expect(component.length).toBe(1);\n});\ntest(\"renders no text when `display` prop is false\", () => {\n  const wrapper = setup({ display: false });\n  const component = findByTestAttr(wrapper, \"component-secret-word-reveal\");\n  expect(component.text()).toBe(\"\");\n});\ntest(\"renders message containing secret word when `display` prop is true\", () => {\n  const wrapper = setup({ display: true });\n  const message = findByTestAttr(wrapper, \"reveal-message\");\n  expect(message.text()).toContain(secretWord);\n});\ntest(\"does not throw warning with expected props\", () => {\n  const expectedProps = { display: false, secretWord };\n  checkProps(SecretWordReveal, expectedProps);\n});\n\n// END: Challenge #3: Give Up Button\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/ServerError.js",
    "content": "// Challenge #5: Server Error\nimport React from 'react';\n\nexport default (props) => {\n  return (\n    <div data-test=\"component-server-error\" className=\"alert alert-danger\">\n      There was an error retrieving the secret word. Please try again later.\n    </div>\n  )\n}\n// END: Challenge #5: Server Error"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/ServerError.test.js",
    "content": "// Challenge #5: Server Error\nimport React from 'react';\nimport { shallow } from 'enzyme';\n\nimport { findByTestAttr } from '../test/testUtils';\nimport ServerError from './ServerError';\n\n// no need for setup function here: no props or state\n\ntest('renders without error', () => {\n  const wrapper = shallow(<ServerError />);\n  const component = findByTestAttr(wrapper, 'component-server-error');\n  expect(component.length).toBe(1);\n});\ntest('renders non-empty text', () => {\n  const wrapper = shallow(<ServerError />);\n  const component = findByTestAttr(wrapper, 'component-server-error');\n  expect(component.text().length).not.toBe(0);\n});\n\n// END: Challenge #5: Server Error"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/TotalGuesses.js",
    "content": "// Challenge #1: Number of Guesses\n\nimport React from 'react';\nimport PropTypes from 'prop-types';\n\n/**\n * Functional react component for count of total guesses.\n * @function\n * @param {object} props - React props.\n * @returns {JSX.Element} - Rendered component.\n */\nconst TotalGuesses = (props) => {\n  return (\n    <h4 data-test=\"component-total-guesses\">\n      Total Guesses: {props.guessCount}\n    </h4>\n  );\n};\n\nTotalGuesses.propTypes = {\n  guessCount: PropTypes.number.isRequired,\n};\n\nexport default TotalGuesses;\n\n// END: Challenge #1: Number of Guesses\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/TotalGuesses.test.js",
    "content": "// Challenge #1: Number of Guesses\n\nimport React from 'react';\nimport { shallow } from 'enzyme';\n\nimport { findByTestAttr, checkProps } from '../test/testUtils';\nimport TotalGuesses from './TotalGuesses';\n\nconst defaultProps = { guessCount: 0 };\n\n/**\n* Factory function to create a ShallowWrapper for the TotalGuesses component.\n* @function setup\n* @param {object} props - Component props specific to this setup.\n* @returns {ShallowWrapper}\n*/\nconst setup = (props={}) => {\n  const setupProps = { ...defaultProps, ...props };\n  return shallow(<TotalGuesses {...setupProps} />)\n}\n\ntest('renders without error', () => {\n  const wrapper = setup();\n  const component = findByTestAttr(wrapper, 'component-total-guesses');\n  expect(component.length).toBe(1);\n});\ntest('renders the number of guesses', () => {\n  const guessCount = 8;\n  const wrapper = setup({ guessCount });\n  const component = findByTestAttr(wrapper, 'component-total-guesses');\n  expect(component.text()).toContain(guessCount.toString());\n});\n\n// END: Challenge #1: Number of Guesses\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/actions/__mocks__/index.js",
    "content": "module.exports = {\n  ...jest.requireActual(\"..\"),\n  __esModule: true,\n  getSecretWord: jest.fn().mockReturnValue({ type: \"mock\" }),\n};\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/actions/index.js",
    "content": "import axios from \"axios\";\n\nimport { getLetterMatchCount } from \"../helpers\";\nimport { wordnikKey } from \"../config.js\";\n\nexport const WORDNIK_URL = `https://api.wordnik.com/v4/words.json/randomWord?hasDictionaryDef=true&minLength=5&maxLength=5&api_key=${wordnikKey}`;\n\nexport const actionTypes = {\n  CORRECT_GUESS: \"CORRECT_GUESS\",\n  GUESS_WORD: \"GUESS_WORD\",\n  SET_SECRET_WORD: \"SET_SECRET_WORD\",\n  RESET_GAME: \"RESET_GAME\",\n  GIVE_UP: \"GIVE_UP\",\n  USER_ENTERING: \"USER_ENTERING\",\n  USER_ENTERED: \"USER_ENTERED\",\n  SERVER_ERROR: \"SERVER_ERROR\",\n};\n\n/**\n * Returns Redux Thunk function that dispatches GUESS_WORD action\n *     and (conditionally) CORRECT_GUESS action\n * @function guessWord\n * @param {string} guessedWord - Guessed word.\n * @returns {function} - Redux Thunk function.\n */\nexport const guessWord = (guessedWord) => {\n  return function (dispatch, getState) {\n    const secretWord = getState().secretWord;\n    const letterMatchCount = getLetterMatchCount(guessedWord, secretWord);\n\n    dispatch({\n      type: actionTypes.GUESS_WORD,\n      payload: { guessedWord, letterMatchCount },\n    });\n\n    if (guessedWord === secretWord) {\n      dispatch({ type: actionTypes.CORRECT_GUESS });\n    }\n  };\n};\n\n// Challenge #2: Reset Game\n/**\n * Dispatch axios action to get secret word from random word server.\n * Separate this out so it can be used in getSecretWord and resetGame.\n * @function getSecretWordDispatch\n * @param {dispatch} dispatch - Redux Thunk dispatch.\n *\n */\nconst getSecretWordDispatch = (dispatch) => {\n  return (\n    axios\n      .get(\"http://localhost:3030\")\n      .then((response) => {\n        dispatch({\n          type: actionTypes.SET_SECRET_WORD,\n          payload: response.data,\n        });\n      })\n      // Challenge #5: Server Error\n      // note: axios rejects promise if status is 4xx or 5xx\n      .catch((error) => {\n        dispatch({ type: actionTypes.SERVER_ERROR });\n      })\n  );\n  // END: Challenge #5: Server Error\n};\n\n// Challenge #6: Wordnik\n/**\n * Dispatch axios action to get secret word from Wordnik.\n * Separate this out so it can be used in getSecretWord and resetGame.\n * @function getSecretWordWordnikDispatch\n * @param {dispatch} dispatch - Redux Thunk dispatch.\n *\n */\nconst getSecretWordWordnikDispatch = (dispatch) => {\n  return axios\n    .get(WORDNIK_URL)\n    .then((response) => {\n      dispatch({\n        type: actionTypes.SET_SECRET_WORD,\n        // NOTE: to be true to the rules of jotto here,\n        // we would reject any word with duplicate letters\n        // and try again. However, my commitment to Jotto is\n        // not that strong right now. :p\n        payload: response.data.word,\n      });\n    })\n    .catch((error) => {\n      console.log(\"------>ERROR!\", error);\n      dispatch({ type: actionTypes.SERVER_ERROR });\n    });\n};\n// END: Challenge #6: Wordnik\n\n/**\n * Returns Redux Thunk function that dispatches GET_SECRET_WORD action\n *     after axios promise resolves\n * @function getSecretWord\n * @returns {function} - Redux Thunk function.\n */\nexport const getSecretWord = () => {\n  return getSecretWordWordnikDispatch; // Challenge #6: Wordnik\n};\n\n/**\n * Action creator to reset game and get a new secret word.\n * @function resetGame\n * @returns {function} - Redux Thunk function that dispatches RESET_GAME action and calls getSecretWord().\n */\nexport const resetGame = () => {\n  return (dispatch) => {\n    dispatch({ type: actionTypes.RESET_GAME });\n    return getSecretWordWordnikDispatch(dispatch); // Challenge #6: Wordnik\n  };\n};\n// END: Challenge #2: Reset Game\n\n// Challenge #3: Give Up Button\n/**\n * Simple action creator that returns GIVE_UP action type.\n * @function giveUp\n * @returns {object} - GIVE_UP action type.\n */\nexport const giveUp = () => {\n  return { type: actionTypes.GIVE_UP };\n};\n// END: Challenge #3: Give Up Button\n\n// Challenge #4: Enter Secret Word\n/**\n * Action creator to dispatch USER_ENTERED and SET_SECRET_WORD actions.\n * @function setUserSecretWord\n * @param {string} userSecretWord - Secret word entered by user.\n * @returns {function} - Redux Thunk function.\n */\nexport const setUserSecretWord = (userSecretWord) => {\n  return (dispatch) => {\n    dispatch({ type: actionTypes.SET_SECRET_WORD, payload: userSecretWord });\n    dispatch({ type: actionTypes.USER_ENTERED });\n  };\n};\n\n/**\n * Action creator that returns USER_ENTERING action type.\n * @function setUserEntering\n * @returns {object} - Action with type USER_ENTERING.\n */\nexport const setUserEntering = () => ({ type: actionTypes.USER_ENTERING });\n\n// END: Challenge #4: Enter Secret Word\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/actions/index.test.js",
    "content": "import moxios from 'moxios';\n\nimport { storeFactory } from '../../test/testUtils';\nimport { getSecretWord } from './';\n\ndescribe('getSecretWord action creator', () => {\n  beforeEach(() => {\n    moxios.install();\n  });\n  afterEach(() => {\n    moxios.uninstall();\n  });\n  test('adds response word to state', () => {\n    const secretWord = 'party';\n    const store = storeFactory();\n\n    moxios.wait(() => {\n      const request = moxios.requests.mostRecent();\n      request.respondWith({\n        status: 200,\n\n        // Challenge #6: Wordnik\n        // NOTE: this is the only thing in the tests that needs to change\n        // since the shape of the response is different from wordnik\n        // Otherwise, the tests simply work!\n        response: { word: secretWord },\n        // END: Challenge #6: Wordnik\n      });\n    });\n\n    return store.dispatch(getSecretWord())\n      .then(() => {\n        const newState = store.getState();\n        expect(newState.secretWord).toBe(secretWord);\n      })\n  });\n  describe('updates serverError state to `true`', () => {\n    // NOTE: there's currently no way to simulate server nonresponse with moxios\n    test('when server returns 4xx status', () => {\n      const store = storeFactory();\n\n      moxios.wait(() => {\n        const request = moxios.requests.mostRecent();\n        request.respondWith({\n          status: 404,\n        });\n      });\n  \n      return store.dispatch(getSecretWord())\n        .then(() => {\n          const newState = store.getState();\n          expect(newState.serverError).toBe(true);\n        })\n    });\n    test('when server returns 5xx status', () => {\n      const store = storeFactory();\n\n      moxios.wait(() => {\n        const request = moxios.requests.mostRecent();\n        request.respondWith({\n          status: 500,\n        });\n      });\n  \n      return store.dispatch(getSecretWord())\n        .then(() => {\n          const newState = store.getState();\n          expect(newState.serverError).toBe(true);\n        });\n    });\n  })\n});\n\n\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/config.js.template",
    "content": "module.exports = {\n    wordnikKey: \"YOUR_WORDNIK_KEY_HERE\",\n}"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/configureStore.js",
    "content": "import { createStore, applyMiddleware } from 'redux';\nimport ReduxThunk from 'redux-thunk';\nimport rootReducer from './reducers';\n\nexport const middlewares = [ReduxThunk];\n\nexport default createStore(rootReducer, {}, applyMiddleware(...middlewares));\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/guessWord.test.js",
    "content": "import React from 'react';\nimport { mount } from 'enzyme';\nimport { Provider } from 'react-redux';\n\nimport App from './App';\nimport { findByTestAttr, storeFactory } from '../test/testUtils.js';\n\n// activate global mock to make sure getSecretWord doesn't make network call\njest.mock('./actions');\n\n/**\n * Create wrapper with specified initial conditions,\n * then submit a guessed word of 'train'\n # @function\n *\n * @param {object} state - Initial conditions.\n * @returns {Wrapper} - Enzyme wrapper of mounted App component\n */\nconst setup = (initialState = {}) => {\n  const store = storeFactory(initialState)\n  const wrapper = mount(<Provider store={store}><App /></Provider>);\n\n  // add value to input box\n  const inputBox = findByTestAttr(wrapper, 'input-box');\n  inputBox.simulate('change', { target: { value: 'train' } });\n\n  // simulate click on submit button\n  const submitButton = findByTestAttr(wrapper, 'submit-button');\n  submitButton.simulate('click', { preventDefault() {} });\n\n  return wrapper;\n}\n\ndescribe('no words guessed', () => {\n  let wrapper;\n  beforeEach(() => {\n    wrapper = setup({\n      secretWord: 'party',\n      success: false,\n      guessedWords: []\n    });\n  });\n  test('creates GuessedWords table with one row', () => {\n    const guessedWordRows = findByTestAttr(wrapper, 'guessed-word');\n    expect(guessedWordRows).toHaveLength(1);\n  });\n});\n\ndescribe('some words guessed', () => {\n  let wrapper;\n  beforeEach(() => {\n  \twrapper = setup({\n    \tsecretWord: 'party',\n    \tsuccess: false,\n    \tguessedWords: [{ guessedWord: 'agile', letterMatchCount: 1 }],\n  \t});\n  });\n  test('adds row to guessedWords table', () => {\n    const guessedWordNodes = findByTestAttr(wrapper, 'guessed-word');\n    expect(guessedWordNodes).toHaveLength(2);\n  });\n});\n\ndescribe('guess secret word', () => {\n  let wrapper;\n  beforeEach(() => {\n  \twrapper = setup({\n    \tsecretWord: 'party',\n    \tsuccess: false,\n    \tguessedWords: [{ guessedWord: 'agile', letterMatchCount: 1 }],\n  \t});\n\n    // add value to input box\n    const inputBox = findByTestAttr(wrapper, 'input-box');\n    const mockEvent = { target: { value: 'party' } };\n    inputBox.simulate('change', mockEvent);\n\n  \t// simulate click on submit button\n  \tconst submitButton = findByTestAttr(wrapper, 'submit-button');\n  \tsubmitButton.simulate('click', { preventDefault() {} });\n  });\n  test('adds row to guessedWords table', () => {\n  \tconst guessedWordNodes = findByTestAttr(wrapper, 'guessed-word');\n  \texpect(guessedWordNodes).toHaveLength(3);\n  });\n  test('displays congrats component', () => {\n  \tconst congrats = findByTestAttr(wrapper, 'component-congrats');\n  \texpect(congrats.text().length).toBeGreaterThan(0);\n  });\n  test('does not display input component contents', () => {\n    const inputBox = findByTestAttr(wrapper, \"input-box\");\n    expect(inputBox.exists()).toBe(false);\n\n    const submitButton = findByTestAttr(wrapper, \"submit-button\");\n    expect(submitButton.exists()).toBe(false);\n  });\n});\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/helpers/index.js",
    "content": "/**\n * @method getLetterMatchCount\n * @param {string} guessedWord - Guessed word.\n * @param {string} secretWord - Secret word.\n * @returns {number} - Number of letters matched between guessed word and secret word.\n */\n export function getLetterMatchCount(guessedWord, secretWord) {\n   const secretLetters = secretWord.split('');\n   const guessedLetterSet = new Set(guessedWord);\n   return secretLetters.filter(letter => guessedLetterSet.has(letter)).length;\n };\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/helpers/index.test.js",
    "content": "import { getLetterMatchCount } from './';\n\ndescribe('getLetterMatchCount', () => {\n  const secretWord = 'party';\n  test('returns correct count when there are no matching letters', () => {\n    const letterMatchCount = getLetterMatchCount('bones', secretWord);\n    expect(letterMatchCount).toBe(0);\n  });\n  test('returns the correct count when there are three matching letters', () => {\n    const letterMatchCount = getLetterMatchCount('train', secretWord);\n    expect(letterMatchCount).toBe(3);\n  });\n  test('returns the correct count when there are duplicate letters in the guess', () => {\n    const letterMatchCount = getLetterMatchCount('parka', secretWord);\n    expect(letterMatchCount).toBe(3);\n  });\n});\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/index.css",
    "content": "body {\n  margin: 0;\n  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',\n    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',\n    sans-serif;\n  -webkit-font-smoothing: antialiased;\n  -moz-osx-font-smoothing: grayscale;\n}\n\ncode {\n  font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',\n    monospace;\n}\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/index.js",
    "content": "import React from 'react';\nimport ReactDOM from 'react-dom';\nimport { Provider } from 'react-redux';\n\nimport './index.css';\nimport App from './App';\nimport store from './configureStore';\nimport reportWebVitals from './reportWebVitals';\n\nReactDOM.render(\n  <React.StrictMode>\n    <Provider store={store}>\n      <App />\n    </Provider>\n  </React.StrictMode>,\n  document.getElementById('root')\n);\n\n// If you want to start measuring performance in your app, pass a function\n// to log results (for example: reportWebVitals(console.log))\n// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals\nreportWebVitals();\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/integration.test.js",
    "content": "import { storeFactory } from '../test/testUtils';\nimport { guessWord } from './actions';\nimport { setUserSecretWord } from './actions';\n\n/* Challenge #3 NOTE: \n   It's a sign that these tests weren't optimally designed that we had to\n   `giveUp: false` to every `expectedState`. How would you refactor the tests to\n   be more robust when adding new pieces of state? \n*/\n\ndescribe('guessWord action dispatcher', () => {\n  const secretWord = 'party';\n  const unsuccessfulGuess = 'train';\n  describe('no guessed words', () => {\n    let store;\n    const initialState = { secretWord };\n    beforeEach(() => {\n      store = storeFactory(initialState);\n    });\n    test('updates state correctly for unsuccessful guess', () => {\n      store.dispatch(guessWord(unsuccessfulGuess));\n      const newState = store.getState()\n      const expectedState = {\n        ...initialState,\n        success: false,\n        // Challenge #3, 4 and 5\n        gaveUp: false,\n        userEnter: null,\n        serverError: false,\n        // END: Challenge #3, 4 and 5\n        guessedWords: [{\n          guessedWord: unsuccessfulGuess,\n          letterMatchCount: 3\n        }]\n      };\n      expect(newState).toEqual(expectedState);\n    });\n    test('updates state correctly for successful guess', () => {\n      store.dispatch(guessWord(secretWord));\n      const newState = store.getState()\n      const expectedState = {\n        secretWord,\n        success: true,\n        // Challenge #3, 4 and 5\n        gaveUp: false,\n        userEnter: null,\n        serverError: false,\n        // END: Challenge #3, 4 and 5\n        guessedWords: [{\n          guessedWord: secretWord,\n          letterMatchCount: 5,\n        }],\n      };\n      expect(newState).toEqual(expectedState);\n    });\n  });\n  describe('some guessed words', () => {\n    const guessedWords = [ { guessedWord: 'agile', letterMatchCount: 1 } ];\n    const initialState = { guessedWords, secretWord }\n    let store;\n    beforeEach(() => {\n      store = storeFactory(initialState);\n    })\n    test('updates state correctly for unsuccessful guess', () => {\n      store.dispatch(guessWord(unsuccessfulGuess));\n      const newState = store.getState();\n      const expectedState = {\n        secretWord,\n        success: false,\n        // Challenge #3, 4 and 5\n        gaveUp: false,\n        userEnter: null,\n        serverError: false,\n        // END: Challenge #3, 4 and 5\n        guessedWords: [...guessedWords, { guessedWord: unsuccessfulGuess, letterMatchCount: 3 }]\n      };\n      expect(newState).toEqual(expectedState);\n    });\n    test('updates state correctly for successful guess', () => {\n      store.dispatch(guessWord(secretWord));\n      const newState = store.getState();\n      const expectedState = {\n        secretWord,\n        success: true,\n        // Challenge #3, 4 and 5\n        gaveUp: false,\n        userEnter: null,\n        serverError: false,\n        // END: Challenge #3, 4 and 5\n        guessedWords: [...guessedWords,\n          { guessedWord: secretWord, letterMatchCount: 5 }]\n      };\n      expect(newState).toEqual(expectedState);\n    });\n  });\n});\n\n// Challenge #4: Enter Secret Word\ndescribe('setUserSecretWord action dispatcher', () => {\n  // this is in the integration test section because it\n  // involves the setUserSecretWord action creator and two reducers\n  let store;\n  let newState;\n  \n  // this represents the word the user entered\n  const userSecretWord = 'lunch';\n\n  // this represents the word we got from the server\n  const initialState = { secretWord: 'party' };\n\n  // here I will run the action in the beforeEach, and\n  // check on each relevant piece of state separately\n  beforeEach(() => {\n    store = storeFactory(initialState);\n    store.dispatch(setUserSecretWord(userSecretWord));\n    newState = store.getState();\n  });\n\n  test('updates `secretWord` state correctly after entered word', () => {\n    expect(newState.secretWord).toBe(userSecretWord);\n  });\n  test('updates `userEnter` state correctly after entered word', () => {\n    expect(newState.userEnter).toBe('done');\n  });\n});\n// END: Challenge #4: Enter Secret Word"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/reducers/gaveUpReducer.js",
    "content": "// Challenge #3: Give Up Button\n\n/* NOTE: This is not the optimal way to track whether or not the user has given up. \n With two boolean pieces of state (success aveUp), we have four possibilities:\n \n success=false aveUp=false (user is playing the game)\n success=true aveUp=false (user gave up)\n success=false aveUp=true (user guessed correctly)\n success=true aveUp=true (will never logically happen)\n\n If I were starting from scratch, I would have one piece of state, called, say, 'status'\n with three possibilities: inProgress, victory, gaveUp\n\n To refactor to that new scheme now would make this challenge solution more \n confusing than necessary, however, so we'll live with the inefficiency.\n*/\n\nimport { actionTypes } from '../actions';\n\n/**\n * @function gaveUp\n * @param {boolean} state - Whether the user has given up.\n * @param {object} action - Action to be reduced.\n * @returns {boolean} - aveUp state.\n */\nexport default (state=false, action) => {\n  switch(action.type) {\n    case (actionTypes.GIVE_UP):\n      return true;\n    case (actionTypes.RESET_GAME):\n      return false;\n    default:\n      return state;\n  }\n}\n\n// END: Challenge #3: Give Up Button"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/reducers/gaveUpReducer.test.js",
    "content": "// Challenge #3: Give Up Button\nimport { actionTypes } from '../actions';\nimport gaveUpReducer from './gaveUpReducer';\n\ntest('returns default initial state of `false` when no action is passed', () => {\n  const newState = gaveUpReducer(undefined, {});\n  expect(newState).toBe(false);\n});\ntest('returns state of true upon receiving an action of type `GIVE_UP`', () => {\n  const newState = gaveUpReducer(false, { type: actionTypes.GIVE_UP });\n  expect(newState).toBe(true);\n});\n\ntest('returns state of false upon receiving an action of type `RESET_GAME`', () => {\n  // start with giveUp true, since giveUp is false by default\n  const newState = gaveUpReducer(true, { type: actionTypes.RESET_GAME });\n  expect(newState).toBe(false);\n});\n\n// END: Challenge #3: Give Up Button"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/reducers/guessedWordsReducer.js",
    "content": "import { actionTypes } from \"../actions\";\n\n/**\n * @function guessedWordsReducer\n * @param {array} state - Array of guessed words.\n * @param {object} action - action to be reduced.\n * @returns {array} - new guessedWords state.\n */\nexport default (state = [], action) => {\n  switch (action.type) {\n    case actionTypes.GUESS_WORD:\n      return [...state, action.payload];\n    case actionTypes.RESET_GAME:\n      return [];\n    default:\n      return state;\n  }\n};\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/reducers/index.js",
    "content": "import { combineReducers } from 'redux';\nimport success from './successReducer';\nimport guessedWords from './guessedWordsReducer';\nimport secretWord from './secretWordReducer';\nimport userEnter from './userEnterReducer';\n\n// Challenge #3: Give Up Button\nimport gaveUp from './gaveUpReducer';\n// END: Challenge #3: Give Up Button\n\n// Challenge #5: Server Error\nimport serverError from './serverErrorReducer';\n// END: Challenge #5: Server Error\n\n\nexport default combineReducers({\n  success,\n  guessedWords,\n  secretWord,\n  // Challenge #3: Give Up Button\n  gaveUp,\n  // END: Challenge #3: Give Up Button\n  // Challenge #4: Enter Secret Word\n  userEnter,\n  // END: Challenge #4: Enter Secret Word\n  // Challenge 5: Server Error\n  serverError,\n  // END: Challenge #5: Server Error\n});\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/reducers/secretWordReducer.js",
    "content": "import { actionTypes } from '../actions';\n\n/**\n * @function secretWordReducer\n * @param {string} state - State before reducer.\n * @param {object} action - Action sent to reducer.\n * @returns {string} - New state (secret word payload from action).\n */\nexport default (state='', action) => {\n  switch(action.type) {\n    case actionTypes.SET_SECRET_WORD:\n      return action.payload\n    default:\n      return state;\n  }\n}\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/reducers/serverErrorReducer.js",
    "content": "// Challenge #5: Server Error\nimport { actionTypes } from '../actions';\n\n/**\n * @function serverErrorReducer\n * @param {string} state - State before reducer.\n * @param {object} action - Action sent to reducer.\n * @returns {string} - New state (depending on action type).\n */\nexport default (state=false, action) => {\n  switch (action.type) {\n    case actionTypes.SERVER_ERROR:\n      return true;\n    default:\n      return state;\n  }\n}\n// END: Challenge #5: Server Error\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/reducers/serverErrorReducer.test.js",
    "content": "// Challenge #5: Server Error\nimport { actionTypes } from '../actions';\nimport serverErrorReducer from './serverErrorReducer';\n\ntest('returns default initial state of `false` when no action is passed', () => {\n  const newState = serverErrorReducer(undefined, {});\n  expect(newState).toBe(false);\n});\ntest('returns state of `true` upon receiving an action of type `SERVER_ERROR`', () => {\n  const newState = serverErrorReducer(undefined, { type: actionTypes.SERVER_ERROR });\n  expect(newState).toBe(true);\n});\n// END: Challenge #5: Server Error"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/reducers/successReducer.js",
    "content": "import { actionTypes } from \"../actions\";\n\n/**\n * @function successReducer\n * @param {boolean} state - previous state.\n * @param {object} action - action to be reduced.\n * @returns {boolean} - new success state.\n */\nexport default (state = false, action) => {\n  switch (action.type) {\n    case actionTypes.CORRECT_GUESS:\n      return true;\n    case actionTypes.RESET_GAME:\n      return false;\n    default:\n      return state;\n  }\n};\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/reducers/successReducer.test.js",
    "content": "import { actionTypes } from '../actions';\nimport successReducer from './successReducer';\n\ntest('when previous state is undefined, return false', () => {\n  const newState = successReducer(undefined, {});\n  expect(newState).toBe(false);\n});\n\ntest('return previous state when unknown action type', () => {\n  const newState = successReducer(false, { type: 'unknown' });\n  expect(newState).toBe(false);\n});\n\ntest('return `true` for action type CORRECT_GUESS', () => {\n  const newState = successReducer(false, { type: actionTypes.CORRECT_GUESS });\n  expect(newState).toBe(true);\n});\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/reducers/userEnterReducer.js",
    "content": "// Challenge #4: Enter Secret Word\nimport { actionTypes } from '../actions';\n\n/**\n * @function userEnterReducer\n * @param {string} state - State before reducer.\n * @param {object} action - Action sent to reducer.\n * @returns {string} - New state (depending on action type).\n */\nexport default (state=null, action) => {\n  switch (action.type) {\n    case actionTypes.USER_ENTERING:\n      return 'inProgress';\n    case actionTypes.USER_ENTERED:\n      return 'done';\n    case actionTypes.RESET_GAME:\n      return null;\n    default:\n      return state;\n  }\n}\n// END: Challenge #4: Enter Secret Word\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/reducers/userEnterReducer.test.js",
    "content": "// Challenge #4: Enter Secret Word\nimport { actionTypes } from '../actions';\nimport userEnterReducer from './userEnterReducer';\n\ntest('returns default initial state of `null` when no action is passed', () => {\n  const newState = userEnterReducer(undefined, {});\n  expect(newState).toBeNull();\n});\ntest('returns state of \"inProgress\" upon receiving an action of type `USER_ENTERING`', () => {\n  const newState = userEnterReducer(undefined, { type: actionTypes.USER_ENTERING });\n  expect(newState).toBe('inProgress');\n});\ntest('returns state of \"done\" upon receiving an action of type `USER_ENTERED`', () => {\n  // state is most likely to be 'inProgress' at this point\n  const newState = userEnterReducer('inProgress', { type: actionTypes.USER_ENTERED });\n  expect(newState).toBe('done');\n});\ntest('returns state of `null` upon receiving an action of type `RESET_GAME`', () => {\n  // state is most likely to be 'done' at this point\n  const newState = userEnterReducer('done', { type: actionTypes.RESET_GAME });\n  expect(newState).toBeNull();\n});\n// END: Challenge #4: Enter Secret Word\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/reportWebVitals.js",
    "content": "const reportWebVitals = onPerfEntry => {\n  if (onPerfEntry && onPerfEntry instanceof Function) {\n    import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {\n      getCLS(onPerfEntry);\n      getFID(onPerfEntry);\n      getFCP(onPerfEntry);\n      getLCP(onPerfEntry);\n      getTTFB(onPerfEntry);\n    });\n  }\n};\n\nexport default reportWebVitals;\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/src/setupTests.js",
    "content": "import Enzyme from 'enzyme';\nimport EnzymeAdapter from '@wojtekmaj/enzyme-adapter-react-17';\n\nEnzyme.configure({ adapter: new EnzymeAdapter() });\n"
  },
  {
    "path": "SOLUTIONS for Jotto Redux Hooks Challenges/test/testUtils.js",
    "content": "import checkPropTypes from 'check-prop-types';\nimport { createStore, applyMiddleware } from 'redux';\n\nimport rootReducer from '../src/reducers';\nimport { middlewares } from '../src/configureStore';\n\n/**\n * Create a testing store with imported reducers, middleware, and initial state.\n *  globals: rootReducer.\n * @param {object} initialState - Initial state for store.\n * @function storeFactory\n * @returns {Store} - Redux store.\n */\nexport const storeFactory = (initialState) => {\n  return createStore(rootReducer, initialState, applyMiddleware(...middlewares));\n}\n\n\n/**\n * Return node(s) with the given data-test attribute.\n * @param {ShallowWrapper} wrapper - Enzyme shallow wrapper.\n * @param {string} val - Value of data-test attribute for search.\n * @returns {ShallowWrapper}\n */\nexport const findByTestAttr = (wrapper, val) => {\n  return wrapper.find(`[data-test=\"${val}\"]`);\n}\n\n\n/**\n * Assert that expected conforming props conform to propTypes definiton.\n * @param {React.Component} component - React component.\n * @param {object} conformingProps - Object of conforming props.\n * @returns {undefined} - Throws error if props do not conform.\n */\nexport const checkProps = (component, conformingProps) => {\n  const propError = checkPropTypes(\n    component.propTypes,\n    conformingProps,\n    'prop',\n    component.name);\n  expect(propError).toBeUndefined();\n}\n"
  },
  {
    "path": "click-counter/.gitignore",
    "content": "# See https://help.github.com/ignore-files/ for more about ignoring files.\n\n# dependencies\n/node_modules\n\n# testing\n/coverage\n\n# production\n/build\n\n# misc\n.DS_Store\n.env.local\n.env.development.local\n.env.test.local\n.env.production.local\n\nnpm-debug.log*\nyarn-debug.log*\nyarn-error.log*\n"
  },
  {
    "path": "click-counter/.npmrc",
    "content": "fund=false\naudit=false\nloglevel=error\n"
  },
  {
    "path": "click-counter/README.md",
    "content": "# Click Counter\n### A very basic app to demonstrate React TDD\n\n## Branches\n\n*  `master`\n\n  This branch represents the project at the end of the instructional videos, without any of the challenges completed.\n\n* `click-counter-challenges`\n\n  This branch contains solutions to the challenges. You can also find challenge solutions in the [SOLUTIONS for Click Counter Challenges](https://github.com/flyrightsister/udemy-react-testing-projects/tree/master/SOLUTIONS%20for%20Click%20Counter%20Challenges) folder.\n\n## Challenges\n\n#### 1. Decrement button\n  * Create a new button that subtracts 1 from the counter\n  * Add functionality that decrements the counter when the new button is clicked.\n\n#### 2. No count below 0\n  * Don't let the counter go below zero.\n  * if the counter is at 0 and the decrement button is clicked:\n    * don't decrement the counter\n    * display an error message saying the counter can't go below zero\n\n#### 3. Remove error when increment button is clicked\n  * If error is showing and increment button is clicked, clear the error.\n\n## Credits\nThis project was bootstrapped with [Create React App](https://github.com/facebookincubator/create-react-app).\n"
  },
  {
    "path": "click-counter/package.json",
    "content": "{\n  \"name\": \"click-counter-functional\",\n  \"version\": \"0.1.0\",\n  \"private\": true,\n  \"dependencies\": {\n    \"@testing-library/jest-dom\": \"^4.2.4\",\n    \"@testing-library/react\": \"^9.5.0\",\n    \"@testing-library/user-event\": \"^7.2.1\",\n    \"enzyme\": \"^3.11.0\",\n    \"enzyme-adapter-react-16\": \"^1.15.2\",\n    \"jest-enzyme\": \"^7.1.2\",\n    \"react\": \"^16.13.1\",\n    \"react-dom\": \"^16.13.1\",\n    \"react-scripts\": \"3.4.1\"\n  },\n  \"scripts\": {\n    \"start\": \"react-scripts start\",\n    \"build\": \"react-scripts build\",\n    \"test\": \"react-scripts test\",\n    \"eject\": \"react-scripts eject\"\n  },\n  \"eslintConfig\": {\n    \"extends\": \"react-app\"\n  },\n  \"browserslist\": {\n    \"production\": [\n      \">0.2%\",\n      \"not dead\",\n      \"not op_mini all\"\n    ],\n    \"development\": [\n      \"last 1 chrome version\",\n      \"last 1 firefox version\",\n      \"last 1 safari version\"\n    ]\n  }\n}\n"
  },
  {
    "path": "click-counter/public/index.html",
    "content": "<!DOCTYPE html>\n<html lang=\"en\">\n  <head>\n    <meta charset=\"utf-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\">\n    <meta name=\"theme-color\" content=\"#000000\">\n    <!--\n      manifest.json provides metadata used when your web app is added to the\n      homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/\n    -->\n    <link rel=\"manifest\" href=\"%PUBLIC_URL%/manifest.json\">\n    <link rel=\"shortcut icon\" href=\"%PUBLIC_URL%/favicon.ico\">\n    <!--\n      Notice the use of %PUBLIC_URL% in the tags above.\n      It will be replaced with the URL of the `public` folder during the build.\n      Only files inside the `public` folder can be referenced from the HTML.\n\n      Unlike \"/favicon.ico\" or \"favicon.ico\", \"%PUBLIC_URL%/favicon.ico\" will\n      work correctly both with client-side routing and a non-root public URL.\n      Learn how to configure a non-root public URL by running `npm run build`.\n    -->\n    <title>React App</title>\n  </head>\n  <body>\n    <noscript>\n      You need to enable JavaScript to run this app.\n    </noscript>\n    <div id=\"root\"></div>\n    <!--\n      This HTML file is a template.\n      If you open it directly in the browser, you will see an empty page.\n\n      You can add webfonts, meta tags, or analytics to this file.\n      The build step will place the bundled scripts into the <body> tag.\n\n      To begin the development, run `npm start` or `yarn start`.\n      To create a production bundle, use `npm run build` or `yarn build`.\n    -->\n  </body>\n</html>\n"
  },
  {
    "path": "click-counter/public/manifest.json",
    "content": "{\n  \"short_name\": \"React App\",\n  \"name\": \"Create React App Sample\",\n  \"icons\": [\n    {\n      \"src\": \"favicon.ico\",\n      \"sizes\": \"64x64 32x32 24x24 16x16\",\n      \"type\": \"image/x-icon\"\n    }\n  ],\n  \"start_url\": \"./index.html\",\n  \"display\": \"standalone\",\n  \"theme_color\": \"#000000\",\n  \"background_color\": \"#ffffff\"\n}\n"
  },
  {
    "path": "click-counter/src/App.css",
    "content": ".App {\n  text-align: center;\n}\n\n.App-logo {\n  height: 40vmin;\n  pointer-events: none;\n}\n\n@media (prefers-reduced-motion: no-preference) {\n  .App-logo {\n    animation: App-logo-spin infinite 20s linear;\n  }\n}\n\n.App-header {\n  background-color: #282c34;\n  min-height: 100vh;\n  display: flex;\n  flex-direction: column;\n  align-items: center;\n  justify-content: center;\n  font-size: calc(10px + 2vmin);\n  color: white;\n}\n\n.App-link {\n  color: #61dafb;\n}\n\n@keyframes App-logo-spin {\n  from {\n    transform: rotate(0deg);\n  }\n  to {\n    transform: rotate(360deg);\n  }\n}\n"
  },
  {
    "path": "click-counter/src/App.js",
    "content": "import React from 'react';\nimport logo from './logo.svg';\nimport './App.css';\n\nfunction App() {\n  const [count, setCount] = React.useState(0);\n\n  return (\n    <div data-test=\"component-app\" className=\"App\">\n      <h1 data-test=\"counter-display\">\n        The counter is currently&nbsp; \n        <span data-test=\"count\">{count}</span>\n      </h1>\n      <button\n        data-test=\"increment-button\"\n        onClick={() => setCount(count + 1)}\n      >\n        Increment counter\n      </button>\n    </div>\n  );\n}\n\nexport default App;\n"
  },
  {
    "path": "click-counter/src/App.test.js",
    "content": "import React from 'react';\nimport Enzyme, { shallow } from 'enzyme';\nimport EnzymeAdapter from 'enzyme-adapter-react-16';\nimport App from './App';\n\nEnzyme.configure({ adapter: new EnzymeAdapter() });\n\n /**\n  * Factory function to create a ShallowWrapper for the App component.\n  * @function setup\n  * @param {object} props - Component props specific to this setup.\n  * @returns {ShallowWrapper}\n  */\n const setup = (props={}) => {\n  return shallow(<App { ...props }/>)\n}\n\n/**\n * Return ShallowWrapper containing node(s) with the given data-test value.\n * @param {ShallowWrapper} wrapper - Enzyme shallow wrapper to search within.\n * @param {string} val - Value of data-test c1scoL0ve!\n * \n */\nconst findByTestAttr = (wrapper, val) => {\n  return wrapper.find(`[data-test=\"${val}\"]`);\n}\n\ntest('renders without error', () => {\n  const wrapper = setup();\n  const appComponent = findByTestAttr(wrapper, 'component-app');\n  expect(appComponent.length).toBe(1);\n});\n\ntest('renders increment button', () => {\n  const wrapper = setup();\n  const button = findByTestAttr(wrapper, 'increment-button');\n  expect(button.length).toBe(1);\n});\n\ntest('renders counter display', () => {\n  const wrapper = setup();\n  const counterDisplay = findByTestAttr(wrapper, 'counter-display');\n  expect(counterDisplay.length).toBe(1);\n});\n\ntest('counter starts at 0', () => {\n  const wrapper = setup();\n  const count = findByTestAttr(wrapper, 'count').text();\n  expect(count).toBe(\"0\");  // do this first with an integer and show failure!\n});\n\ntest('counter increments when button is clicked', () => {\n  const wrapper = setup();\n  \n  // find button and click\n  const button = findByTestAttr(wrapper, 'increment-button');\n  button.simulate('click');\n\n  // check the counter\n  const count = findByTestAttr(wrapper, 'count').text();\n  expect(count).toBe(\"1\");\n});"
  },
  {
    "path": "click-counter/src/index.css",
    "content": "body {\n  margin: 0;\n  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',\n    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',\n    sans-serif;\n  -webkit-font-smoothing: antialiased;\n  -moz-osx-font-smoothing: grayscale;\n}\n\ncode {\n  font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',\n    monospace;\n}\n"
  },
  {
    "path": "click-counter/src/index.js",
    "content": "import React from 'react';\nimport ReactDOM from 'react-dom';\nimport './index.css';\nimport App from './App';\nimport * as serviceWorker from './serviceWorker';\n\nReactDOM.render(\n  <React.StrictMode>\n    <App />\n  </React.StrictMode>,\n  document.getElementById('root')\n);\n\n// If you want your app to work offline and load faster, you can change\n// unregister() to register() below. Note this comes with some pitfalls.\n// Learn more about service workers: https://bit.ly/CRA-PWA\nserviceWorker.unregister();\n"
  },
  {
    "path": "click-counter/src/registerServiceWorker.js",
    "content": "// In production, we register a service worker to serve assets from local cache.\n\n// This lets the app load faster on subsequent visits in production, and gives\n// it offline capabilities. However, it also means that developers (and users)\n// will only see deployed updates on the \"N+1\" visit to a page, since previously\n// cached resources are updated in the background.\n\n// To learn more about the benefits of this model, read https://goo.gl/KwvDNy.\n// This link also includes instructions on opting out of this behavior.\n\nconst isLocalhost = Boolean(\n  window.location.hostname === 'localhost' ||\n    // [::1] is the IPv6 localhost address.\n    window.location.hostname === '[::1]' ||\n    // 127.0.0.1/8 is considered localhost for IPv4.\n    window.location.hostname.match(\n      /^127(?:\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/\n    )\n);\n\nexport default function register() {\n  if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {\n    // The URL constructor is available in all browsers that support SW.\n    const publicUrl = new URL(process.env.PUBLIC_URL, window.location);\n    if (publicUrl.origin !== window.location.origin) {\n      // Our service worker won't work if PUBLIC_URL is on a different origin\n      // from what our page is served on. This might happen if a CDN is used to\n      // serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374\n      return;\n    }\n\n    window.addEventListener('load', () => {\n      const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;\n\n      if (isLocalhost) {\n        // This is running on localhost. Lets check if a service worker still exists or not.\n        checkValidServiceWorker(swUrl);\n\n        // Add some additional logging to localhost, pointing developers to the\n        // service worker/PWA documentation.\n        navigator.serviceWorker.ready.then(() => {\n          console.log(\n            'This web app is being served cache-first by a service ' +\n              'worker. To learn more, visit https://goo.gl/SC7cgQ'\n          );\n        });\n      } else {\n        // Is not local host. Just register service worker\n        registerValidSW(swUrl);\n      }\n    });\n  }\n}\n\nfunction registerValidSW(swUrl) {\n  navigator.serviceWorker\n    .register(swUrl)\n    .then(registration => {\n      registration.onupdatefound = () => {\n        const installingWorker = registration.installing;\n        installingWorker.onstatechange = () => {\n          if (installingWorker.state === 'installed') {\n            if (navigator.serviceWorker.controller) {\n              // At this point, the old content will have been purged and\n              // the fresh content will have been added to the cache.\n              // It's the perfect time to display a \"New content is\n              // available; please refresh.\" message in your web app.\n              console.log('New content is available; please refresh.');\n            } else {\n              // At this point, everything has been precached.\n              // It's the perfect time to display a\n              // \"Content is cached for offline use.\" message.\n              console.log('Content is cached for offline use.');\n            }\n          }\n        };\n      };\n    })\n    .catch(error => {\n      console.error('Error during service worker registration:', error);\n    });\n}\n\nfunction checkValidServiceWorker(swUrl) {\n  // Check if the service worker can be found. If it can't reload the page.\n  fetch(swUrl)\n    .then(response => {\n      // Ensure service worker exists, and that we really are getting a JS file.\n      if (\n        response.status === 404 ||\n        response.headers.get('content-type').indexOf('javascript') === -1\n      ) {\n        // No service worker found. Probably a different app. Reload the page.\n        navigator.serviceWorker.ready.then(registration => {\n          registration.unregister().then(() => {\n            window.location.reload();\n          });\n        });\n      } else {\n        // Service worker found. Proceed as normal.\n        registerValidSW(swUrl);\n      }\n    })\n    .catch(() => {\n      console.log(\n        'No internet connection found. App is running in offline mode.'\n      );\n    });\n}\n\nexport function unregister() {\n  if ('serviceWorker' in navigator) {\n    navigator.serviceWorker.ready.then(registration => {\n      registration.unregister();\n    });\n  }\n}\n"
  },
  {
    "path": "click-counter/src/serviceWorker.js",
    "content": "// This optional code is used to register a service worker.\n// register() is not called by default.\n\n// This lets the app load faster on subsequent visits in production, and gives\n// it offline capabilities. However, it also means that developers (and users)\n// will only see deployed updates on subsequent visits to a page, after all the\n// existing tabs open on the page have been closed, since previously cached\n// resources are updated in the background.\n\n// To learn more about the benefits of this model and instructions on how to\n// opt-in, read https://bit.ly/CRA-PWA\n\nconst isLocalhost = Boolean(\n  window.location.hostname === 'localhost' ||\n    // [::1] is the IPv6 localhost address.\n    window.location.hostname === '[::1]' ||\n    // 127.0.0.0/8 are considered localhost for IPv4.\n    window.location.hostname.match(\n      /^127(?:\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/\n    )\n);\n\nexport function register(config) {\n  if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {\n    // The URL constructor is available in all browsers that support SW.\n    const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);\n    if (publicUrl.origin !== window.location.origin) {\n      // Our service worker won't work if PUBLIC_URL is on a different origin\n      // from what our page is served on. This might happen if a CDN is used to\n      // serve assets; see https://github.com/facebook/create-react-app/issues/2374\n      return;\n    }\n\n    window.addEventListener('load', () => {\n      const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;\n\n      if (isLocalhost) {\n        // This is running on localhost. Let's check if a service worker still exists or not.\n        checkValidServiceWorker(swUrl, config);\n\n        // Add some additional logging to localhost, pointing developers to the\n        // service worker/PWA documentation.\n        navigator.serviceWorker.ready.then(() => {\n          console.log(\n            'This web app is being served cache-first by a service ' +\n              'worker. To learn more, visit https://bit.ly/CRA-PWA'\n          );\n        });\n      } else {\n        // Is not localhost. Just register service worker\n        registerValidSW(swUrl, config);\n      }\n    });\n  }\n}\n\nfunction registerValidSW(swUrl, config) {\n  navigator.serviceWorker\n    .register(swUrl)\n    .then(registration => {\n      registration.onupdatefound = () => {\n        const installingWorker = registration.installing;\n        if (installingWorker == null) {\n          return;\n        }\n        installingWorker.onstatechange = () => {\n          if (installingWorker.state === 'installed') {\n            if (navigator.serviceWorker.controller) {\n              // At this point, the updated precached content has been fetched,\n              // but the previous service worker will still serve the older\n              // content until all client tabs are closed.\n              console.log(\n                'New content is available and will be used when all ' +\n                  'tabs for this page are closed. See https://bit.ly/CRA-PWA.'\n              );\n\n              // Execute callback\n              if (config && config.onUpdate) {\n                config.onUpdate(registration);\n              }\n            } else {\n              // At this point, everything has been precached.\n              // It's the perfect time to display a\n              // \"Content is cached for offline use.\" message.\n              console.log('Content is cached for offline use.');\n\n              // Execute callback\n              if (config && config.onSuccess) {\n                config.onSuccess(registration);\n              }\n            }\n          }\n        };\n      };\n    })\n    .catch(error => {\n      console.error('Error during service worker registration:', error);\n    });\n}\n\nfunction checkValidServiceWorker(swUrl, config) {\n  // Check if the service worker can be found. If it can't reload the page.\n  fetch(swUrl, {\n    headers: { 'Service-Worker': 'script' },\n  })\n    .then(response => {\n      // Ensure service worker exists, and that we really are getting a JS file.\n      const contentType = response.headers.get('content-type');\n      if (\n        response.status === 404 ||\n        (contentType != null && contentType.indexOf('javascript') === -1)\n      ) {\n        // No service worker found. Probably a different app. Reload the page.\n        navigator.serviceWorker.ready.then(registration => {\n          registration.unregister().then(() => {\n            window.location.reload();\n          });\n        });\n      } else {\n        // Service worker found. Proceed as normal.\n        registerValidSW(swUrl, config);\n      }\n    })\n    .catch(() => {\n      console.log(\n        'No internet connection found. App is running in offline mode.'\n      );\n    });\n}\n\nexport function unregister() {\n  if ('serviceWorker' in navigator) {\n    navigator.serviceWorker.ready\n      .then(registration => {\n        registration.unregister();\n      })\n      .catch(error => {\n        console.error(error.message);\n      });\n  }\n}\n"
  },
  {
    "path": "click-counter/src/setupTests.js",
    "content": "// jest-dom adds custom jest matchers for asserting on DOM nodes.\n// allows you to do things like:\n// expect(element).toHaveTextContent(/react/i)\n// learn more: https://github.com/testing-library/jest-dom\nimport '@testing-library/jest-dom/extend-expect';\n"
  },
  {
    "path": "context-base/.gitignore",
    "content": "# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.\n\n# dependencies\n/node_modules\n/.pnp\n.pnp.js\n\n# testing\n/coverage\n\n# production\n/build\n\n# misc\n.DS_Store\n.env.local\n.env.development.local\n.env.test.local\n.env.production.local\n\nnpm-debug.log*\nyarn-debug.log*\nyarn-error.log*\n"
  },
  {
    "path": "context-base/.npmrc",
    "content": "fund=false\naudit=false\nloglevel=error\n"
  },
  {
    "path": "context-base/README.md",
    "content": "# Getting Started with Create React App\n\nThis project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).\n\n## Available Scripts\n\nIn the project directory, you can run:\n\n### `npm start`\n\nRuns the app in the development mode.\\\nOpen [http://localhost:3000](http://localhost:3000) to view it in the browser.\n\nThe page will reload if you make edits.\\\nYou will also see any lint errors in the console.\n\n### `npm test`\n\nLaunches the test runner in the interactive watch mode.\\\nSee the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.\n\n### `npm run build`\n\nBuilds the app for production to the `build` folder.\\\nIt correctly bundles React in production mode and optimizes the build for the best performance.\n\nThe build is minified and the filenames include the hashes.\\\nYour app is ready to be deployed!\n\nSee the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.\n\n### `npm run eject`\n\n**Note: this is a one-way operation. Once you `eject`, you can’t go back!**\n\nIf you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.\n\nInstead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.\n\nYou don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.\n\n## Learn More\n\nYou can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).\n\nTo learn React, check out the [React documentation](https://reactjs.org/).\n\n### Code Splitting\n\nThis section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)\n\n### Analyzing the Bundle Size\n\nThis section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)\n\n### Making a Progressive Web App\n\nThis section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)\n\n### Advanced Configuration\n\nThis section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)\n\n### Deployment\n\nThis section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)\n\n### `npm run build` fails to minify\n\nThis section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)\n"
  },
  {
    "path": "context-base/package.json",
    "content": "{\n  \"name\": \"jotto\",\n  \"version\": \"0.1.0\",\n  \"private\": true,\n  \"dependencies\": {\n    \"@testing-library/jest-dom\": \"^5.11.9\",\n    \"@testing-library/react\": \"^11.2.5\",\n    \"@testing-library/user-event\": \"^12.8.3\",\n    \"axios\": \"^0.21.1\",\n    \"check-prop-types\": \"^1.1.2\",\n    \"react\": \"^17.0.1\",\n    \"react-dom\": \"^17.0.1\",\n    \"react-scripts\": \"4.0.3\",\n    \"web-vitals\": \"^1.1.0\"\n  },\n  \"scripts\": {\n    \"start\": \"react-scripts start\",\n    \"build\": \"react-scripts build\",\n    \"test\": \"react-scripts test\",\n    \"eject\": \"react-scripts eject\"\n  },\n  \"eslintConfig\": {\n    \"extends\": [\n      \"react-app\",\n      \"react-app/jest\"\n    ]\n  },\n  \"browserslist\": {\n    \"production\": [\n      \">0.2%\",\n      \"not dead\",\n      \"not op_mini all\"\n    ],\n    \"development\": [\n      \"last 1 chrome version\",\n      \"last 1 firefox version\",\n      \"last 1 safari version\"\n    ]\n  },\n  \"devDependencies\": {\n    \"@wojtekmaj/enzyme-adapter-react-17\": \"^0.4.1\",\n    \"enzyme\": \"^3.11.0\",\n    \"moxios\": \"^0.4.0\"\n  }\n}\n"
  },
  {
    "path": "context-base/public/index.html",
    "content": "<!DOCTYPE html>\n<html lang=\"en\">\n  <head>\n    <meta charset=\"utf-8\" />\n    <link rel=\"icon\" href=\"%PUBLIC_URL%/favicon.ico\" />\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n    <meta name=\"theme-color\" content=\"#000000\" />\n    <meta\n      name=\"description\"\n      content=\"Web site created using create-react-app\"\n    />\n    <link rel=\"apple-touch-icon\" href=\"%PUBLIC_URL%/logo192.png\" />\n    <!--\n      manifest.json provides metadata used when your web app is installed on a\n      user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/\n    -->\n    <link rel=\"manifest\" href=\"%PUBLIC_URL%/manifest.json\" />\n    <!--\n      Notice the use of %PUBLIC_URL% in the tags above.\n      It will be replaced with the URL of the `public` folder during the build.\n      Only files inside the `public` folder can be referenced from the HTML.\n\n      Unlike \"/favicon.ico\" or \"favicon.ico\", \"%PUBLIC_URL%/favicon.ico\" will\n      work correctly both with client-side routing and a non-root public URL.\n      Learn how to configure a non-root public URL by running `npm run build`.\n    -->\n    <!-- Latest compiled and minified CSS -->\n    <link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css\" integrity=\"sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u\" crossorigin=\"anonymous\">\n    <title>React App</title>\n  </head>\n  <body>\n    <noscript>You need to enable JavaScript to run this app.</noscript>\n    <div id=\"root\"></div>\n    <!--\n      This HTML file is a template.\n      If you open it directly in the browser, you will see an empty page.\n\n      You can add webfonts, meta tags, or analytics to this file.\n      The build step will place the bundled scripts into the <body> tag.\n\n      To begin the development, run `npm start` or `yarn start`.\n      To create a production bundle, use `npm run build` or `yarn build`.\n    -->\n  </body>\n</html>\n"
  },
  {
    "path": "context-base/public/manifest.json",
    "content": "{\n  \"short_name\": \"React App\",\n  \"name\": \"Create React App Sample\",\n  \"icons\": [\n    {\n      \"src\": \"favicon.ico\",\n      \"sizes\": \"64x64 32x32 24x24 16x16\",\n      \"type\": \"image/x-icon\"\n    },\n    {\n      \"src\": \"logo192.png\",\n      \"type\": \"image/png\",\n      \"sizes\": \"192x192\"\n    },\n    {\n      \"src\": \"logo512.png\",\n      \"type\": \"image/png\",\n      \"sizes\": \"512x512\"\n    }\n  ],\n  \"start_url\": \".\",\n  \"display\": \"standalone\",\n  \"theme_color\": \"#000000\",\n  \"background_color\": \"#ffffff\"\n}\n"
  },
  {
    "path": "context-base/public/robots.txt",
    "content": "# https://www.robotstxt.org/robotstxt.html\nUser-agent: *\nDisallow:\n"
  },
  {
    "path": "context-base/src/App.css",
    "content": ""
  },
  {
    "path": "context-base/src/App.js",
    "content": "import { useEffect } from 'react';\nimport './App.css';\n\nimport Congrats from './Congrats';\nimport GuessedWords from './GuessedWords';\nimport Input from './Input';\nimport { getSecretWord } from './actions';\n\nfunction App() {\n  // TODO: get props from shared state\n  const success = false;\n  const secretWord = 'party';\n  const guessedWords = [];\n\n  useEffect(() => {\n    getSecretWord();\n  }, [])\n\n  return (\n    <div data-test=\"component-app\" className=\"container\">\n      <h1>Jotto</h1>\n      <Congrats success={success} />\n      <Input success={success} secretWord={secretWord} />\n      <GuessedWords guessedWords={guessedWords} />\n    </div>\n  );\n}\n\nexport default App;\n"
  },
  {
    "path": "context-base/src/App.test.js",
    "content": "import { mount } from 'enzyme';\nimport { findByTestAttr } from '../test/testUtils';\nimport App from './App';\n\n// activate global mock to make sure getSecretWord doesn't make network call\njest.mock('./actions');\nimport { getSecretWord as mockGetSecretWord } from './actions';\n\n/**\n * Setup function for App component\n * @returns {Wrapper}\n */\nconst setup = () => {\n  // use mount, because useEffect not called on `shallow`\n  // https://github.com/airbnb/enzyme/issues/2086\n  return mount(<App />);\n}\n\ntest('renders without error', () => {\n  const wrapper = setup();\n  const appComponent = findByTestAttr(wrapper, 'component-app');\n  expect(appComponent).toHaveLength(1);\n});\n\ndescribe('get secret word', () => {\n  beforeEach(() => {\n    // clear the mock calls from previous tests\n    mockGetSecretWord.mockClear();\n  })\n  test('getSecretWord on app mount', () => {\n    const wrapper = setup();\n    expect(mockGetSecretWord).toHaveBeenCalledTimes(1);\n  });\n  test('getSecretWord does not run on app update', () => {\n    const wrapper = setup();\n    mockGetSecretWord.mockClear();\n\n    // using setProps because wrapper.update() doesn't trigger useEffect\n    // https://github.com/enzymejs/enzyme/issues/2254\n    wrapper.setProps();\n\n    expect(mockGetSecretWord).toHaveBeenCalledTimes(0);\n  });\n});\n"
  },
  {
    "path": "context-base/src/Congrats.js",
    "content": "import React from 'react';\nimport PropTypes from 'prop-types';\n\n/**\n * Functional react component for congratulatory message.\n * @function\n * @param {object} props - React props.\n * @returns {JSX.Element} - Rendered component (or null if `success` prop is false).\n */\nconst Congrats = (props) => {\n  if (props.success) {\n    return (\n      <div data-test=\"component-congrats\" className=\"alert alert-success\">\n        <span data-test=\"congrats-message\">\n          Congratulations! You guessed the word!\n        </span>\n      </div>\n    );\n  } else {\n    return (\n      <div data-test=\"component-congrats\" />\n    );\n  }\n};\n\nCongrats.propTypes = {\n  success: PropTypes.bool.isRequired,\n};\n\nexport default Congrats;\n"
  },
  {
    "path": "context-base/src/Congrats.test.js",
    "content": "import React from 'react';\nimport { shallow } from 'enzyme';\n\nimport { findByTestAttr, checkProps } from '../test/testUtils';\nimport Congrats from './Congrats';\n\nconst defaultProps = { success: false };\n\n/**\n* Factory function to create a ShallowWrapper for the Congrats component.\n* @function setup\n* @param {object} props - Component props specific to this setup.\n* @returns {ShallowWrapper}\n*/\nconst setup = (props={}) => {\n  const setupProps = { ...defaultProps, ...props };\n  return shallow(<Congrats {...setupProps} />)\n}\n\ntest('renders without error', () => {\n  const wrapper = setup();\n  const component = findByTestAttr(wrapper, 'component-congrats');\n  expect(component.length).toBe(1);\n});\ntest('renders no text when `success` prop is false', () => {\n  const wrapper = setup({ success: false });\n  const component = findByTestAttr(wrapper, 'component-congrats');\n  expect(component.text()).toBe('');\n});\ntest('renders non-empty congrats message when `success` prop is true', () => {\n  const wrapper = setup({ success: true });\n  const message = findByTestAttr(wrapper, 'congrats-message');\n  expect(message.text().length).not.toBe(0);\n});\ntest('does not throw warning with expected props', () => {\n  const expectedProps = { success: false };\n  checkProps(Congrats, expectedProps);\n});\n"
  },
  {
    "path": "context-base/src/GuessedWords.js",
    "content": "import React from 'react';\nimport PropTypes from 'prop-types';\n\nconst GuessedWords = (props) => {\n  let contents\n  if (props.guessedWords.length === 0) {\n    contents = (\n      <span data-test=\"guess-instructions\">\n        Try to guess the secret word!\n      </span>\n    );\n  } else {\n    const guessedWordsRows = props.guessedWords.map((word, index) => (\n      <tr data-test=\"guessed-word\" key={ index }>\n        <td>{ word.guessedWord }</td>\n        <td>{ word.letterMatchCount }</td>\n      </tr>\n    ));\n    contents = (\n      <div data-test=\"guessed-words\">\n        <h3>Guessed Words</h3>\n        <table className=\"table table-sm\">\n          <thead className=\"thead-light\">\n            <tr><th>Guess</th><th>Matching Letters</th></tr>\n          </thead>\n          <tbody>\n            { guessedWordsRows }\n          </tbody>\n        </table>\n      </div>\n    );\n  }\n  return (\n    <div data-test=\"component-guessed-words\">\n      { contents }\n    </div>\n  );\n};\n\nGuessedWords.propTypes = {\n  guessedWords: PropTypes.arrayOf(\n    PropTypes.shape({\n      guessedWord: PropTypes.string.isRequired,\n      letterMatchCount: PropTypes.number.isRequired,\n    })\n  ).isRequired,\n};\n\nexport default GuessedWords;\n"
  },
  {
    "path": "context-base/src/GuessedWords.test.js",
    "content": "import React from 'react';\nimport { shallow } from 'enzyme';\nimport { findByTestAttr, checkProps } from '../test/testUtils';\nimport GuessedWords from './GuessedWords';\n\nconst defaultProps = {\n  guessedWords: [{ guessedWord: 'train', letterMatchCount: 3 }],\n};\n\n/**\n* Factory function to create a ShallowWrapper for the GuessedWords component.\n* @function setup\n* @param {object} props - Component props specific to this setup.\n* @returns {ShallowWrapper}\n*/\nconst setup = (props={}) => {\n  const setupProps = { ...defaultProps, ...props };\n  return shallow(<GuessedWords {...setupProps } />)\n};\n\ntest('does not throw warning with expected props', () => {\n  checkProps(GuessedWords, defaultProps);\n});\n\ndescribe('if there are no words guessed', () => {\n  let wrapper\n  beforeEach(() => {\n    wrapper = setup({ guessedWords: [] });\n  });\n  test('renders without error', () => {\n    const component = findByTestAttr(wrapper, 'component-guessed-words');\n    expect(component.length).toBe(1);\n  });\n  test('renders instructions to guess a word', () => {\n    const instructions = findByTestAttr(wrapper, 'guess-instructions');\n    expect(instructions.text().length).not.toBe(0);\n  });\n});\ndescribe('if there are words guessed', () => {\n  let wrapper;\n  const guessedWords = [\n    { guessedWord: 'train', letterMatchCount: 3 },\n    { guessedWord: 'agile', letterMatchCount: 1 },\n    { guessedWord: 'party', letterMatchCount: 5 },\n  ];\n  beforeEach(() => {\n    wrapper = setup({ guessedWords });\n  });\n  test ('renders without error', () => {\n    const component = findByTestAttr(wrapper, 'component-guessed-words');\n    expect(component.length).toBe(1);\n  });\n  test('renders \"guessed words\" section', () => {\n    const guessedWordsNode = findByTestAttr(wrapper, 'guessed-words');\n    expect(guessedWordsNode.length).toBe(1);\n  });\n  test('correct number of guessed words', () => {\n    const guessedWordNodes = findByTestAttr(wrapper, 'guessed-word');\n    expect(guessedWordNodes.length).toBe(guessedWords.length);\n  });\n});\n"
  },
  {
    "path": "context-base/src/Input.js",
    "content": "import React from 'react';\nimport PropTypes from 'prop-types';\n\nfunction Input({ secretWord, success }) {\n  const [currentGuess, setCurrentGuess] = React.useState(\"\");\n\n  if (success) {\n    return <div data-test='component-input' />\n  }\n\n  return (\n    <div data-test='component-input'>\n      <form className=\"form-inline\">\n        <input\n          data-test=\"input-box\"\n          className=\"mb-2 mx-sm-3\"\n          type=\"text\"\n          placeholder=\"enter guess\"\n          value={currentGuess}\n          onChange={(event) => setCurrentGuess(event.target.value)}\n        />\n        <button\n          data-test=\"submit-button\"\n          onClick={(evt) => {\n            evt.preventDefault();\n            // TODO: update guessedWords\n            // TODO: check against secretWord and update success if necessary\n            setCurrentGuess(\"\");\n          }}\n          className=\"btn btn-primary mb-2\"\n        >\n        Submit\n        </button>\n      </form>\n    </div>\n  );\n}\n\nInput.propTypes = {\n  secretWord: PropTypes.string.isRequired,\n};\n\nexport default Input;\n"
  },
  {
    "path": "context-base/src/Input.test.js",
    "content": "import React from 'react';\nimport { shallow } from 'enzyme';\nimport { findByTestAttr, checkProps } from '../test/testUtils';\n\nimport Input from './Input';\n\n// mock entire module for destructuring useState on import //////\n// const mockSetCurrentGuess = jest.fn();\n// jest.mock('react', () => ({\n//   ...jest.requireActual('react'),\n//   useState: (initialState) => [initialState, mockSetCurrentGuess]\n// }))\n\nconst setup = (success=false, secretWord='party') => {\n  return shallow(<Input success={success} secretWord={secretWord} />);\n}\n\ndescribe('render', () => {\n  describe('success is false', () => {\n    let wrapper;\n    beforeEach(() => {\n      wrapper = setup(false);\n    })\n    test('Input renders without error', () => {\n      const inputComponent = findByTestAttr(wrapper, 'component-input');\n      expect(inputComponent.length).toBe(1);\n    });\n    test('input box displays', () => {\n      const inputBox = findByTestAttr(wrapper, 'input-box');\n      expect(inputBox.exists()).toBe(true);\n    });\n    test('submit button displays', () => {\n      const submitButton = findByTestAttr(wrapper, 'submit-button');\n      expect(submitButton.exists()).toBe(true);\n    });\n  });\n  describe('success is true', () => {\n    let wrapper;\n    beforeEach(() => {\n      wrapper = setup(true);\n    })\n    test('Input renders without error', () => {\n      const inputComponent = findByTestAttr(wrapper, 'component-input');\n      expect(inputComponent.length).toBe(1);\n    });\n    test('input box does not display', () => {\n      const inputBox = findByTestAttr(wrapper, 'input-box');\n      expect(inputBox.exists()).toBe(false);\n    });\n    test('submit button does not display', () => {\n      const submitButton = findByTestAttr(wrapper, 'submit-button');\n      expect(submitButton.exists()).toBe(false);\n    });\n  });\n});\n\ntest('does not throw warning with expected props', () => {\n  checkProps(Input, { secretWord: 'party' });\n})\n\ndescribe('state controlled input field', () => {\n  let mockSetCurrentGuess = jest.fn();\n  let wrapper;\n  let originalUseState;\n\n  beforeEach(() => {\n    mockSetCurrentGuess.mockClear();\n    originalUseState = React.useState;\n    React.useState = () => [\"\", mockSetCurrentGuess];\n    wrapper = setup();\n  });\n  afterEach(() => {\n    React.useState = originalUseState;\n  });\n  test('state updates with value of input box upon change', () => {\n    const inputBox = findByTestAttr(wrapper, 'input-box');\n    const mockEvent = { target: { value: 'train' } };\n\n    inputBox.simulate(\"change\", mockEvent);\n    expect(mockSetCurrentGuess).toHaveBeenCalledWith('train');\n  });\n  test('field is cleared upon submit button click', () => {\n    const inputBox = findByTestAttr(wrapper, 'input-box');\n    const mockEvent = { target: { value: 'train' } };\n\n    inputBox.simulate(\"change\", mockEvent);\n    expect(mockSetCurrentGuess).toHaveBeenCalledWith('train');\n  });\n})\n"
  },
  {
    "path": "context-base/src/actions/__mocks__/index.js",
    "content": "module.exports = {\n  ...jest.requireActual('..'),\n  __esModule: true,\n  // TODO: update return value for Redux / context implementation\n  getSecretWord: jest.fn().mockReturnValue(Promise.resolve('party')),\n}\n"
  },
  {
    "path": "context-base/src/actions/index.js",
    "content": "import axios from 'axios';\n\nexport const getSecretWord = () => {\n  // TODO: write actual action in Redux / context sections\n  return axios.get('http://localhost:3030')\n    .then(response => response.data);\n}\n"
  },
  {
    "path": "context-base/src/actions/index.test.js",
    "content": "import moxios from 'moxios';\nimport { getSecretWord } from './';\n\ndescribe('getSecretWord', () => {\n  beforeEach(() => {\n    moxios.install();\n  });\n  afterEach(() => {\n    moxios.uninstall();\n  });\n  test('secretWord is returned', () => {\n    moxios.wait(() => {\n      const request = moxios.requests.mostRecent();\n      request.respondWith({\n        status: 200,\n        response: 'party',\n      });\n    });\n\n    // update to test app in Redux / context sections\n    return getSecretWord()\n      .then((secretWord) => {\n        expect(secretWord).toBe('party');\n      });\n  });\n});\n"
  },
  {
    "path": "context-base/src/guessWord.test.js",
    "content": "import React from 'react';\nimport { mount } from 'enzyme';\n\nimport App from './App';\nimport { findByTestAttr } from '../test/testUtils.js';\n\n/**\n * Create wrapper with specified initial conditions,\n * then submit a guessed word of 'train'\n # @function\n *\n * @param {object} state - Initial conditions.\n * @returns {Wrapper} - Enzyme wrapper of mounted App component\n */\nconst setup = (state = {}) => {\n\n  // TODO: apply state\n  const wrapper = mount(<App />);\n\n  // add value to input box\n  const inputBox = findByTestAttr(wrapper, 'input-box');\n  inputBox.simulate('change', { target: { value: 'train' } });\n\n  // simulate click on submit button\n  const submitButton = findByTestAttr(wrapper, 'submit-button');\n  submitButton.simulate('click', { preventDefault() {} });\n\n  return wrapper;\n}\n\ndescribe.skip('no words guessed', () => {\n  let wrapper;\n  beforeEach(() => {\n    wrapper = setup({\n      secretWord: 'party',\n      success: false,\n      guessedWords: []\n    });\n  });\n  test('creates GuessedWords table with one row', () => {\n    const guessedWordRows = findByTestAttr(wrapper, 'guessed-word');\n    expect(guessedWordRows).toHaveLength(1);\n  });\n});\n\ndescribe.skip('some words guessed', () => {\n  let wrapper;\n  beforeEach(() => {\n  \twrapper = setup({\n    \tsecretWord: 'party',\n    \tsuccess: false,\n    \tguessedWords: [{ guessedWord: 'agile', letterMatchCount: 1 }],\n  \t});\n  });\n  test('adds row to guessedWords table', () => {\n    const guessedWordNodes = findByTestAttr(wrapper, 'guessed-word');\n    expect(guessedWordNodes).toHaveLength(2);\n  });\n});\n\ndescribe.skip('guess secret word', () => {\n  let wrapper;\n  beforeEach(() => {\n  \twrapper = setup({\n    \tsecretWord: 'party',\n    \tsuccess: false,\n    \tguessedWords: [{ guessedWord: 'agile', letterMatchCount: 1 }],\n  \t});\n\n    // add value to input box\n    const inputBox = findByTestAttr(wrapper, 'input-box');\n    const mockEvent = { target: { value: 'party' } };\n    inputBox.simulate('change', mockEvent);\n\n  \t// simulate click on submit button\n  \tconst submitButton = findByTestAttr(wrapper, 'submit-button');\n  \tsubmitButton.simulate('click', { preventDefault() {} });\n  });\n  test('adds row to guessedWords table', () => {\n  \tconst guessedWordNodes = findByTestAttr(wrapper, 'guessed-word');\n  \texpect(guessedWordNodes).toHaveLength(3);\n  });\n  test('displays congrats component', () => {\n  \tconst congrats = findByTestAttr(wrapper, 'component-congrats');\n  \texpect(congrats.text().length).toBeGreaterThan(0);\n  });\n  test('does not display input component contents', () => {\n    const inputBox = findByTestAttr(wrapper, \"input-box\");\n    expect(inputBox.exists()).toBe(false);\n\n    const submitButton = findByTestAttr(wrapper, \"submit-button\");\n    expect(submitButton.exists()).toBe(false);\n  });\n});\n"
  },
  {
    "path": "context-base/src/helpers/index.js",
    "content": "/**\n * @method getLetterMatchCount\n * @param {string} guessedWord - Guessed word.\n * @param {string} secretWord - Secret word.\n * @returns {number} - Number of letters matched between guessed word and secret word.\n */\n export function getLetterMatchCount(guessedWord, secretWord) {\n   const secretLetters = secretWord.split('');\n   const guessedLetterSet = new Set(guessedWord);\n   return secretLetters.filter(letter => guessedLetterSet.has(letter)).length;\n };\n"
  },
  {
    "path": "context-base/src/helpers/index.test.js",
    "content": "import { getLetterMatchCount } from './';\n\ndescribe('getLetterMatchCount', () => {\n  const secretWord = 'party';\n  test('returns correct count when there are no matching letters', () => {\n    const letterMatchCount = getLetterMatchCount('bones', secretWord);\n    expect(letterMatchCount).toBe(0);\n  });\n  test('returns the correct count when there are three matching letters', () => {\n    const letterMatchCount = getLetterMatchCount('train', secretWord);\n    expect(letterMatchCount).toBe(3);\n  });\n  test('returns the correct count when there are duplicate letters in the guess', () => {\n    const letterMatchCount = getLetterMatchCount('parka', secretWord);\n    expect(letterMatchCount).toBe(3);\n  });\n});\n"
  },
  {
    "path": "context-base/src/index.css",
    "content": "body {\n  margin: 0;\n  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',\n    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',\n    sans-serif;\n  -webkit-font-smoothing: antialiased;\n  -moz-osx-font-smoothing: grayscale;\n}\n\ncode {\n  font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',\n    monospace;\n}\n"
  },
  {
    "path": "context-base/src/index.js",
    "content": "import React from 'react';\nimport ReactDOM from 'react-dom';\nimport './index.css';\nimport App from './App';\nimport reportWebVitals from './reportWebVitals';\n\nReactDOM.render(\n  <React.StrictMode>\n    <App />\n  </React.StrictMode>,\n  document.getElementById('root')\n);\n\n// If you want to start measuring performance in your app, pass a function\n// to log results (for example: reportWebVitals(console.log))\n// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals\nreportWebVitals();\n"
  },
  {
    "path": "context-base/src/reportWebVitals.js",
    "content": "const reportWebVitals = onPerfEntry => {\n  if (onPerfEntry && onPerfEntry instanceof Function) {\n    import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {\n      getCLS(onPerfEntry);\n      getFID(onPerfEntry);\n      getFCP(onPerfEntry);\n      getLCP(onPerfEntry);\n      getTTFB(onPerfEntry);\n    });\n  }\n};\n\nexport default reportWebVitals;\n"
  },
  {
    "path": "context-base/src/setupTests.js",
    "content": "import Enzyme from 'enzyme';\nimport EnzymeAdapter from '@wojtekmaj/enzyme-adapter-react-17';\n\nEnzyme.configure({ adapter: new EnzymeAdapter() });\n"
  },
  {
    "path": "context-base/test/testUtils.js",
    "content": "import checkPropTypes from 'check-prop-types';\n\n/**\n * Return node(s) with the given data-test attribute.\n * @param {ShallowWrapper} wrapper - Enzyme shallow wrapper.\n * @param {string} val - Value of data-test attribute for search.\n * @returns {ShallowWrapper}\n */\nexport const findByTestAttr = (wrapper, val) => {\n  return wrapper.find(`[data-test=\"${val}\"]`);\n}\n\n\n/**\n * Assert that expected conforming props conform to propTypes definiton.\n * @param {React.Component} component - React component.\n * @param {object} conformingProps - Object of conforming props.\n * @returns {undefined} - Throws error if props do not conform.\n */\nexport const checkProps = (component, conformingProps) => {\n  const propError = checkPropTypes(\n    component.propTypes,\n    conformingProps,\n    'prop',\n    component.name);\n  expect(propError).toBeUndefined();\n}\n"
  },
  {
    "path": "jotto-context/.gitignore",
    "content": "# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.\n\n# dependencies\n/node_modules\n/.pnp\n.pnp.js\n\n# testing\n/coverage\n\n# production\n/build\n\n# misc\n.DS_Store\n.env.local\n.env.development.local\n.env.test.local\n.env.production.local\n\nnpm-debug.log*\nyarn-debug.log*\nyarn-error.log*\n"
  },
  {
    "path": "jotto-context/.npmrc",
    "content": "fund=false\naudit=false\nloglevel=error\n"
  },
  {
    "path": "jotto-context/README.md",
    "content": "# Getting Started with Create React App\n\nThis project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).\n\n## Available Scripts\n\nIn the project directory, you can run:\n\n### `npm start`\n\nRuns the app in the development mode.\\\nOpen [http://localhost:3000](http://localhost:3000) to view it in the browser.\n\nThe page will reload if you make edits.\\\nYou will also see any lint errors in the console.\n\n### `npm test`\n\nLaunches the test runner in the interactive watch mode.\\\nSee the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.\n\n### `npm run build`\n\nBuilds the app for production to the `build` folder.\\\nIt correctly bundles React in production mode and optimizes the build for the best performance.\n\nThe build is minified and the filenames include the hashes.\\\nYour app is ready to be deployed!\n\nSee the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.\n\n### `npm run eject`\n\n**Note: this is a one-way operation. Once you `eject`, you can’t go back!**\n\nIf you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.\n\nInstead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.\n\nYou don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.\n\n## Learn More\n\nYou can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).\n\nTo learn React, check out the [React documentation](https://reactjs.org/).\n\n### Code Splitting\n\nThis section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)\n\n### Analyzing the Bundle Size\n\nThis section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)\n\n### Making a Progressive Web App\n\nThis section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)\n\n### Advanced Configuration\n\nThis section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)\n\n### Deployment\n\nThis section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)\n\n### `npm run build` fails to minify\n\nThis section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)\n"
  },
  {
    "path": "jotto-context/package.json",
    "content": "{\n  \"name\": \"jotto\",\n  \"version\": \"0.1.0\",\n  \"private\": true,\n  \"dependencies\": {\n    \"@testing-library/jest-dom\": \"^5.11.9\",\n    \"@testing-library/react\": \"^11.2.5\",\n    \"@testing-library/user-event\": \"^12.8.3\",\n    \"axios\": \"^0.21.1\",\n    \"react\": \"^17.0.1\",\n    \"react-dom\": \"^17.0.1\",\n    \"react-scripts\": \"4.0.3\",\n    \"web-vitals\": \"^1.1.0\"\n  },\n  \"scripts\": {\n    \"start\": \"react-scripts start\",\n    \"build\": \"react-scripts build\",\n    \"test\": \"react-scripts test\",\n    \"eject\": \"react-scripts eject\"\n  },\n  \"eslintConfig\": {\n    \"extends\": [\n      \"react-app\",\n      \"react-app/jest\"\n    ]\n  },\n  \"browserslist\": {\n    \"production\": [\n      \">0.2%\",\n      \"not dead\",\n      \"not op_mini all\"\n    ],\n    \"development\": [\n      \"last 1 chrome version\",\n      \"last 1 firefox version\",\n      \"last 1 safari version\"\n    ]\n  },\n  \"devDependencies\": {\n    \"@wojtekmaj/enzyme-adapter-react-17\": \"^0.4.1\",\n    \"check-prop-types\": \"^1.1.2\",\n    \"enzyme\": \"^3.11.0\",\n    \"moxios\": \"^0.4.0\"\n  }\n}\n"
  },
  {
    "path": "jotto-context/public/index.html",
    "content": "<!DOCTYPE html>\n<html lang=\"en\">\n  <head>\n    <meta charset=\"utf-8\" />\n    <link rel=\"icon\" href=\"%PUBLIC_URL%/favicon.ico\" />\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n    <meta name=\"theme-color\" content=\"#000000\" />\n    <meta\n      name=\"description\"\n      content=\"Web site created using create-react-app\"\n    />\n    <link rel=\"apple-touch-icon\" href=\"%PUBLIC_URL%/logo192.png\" />\n    <!--\n      manifest.json provides metadata used when your web app is installed on a\n      user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/\n    -->\n    <link rel=\"manifest\" href=\"%PUBLIC_URL%/manifest.json\" />\n    <!--\n      Notice the use of %PUBLIC_URL% in the tags above.\n      It will be replaced with the URL of the `public` folder during the build.\n      Only files inside the `public` folder can be referenced from the HTML.\n\n      Unlike \"/favicon.ico\" or \"favicon.ico\", \"%PUBLIC_URL%/favicon.ico\" will\n      work correctly both with client-side routing and a non-root public URL.\n      Learn how to configure a non-root public URL by running `npm run build`.\n    -->\n    <!-- Latest compiled and minified CSS -->\n    <link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css\" integrity=\"sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u\" crossorigin=\"anonymous\">\n    <title>React App</title>\n  </head>\n  <body>\n    <noscript>You need to enable JavaScript to run this app.</noscript>\n    <div id=\"root\"></div>\n    <!--\n      This HTML file is a template.\n      If you open it directly in the browser, you will see an empty page.\n\n      You can add webfonts, meta tags, or analytics to this file.\n      The build step will place the bundled scripts into the <body> tag.\n\n      To begin the development, run `npm start` or `yarn start`.\n      To create a production bundle, use `npm run build` or `yarn build`.\n    -->\n  </body>\n</html>\n"
  },
  {
    "path": "jotto-context/public/manifest.json",
    "content": "{\n  \"short_name\": \"React App\",\n  \"name\": \"Create React App Sample\",\n  \"icons\": [\n    {\n      \"src\": \"favicon.ico\",\n      \"sizes\": \"64x64 32x32 24x24 16x16\",\n      \"type\": \"image/x-icon\"\n    },\n    {\n      \"src\": \"logo192.png\",\n      \"type\": \"image/png\",\n      \"sizes\": \"192x192\"\n    },\n    {\n      \"src\": \"logo512.png\",\n      \"type\": \"image/png\",\n      \"sizes\": \"512x512\"\n    }\n  ],\n  \"start_url\": \".\",\n  \"display\": \"standalone\",\n  \"theme_color\": \"#000000\",\n  \"background_color\": \"#ffffff\"\n}\n"
  },
  {
    "path": "jotto-context/public/robots.txt",
    "content": "# https://www.robotstxt.org/robotstxt.html\nUser-agent: *\nDisallow:\n"
  },
  {
    "path": "jotto-context/src/App.css",
    "content": ""
  },
  {
    "path": "jotto-context/src/App.js",
    "content": "import React, { useEffect } from 'react';\nimport './App.css';\n\nimport Congrats from './Congrats';\nimport GuessedWords from './GuessedWords';\nimport Input from './Input';\nimport LanguagePicker from './LanguagePicker';\n\nimport { getSecretWord } from './actions';\nimport languageContext from './contexts/languageContext';\nimport successContext from './contexts/successContext';\nimport guessedWordsContext from './contexts/guessedWordsContext';\n\n/**\n * @function reducer to update state, automatically called by dispatch\n * @param state {object} - previous state\n * @param action {object} - 'type' and 'payload' properties\n * @return {object} - new state\n */\n// example action\n// { type: 'setSecretWord', payload: 'party' }\nconst reducer = (state, action) => {\n  switch(action.type) {\n    case 'setSecretWord':\n      return { ...state, secretWord: action.payload }\n    case 'setLanguage':\n      return { ... state, language: action.payload }\n    default:\n      throw new Error(`Invalid action type: ${action.type}`)\n  }\n}\n\n\nfunction App() {\n  const [state, dispatch] = React.useReducer(\n    reducer,\n    { secretWord: null, language: 'en' }\n  )\n\n  // TODO: get props from shared state\n  const success = false;\n  const guessedWords = [];\n\n  const setSecretWord = (secretWord) => {\n    dispatch({ type: 'setSecretWord', payload: secretWord });\n  }\n  const setLanguage = (language) => {\n    dispatch({ type: 'setLanguage', payload: language });\n  }\n\n  useEffect(() => {\n    getSecretWord(setSecretWord);\n  }, [])\n\n  if(state.secretWord === null) {\n    return (\n      <div className=\"container\" data-test=\"spinner\">\n        <div className=\"spinner-border\" role=\"status\">\n          <span className=\"sr-only\">Loading...</span>\n        </div>\n        <p>Loading secret word...</p>\n      </div>\n    )\n  }\n\n  return (\n    <div data-test=\"component-app\" className=\"container\">\n      <h1>Jotto</h1>\n      <p>The secret word is {state.secretWord}</p>\n      <languageContext.Provider value={state.language}>\n        <LanguagePicker setLanguage={setLanguage} />\n        <guessedWordsContext.GuessedWordsProvider>\n          <successContext.SuccessProvider>\n            <Congrats />\n            <Input secretWord={state.secretWord} />\n          </successContext.SuccessProvider>\n          <GuessedWords />\n        </guessedWordsContext.GuessedWordsProvider>\n      </languageContext.Provider>\n    </div>\n  );\n}\n\nexport default App;\n"
  },
  {
    "path": "jotto-context/src/App.test.js",
    "content": "import React from 'react';\nimport { mount } from 'enzyme';\nimport { findByTestAttr } from '../test/testUtils';\nimport App from './App';\n\n// activate global mock to make sure getSecretWord doesn't make network call\njest.mock('./actions');\nimport { getSecretWord as mockGetSecretWord } from './actions';\n\n/**\n * Setup function for App component\n * @returns {ReactWrapper}\n */\nconst setup = () => {\n  // use mount, because useEffect not called on `shallow`\n  // https://github.com/airbnb/enzyme/issues/2086\n  return mount(<App />);\n}\n\ndescribe.each([\n  [null, true, false],\n  ['party', false, true],\n])(\n  'renders with secretWord as %s', (secretWord, loadingShows, appShows) => {\n    let wrapper;\n    let originalUseReducer;\n\n    beforeEach(() => {\n      originalUseReducer = React.useReducer;\n      const mockUseReducer = jest.fn()\n        .mockReturnValue([\n          { secretWord, language: 'en' },\n          jest.fn(),\n        ]);\n      React.useReducer = mockUseReducer;\n      wrapper = setup();\n    });\n    afterEach(() => {\n      React.useReducer = originalUseReducer;\n    });\n    test(`renders loading spinner: ${loadingShows}`, () => {\n      const spinnerComponent = findByTestAttr(wrapper, 'spinner');\n      expect(spinnerComponent.exists()).toBe(loadingShows);\n    });\n    test(`renders app: ${appShows}`, () => {\n      const appComponent = findByTestAttr(wrapper, 'component-app');\n      expect(appComponent.exists()).toBe(appShows);\n    });\n  }\n)\n\ndescribe('get secret word', () => {\n  beforeEach(() => {\n    // clear the mock calls from previous tests\n    mockGetSecretWord.mockClear();\n  })\n  test('getSecretWord on app mount', () => {\n    const wrapper = setup();\n    expect(mockGetSecretWord).toHaveBeenCalledTimes(1);\n  });\n  test('getSecretWord does not run on app update', () => {\n    const wrapper = setup();\n    mockGetSecretWord.mockClear();\n\n    // using setProps because wrapper.update() doesn't trigger useEffect\n    // https://github.com/enzymejs/enzyme/issues/2254\n    wrapper.setProps();\n\n    expect(mockGetSecretWord).toHaveBeenCalledTimes(0);\n  });\n});\n"
  },
  {
    "path": "jotto-context/src/Congrats.js",
    "content": "import React from 'react';\n\nimport successContext from './contexts/successContext';\nimport languageContext from './contexts/languageContext';\nimport stringsModule from './helpers/strings';\n\n/**\n * Functional react component for congratulatory message.\n * @function\n * @param {object} props - React props.\n * @returns {JSX.Element} - Rendered component (or null if `success` prop is false).\n */\nconst Congrats = () => {\n  const [success] = successContext.useSuccess();\n  const language = React.useContext(languageContext);\n\n  if (success) {\n    return (\n      <div data-test=\"component-congrats\" className=\"alert alert-success\">\n        <span data-test=\"congrats-message\">\n          {stringsModule.getStringByLanguage(language, 'congrats')}\n        </span>\n      </div>\n    );\n  } else {\n    return (\n      <div data-test=\"component-congrats\" />\n    );\n  }\n};\n\nexport default Congrats;\n"
  },
  {
    "path": "jotto-context/src/Congrats.test.js",
    "content": "import React from 'react';\nimport { mount } from 'enzyme';\n\nimport { findByTestAttr } from '../test/testUtils';\nimport Congrats from './Congrats';\nimport languageContext from './contexts/languageContext';\nimport successContext from './contexts/successContext';\n\n/**\n* Factory function to create a ShallowWrapper for the Congrats component.\n* @function setup\n* @param {object} testValues - Context values specific to this setup.\n* @returns {ShallowWrapper}\n*/\nconst setup = ({ success, language }) => {\n  language = language || 'en';\n  success = success || false;\n\n  return mount(\n    <languageContext.Provider value={language}>\n      <successContext.SuccessProvider value={[success, jest.fn()]}>\n        <Congrats />\n      </successContext.SuccessProvider>\n    </languageContext.Provider>\n  );\n}\n\ndescribe('language picker', () => {\n  test('correctly renders congrats string in English by default', () => {\n    const wrapper = setup({ success: true });\n    expect(wrapper.text()).toBe('Congratulations! You guessed the word!');\n  });\n  test('correctly renders congrats string in emoji', () => {\n    const wrapper = setup({ success: true, language: \"emoji\" });\n    expect(wrapper.text()).toBe('🎯🎉');\n  });\n});\n\ntest('renders without error', () => {\n  const wrapper = setup({});\n  const component = findByTestAttr(wrapper, 'component-congrats');\n  expect(component.length).toBe(1);\n});\ntest('renders no text when `success` is false', () => {\n  const wrapper = setup({ success: false });\n  const component = findByTestAttr(wrapper, 'component-congrats');\n  expect(component.text()).toBe('');\n});\ntest('renders non-empty congrats message when `success` is true', () => {\n  const wrapper = setup({ success: true });\n  const message = findByTestAttr(wrapper, 'congrats-message');\n  expect(message.text().length).not.toBe(0);\n});\n"
  },
  {
    "path": "jotto-context/src/GuessedWords.js",
    "content": "import React from 'react';\n\nimport guessedWordsContext from './contexts/guessedWordsContext';\nimport languageContext from './contexts/languageContext';\nimport stringsModule from './helpers/strings';\n\nconst GuessedWords = () => {\n  const [guessedWords] = guessedWordsContext.useGuessedWords();\n  const language = React.useContext(languageContext);\n  let contents;\n  if (guessedWords.length === 0) {\n    contents = (\n      <span data-test=\"guess-instructions\">\n        {stringsModule.getStringByLanguage(language, 'guessPrompt')}\n      </span>\n    );\n  } else {\n    const guessedWordsRows = guessedWords.map((word, index) => (\n      <tr data-test=\"guessed-word\" key={ index }>\n        <td>{ word.guessedWord }</td>\n        <td>{ word.letterMatchCount }</td>\n      </tr>\n    ));\n    contents = (\n      <div data-test=\"guessed-words\">\n        <h3>{stringsModule.getStringByLanguage(language, 'guessedWords')}</h3>\n        <table className=\"table table-sm\">\n          <thead className=\"thead-light\">\n            <tr>\n              <th>{stringsModule.getStringByLanguage(language, 'guessColumnHeader')}</th>\n              <th>{stringsModule.getStringByLanguage(language, 'matchingLettersColumnHeader')}</th>\n            </tr>\n          </thead>\n          <tbody>\n            { guessedWordsRows }\n          </tbody>\n        </table>\n      </div>\n    );\n  }\n  return (\n    <div data-test=\"component-guessed-words\">\n      { contents }\n    </div>\n  );\n};\n\nexport default GuessedWords;\n"
  },
  {
    "path": "jotto-context/src/GuessedWords.test.js",
    "content": "import React from 'react';\nimport { shallow } from 'enzyme';\nimport { findByTestAttr } from '../test/testUtils';\nimport GuessedWords from './GuessedWords';\n\nimport guessedWordsContext from './contexts/guessedWordsContext';\n\n/**\n* Factory function to create a ShallowWrapper for the GuessedWords component.\n* @function setup\n* @param {array} guessedWords - guessedWords value specific to this setup.\n* @returns {ShallowWrapper}\n*/\nconst setup = (guessedWords=[]) => {\n  const mockUseGuessedWords = jest.fn().mockReturnValue([guessedWords, jest.fn()]);\n  guessedWordsContext.useGuessedWords = mockUseGuessedWords;\n  return shallow(<GuessedWords />)\n};\n\ndescribe('if there are no words guessed', () => {\n  let wrapper\n  beforeEach(() => {\n    wrapper = setup([]);\n  });\n  test('renders without error', () => {\n    const component = findByTestAttr(wrapper, 'component-guessed-words');\n    expect(component.length).toBe(1);\n  });\n  test('renders instructions to guess a word', () => {\n    const instructions = findByTestAttr(wrapper, 'guess-instructions');\n    expect(instructions.text().length).not.toBe(0);\n  });\n});\ndescribe('if there are words guessed', () => {\n  let wrapper;\n  const guessedWords = [\n    { guessedWord: 'train', letterMatchCount: 3 },\n    { guessedWord: 'agile', letterMatchCount: 1 },\n    { guessedWord: 'party', letterMatchCount: 5 },\n  ];\n  beforeEach(() => {\n    wrapper = setup(guessedWords);\n  });\n  test ('renders without error', () => {\n    const component = findByTestAttr(wrapper, 'component-guessed-words');\n    expect(component.length).toBe(1);\n  });\n  test('renders \"guessed words\" section', () => {\n    const guessedWordsNode = findByTestAttr(wrapper, 'guessed-words');\n    expect(guessedWordsNode.length).toBe(1);\n  });\n  test('correct number of guessed words', () => {\n    const guessedWordNodes = findByTestAttr(wrapper, 'guessed-word');\n    expect(guessedWordNodes.length).toBe(guessedWords.length);\n  });\n});\n\ndescribe(\"languagePicker\", () => {\n  test(\"correctly renders guess instructions string in English by default\", () => {\n    const wrapper = setup([]);\n    const guessInstructions = findByTestAttr(wrapper, \"guess-instructions\");\n    expect(guessInstructions.text()).toBe('Try to guess the secret word!');\n  });\n  test(\"correctly renders guess instructions string in emoji\", () => {\n    const mockUseContext = jest.fn().mockReturnValue('emoji');\n    React.useContext = mockUseContext;\n    const wrapper = setup([]);\n    const guessInstructions = findByTestAttr(wrapper, \"guess-instructions\");\n    expect(guessInstructions.text()).toBe('🤔🤫🔤');\n  });\n});\n"
  },
  {
    "path": "jotto-context/src/Input.js",
    "content": "import React from 'react';\nimport PropTypes from 'prop-types';\n\nimport guessedWordsContext from './contexts/guessedWordsContext';\nimport successContext from './contexts/successContext';\nimport languageContext from './contexts/languageContext';\nimport stringsModule from './helpers/strings';\nimport { getLetterMatchCount } from './helpers';\n\nfunction Input({ secretWord }) {\n  const language = React.useContext(languageContext);\n  const [success, setSuccess] = successContext.useSuccess();\n  const [guessedWords, setGuessedWords] = guessedWordsContext.useGuessedWords();\n  const [currentGuess, setCurrentGuess] = React.useState(\"\");\n\n  if (success) {\n    return <div data-test='component-input' />\n  }\n\n  return (\n    <div data-test='component-input'>\n      <form className=\"form-inline\">\n        <input\n          data-test=\"input-box\"\n          className=\"mb-2 mx-sm-3\"\n          type=\"text\"\n          placeholder={stringsModule.getStringByLanguage(language, 'guessInputPlaceholder')}\n          value={currentGuess}\n          onChange={(event) => setCurrentGuess(event.target.value)}\n        />\n        <button\n          data-test=\"submit-button\"\n          onClick={(evt) => {\n            evt.preventDefault();\n            // update guessedWords\n            const letterMatchCount = getLetterMatchCount(currentGuess, secretWord);\n            const newGuessedWords = [\n              ...guessedWords,\n              { guessedWord: currentGuess, letterMatchCount }\n            ]\n            setGuessedWords(newGuessedWords);\n\n            // check against secretWord and update success if necessary\n            if (currentGuess === secretWord) setSuccess(true);\n\n            // clear input box\n            setCurrentGuess(\"\");\n          }}\n          className=\"btn btn-primary mb-2\"\n        >\n        {stringsModule.getStringByLanguage(language, 'submit')}\n        </button>\n      </form>\n    </div>\n  );\n}\n\nInput.propTypes = {\n  secretWord: PropTypes.string.isRequired,\n};\n\nexport default Input;\n"
  },
  {
    "path": "jotto-context/src/Input.test.js",
    "content": "import React from 'react';\nimport { mount } from 'enzyme';\n\nimport { findByTestAttr, checkProps } from '../test/testUtils';\nimport Input from './Input';\nimport languageContext from './contexts/languageContext';\nimport successContext from './contexts/successContext';\nimport guessedWordsContext from './contexts/guessedWordsContext';\n\n// mock entire module for destructuring useState on import //////\n// const mockSetCurrentGuess = jest.fn();\n// jest.mock('react', () => ({\n//   ...jest.requireActual('react'),\n//   useState: (initialState) => [initialState, mockSetCurrentGuess]\n// }))\n\n/**\n * create ReactWrapper for Input component for testing\n * @param {object} testValues - Context and props values for this specific test\n * @return {ReactWrapper} - Wrapper for Input component and providers\n */\nconst setup = ({ language, secretWord, success }) => {\n  language = language || 'en';\n  secretWord = secretWord || 'party';\n  success = success || false;\n\n  return mount(\n    <languageContext.Provider value={language}>\n      <successContext.SuccessProvider value={[success, jest.fn()]}>\n        <guessedWordsContext.GuessedWordsProvider>\n          <Input secretWord={secretWord} />\n        </guessedWordsContext.GuessedWordsProvider>\n      </successContext.SuccessProvider>\n    </languageContext.Provider>\n  );\n}\n\ndescribe('render', () => {\n  describe('success is false', () => {\n    let wrapper;\n    beforeEach(() => {\n      wrapper = setup({ success: false });\n    })\n    test('Input renders without error', () => {\n      const inputComponent = findByTestAttr(wrapper, 'component-input');\n      expect(inputComponent.length).toBe(1);\n    });\n    test('input box displays', () => {\n      const inputBox = findByTestAttr(wrapper, 'input-box');\n      expect(inputBox.exists()).toBe(true);\n    });\n    test('submit button displays', () => {\n      const submitButton = findByTestAttr(wrapper, 'submit-button');\n      expect(submitButton.exists()).toBe(true);\n    });\n  });\n  describe('success is true', () => {\n    let wrapper;\n    beforeEach(() => {\n      wrapper = setup({ success: true });\n    })\n    test('Input renders without error', () => {\n      const inputComponent = findByTestAttr(wrapper, 'component-input');\n      expect(inputComponent.length).toBe(1);\n    });\n    test('input box does not display', () => {\n      const inputBox = findByTestAttr(wrapper, 'input-box');\n      expect(inputBox.exists()).toBe(false);\n    });\n    test('submit button does not display', () => {\n      const submitButton = findByTestAttr(wrapper, 'submit-button');\n      expect(submitButton.exists()).toBe(false);\n    });\n  });\n});\n\ntest('does not throw warning with expected props', () => {\n  checkProps(Input, { secretWord: 'party' });\n})\n\ndescribe('state controlled input field', () => {\n  let mockSetCurrentGuess = jest.fn();\n  let wrapper;\n  let originalUseState;\n\n  beforeEach(() => {\n    mockSetCurrentGuess.mockClear();\n    originalUseState = React.useState;\n    React.useState = () => [\"\", mockSetCurrentGuess];\n    wrapper = setup({});\n  });\n  afterEach(() => {\n    React.useState = originalUseState;\n  });\n  test('state updates with value of input box upon change', () => {\n    const inputBox = findByTestAttr(wrapper, 'input-box');\n    const mockEvent = { target: { value: 'train' } };\n\n    inputBox.simulate(\"change\", mockEvent);\n    expect(mockSetCurrentGuess).toHaveBeenCalledWith('train');\n  });\n  test('field is cleared upon submit button click', () => {\n    const inputBox = findByTestAttr(wrapper, 'input-box');\n    const mockEvent = { target: { value: 'train' } };\n\n    inputBox.simulate(\"change\", mockEvent);\n    expect(mockSetCurrentGuess).toHaveBeenCalledWith('train');\n  });\n});\n\ndescribe('languagePicker', () => {\n  test('correctly renders submit string in english', () => {\n    const wrapper = setup({ language: \"en\" });\n    const submitButton = findByTestAttr(wrapper, 'submit-button');\n    expect(submitButton.text()).toBe('Submit');\n  });\n  test('correctly renders congrats string in emoji', () => {\n    const wrapper = setup({ language: \"emoji\" });\n    const submitButton = findByTestAttr(wrapper, 'submit-button');\n    expect(submitButton.text()).toBe('🚀');\n  });\n});\n"
  },
  {
    "path": "jotto-context/src/LanguagePicker.js",
    "content": "import React from 'react';\nimport propTypes from 'prop-types';\n\nfunction LanguagePicker({ setLanguage }) {\n  const languages = [\n    { code: 'en', symbol: '🇺🇸' },\n    { code: 'emoji', symbol: '😊' },\n  ];\n\n  const languageIcons = languages.map(lang =>\n    <span\n      data-test=\"language-icon\"\n      key={lang.code}\n      onClick={() => setLanguage(lang.code)}\n    >\n    {lang.symbol}\n    </span>\n  );\n\n  return (\n    <div data-test=\"component-language-picker\">\n      {languageIcons}\n    </div>\n  );\n}\n\nLanguagePicker.propTypes = {\n  setLanguage: propTypes.func.isRequired,\n}\n\nexport default LanguagePicker;\n"
  },
  {
    "path": "jotto-context/src/LanguagePicker.test.js",
    "content": "import React from 'react';\nimport { shallow } from 'enzyme';\n\nimport { findByTestAttr, checkProps } from '../test/testUtils';\nimport LanguagePicker from './LanguagePicker';\n\nconst mockSetLanguage = jest.fn();\n\nconst setup = () => {\n    return shallow(<LanguagePicker setLanguage={mockSetLanguage} />);\n}\n\ntest('renders without error', () => {\n  const wrapper = setup();\n  const component = findByTestAttr(wrapper, \"component-language-picker\");\n  expect(component.exists()).toBe(true);\n});\n\ntest('does not throw warning with expected props', () => {\n  checkProps(LanguagePicker, { setLanguage: jest.fn() });\n});\n\ntest('renders non-zero language icons', () => {\n  const wrapper = setup();\n  const languageIcons = findByTestAttr(wrapper, \"language-icon\");\n  expect(languageIcons.length).toBeGreaterThan(0);\n\n});\n\ntest('calls setLanguage prop upon click', () => {\n  const wrapper = setup();\n  const languageIcons = findByTestAttr(wrapper, \"language-icon\");\n\n  const firstIcon = languageIcons.first();\n  firstIcon.simulate(\"click\");\n\n  expect(mockSetLanguage).toHaveBeenCalled();\n});\n"
  },
  {
    "path": "jotto-context/src/actions/__mocks__/index.js",
    "content": "module.exports = {\n  ...jest.requireActual('..'),\n  __esModule: true,\n  // TODO: update return value for Redux / context implementation\n  getSecretWord: jest.fn().mockReturnValue(Promise.resolve('party')),\n}\n"
  },
  {
    "path": "jotto-context/src/actions/index.js",
    "content": "import axios from 'axios';\n\nexport const getSecretWord = async (setSecretWord) => {\n  const response = await axios.get('http://localhost:3030')\n  setSecretWord(response.data);\n}\n"
  },
  {
    "path": "jotto-context/src/actions/index.test.js",
    "content": "import moxios from 'moxios';\nimport { getSecretWord } from './';\n\ndescribe('getSecretWord', () => {\n  beforeEach(() => {\n    moxios.install();\n  });\n  afterEach(() => {\n    moxios.uninstall();\n  });\n  test('secretWord is returned', async () => {\n    moxios.wait(() => {\n      const request = moxios.requests.mostRecent();\n      request.respondWith({\n        status: 200,\n        response: 'party',\n      });\n    });\n\n    const mockSetSecretWord = jest.fn();\n    await getSecretWord(mockSetSecretWord);\n    expect(mockSetSecretWord).toHaveBeenCalledWith('party');\n  });\n});\n"
  },
  {
    "path": "jotto-context/src/contexts/guessedWordsContext.js",
    "content": "import React from 'react'\n\n// no default value\nconst guessedWordsContext = React.createContext();\n\n/**\n * @function useGuessedWords\n * @returns {Array} guessedWordsContext value, which is a state of [value, setter].\n *\n */\nexport function useGuessedWords() {\n  // useContext is a hook that returns the context value\n  // In this case, the context value is an [value, setter] array for the context state\n  // useContext also subscribes to changes, and will update any time the context value updates\n  //     we've memoized this so that it will only update when the guessedWords value updates\n  const context = React.useContext(guessedWordsContext)\n\n  // throw an error if the context doesn't exist -- means we aren't in a provider\n  if (!context) {\n    throw new Error('useGuessedWords must be used within a GuessedWordsProvider')\n  }\n\n  // otherwise return the context\n  return context\n}\n\n/**\n * @function GuessedWordsProvider\n * @param {object} props - props to pass through from declared component\n * @returns {JSX.Element} Provider component\n */\nexport function GuessedWordsProvider(props) {\n  // create state that will be used within the provider\n  // initial state value is false\n  const [guessedWords, setGuessedWords] = React.useState([])\n\n  // value for the context provider will be array of [value, setter] for guessedWords state\n  // useMemo just ensures that the provider value will only update when guessedWords updates\n  // No need to test this -- React tests useMemo for us!\n  const value = React.useMemo(() => [guessedWords, setGuessedWords], [guessedWords])\n\n  // Return a Provider component with the [value, setter] array as the value, passing through the props\n  return <guessedWordsContext.Provider value={value} {...props} />\n}\n\nexport default { GuessedWordsProvider, useGuessedWords }\n"
  },
  {
    "path": "jotto-context/src/contexts/guessedWordsContext.test.js",
    "content": "import React from 'react';\nimport { shallow } from 'enzyme';\n\nimport { GuessedWordsProvider, useGuessedWords } from './GuessedWordsContext';\n\n// a functional component that calls useGuessedWords for our tests\nconst FunctionalComponent = () => {\n  useGuessedWords();\n  return <div />;\n}\n\ntest('useGuessedWords throws error when not wrapped in GuessedWordsProvider', () => {\n  expect(() => {\n    shallow(<FunctionalComponent />)\n  }).toThrow('useGuessedWords must be used within a GuessedWordsProvider');\n});\n\ntest('useGuessedWords does not throw error when wrapped in GuessedWordsProvider', () => {\n  expect(() => {\n    shallow(\n      <GuessedWordsProvider>\n        <FunctionalComponent />\n      </GuessedWordsProvider>\n    )\n  }).not.toThrow()\n});\n"
  },
  {
    "path": "jotto-context/src/contexts/languageContext.js",
    "content": "import React from 'react';\n\nexport default React.createContext('en');\n"
  },
  {
    "path": "jotto-context/src/contexts/successContext.js",
    "content": "import React from 'react';\n\nconst successContext = React.createContext();\n\n\n/**\n* @function useSuccess\n* @returns {array} successContext value, which is a state of [value, setter].\n*\n*/\nfunction useSuccess() {\n  const context = React.useContext(successContext);\n\n  if(!context) {\n    throw new Error('useSuccess must be used within a SuccessProvider');\n  }\n\n  return context;\n}\n\n/**\n* @function SuccessProvider\n* @param {object} props - props to pass through from declared component\n* @returns {JSX.Element} Provider component\n*/\nfunction SuccessProvider(props) {\n    const [success, setSuccess] = React.useState(false);\n\n    const value = React.useMemo(() => [success, setSuccess], [success]);\n\n    return <successContext.Provider value={value} {...props} />\n}\n\nexport default { SuccessProvider, useSuccess }\n"
  },
  {
    "path": "jotto-context/src/contexts/successContext.test.js",
    "content": "import React from 'react';\nimport { shallow, mount } from 'enzyme';\n\nimport successContext from './successContext';\n\n// a functional component that calls useSuccess for our tests\nconst FunctionalComponent = () => {\n  successContext.useSuccess();\n  return <div />;\n}\n\ntest('useSuccess throws error when not wrapped in SuccessProvider', () => {\n  expect(() => {\n    shallow(<FunctionalComponent />);\n  }).toThrow('useSuccess must be used within a SuccessProvider');\n});\n\ntest('useSuccess does not throw error when wrapped in SuccessProvider', () => {\n  expect(() => {\n    mount(\n      <successContext.SuccessProvider>\n        <FunctionalComponent />\n      </successContext.SuccessProvider>\n    )\n  }).not.toThrow();\n})\n"
  },
  {
    "path": "jotto-context/src/guessWord.test.js",
    "content": "import React from 'react';\nimport { mount } from 'enzyme';\n\nimport App from './App';\nimport { findByTestAttr } from '../test/testUtils.js';\n\nimport successContext from './contexts/successContext';\nimport guessedWordsContext from './contexts/guessedWordsContext';\n\nimport Congrats from './Congrats';\nimport Input from './Input';\nimport GuessedWords from './GuessedWords';\n\n/**\n * Create wrapper with specified initial conditions,\n * then submit a guessed word of 'train'\n # @function\n *\n * @param {object} state - Initial conditions.\n * @returns {Wrapper} - Enzyme wrapper of mounted App component\n */\nconst setup = ({ secretWord, guessedWords, success }) => {\n\n  const wrapper = mount(\n    <guessedWordsContext.GuessedWordsProvider>\n      <successContext.SuccessProvider>\n        <Congrats />\n        <Input secretWord={secretWord} />\n        <GuessedWords />\n      </successContext.SuccessProvider>\n    </guessedWordsContext.GuessedWordsProvider>\n  );\n\n  // add value to input box\n  const inputBox = findByTestAttr(wrapper, 'input-box');\n  inputBox.simulate('change', { target: { value: 'train' } });\n\n  // simulate click on submit button\n  const submitButton = findByTestAttr(wrapper, 'submit-button');\n  submitButton.simulate('click', { preventDefault() {} });\n\n  guessedWords.map(guess => {\n    const mockEvent = { target: { value: guess.guessedWord } };\n    inputBox.simulate('change', mockEvent);\n    submitButton.simulate('click', { preventDefault() {} });\n  })\n\n  return wrapper;\n}\n\ndescribe('no words guessed', () => {\n  let wrapper;\n  beforeEach(() => {\n    wrapper = setup({\n      secretWord: 'party',\n      success: false,\n      guessedWords: []\n    });\n  });\n  test('creates GuessedWords table with one row', () => {\n    const guessedWordRows = findByTestAttr(wrapper, 'guessed-word');\n    expect(guessedWordRows).toHaveLength(1);\n  });\n});\n\ndescribe('some words guessed', () => {\n  let wrapper;\n  beforeEach(() => {\n  \twrapper = setup({\n    \tsecretWord: 'party',\n    \tsuccess: false,\n    \tguessedWords: [{ guessedWord: 'agile', letterMatchCount: 1 }],\n  \t});\n  });\n  test('adds row to guessedWords table', () => {\n    const guessedWordNodes = findByTestAttr(wrapper, 'guessed-word');\n    expect(guessedWordNodes).toHaveLength(2);\n  });\n});\n\ndescribe('guess secret word', () => {\n  let wrapper;\n  beforeEach(() => {\n  \twrapper = setup({\n    \tsecretWord: 'party',\n    \tsuccess: false,\n    \tguessedWords: [{ guessedWord: 'agile', letterMatchCount: 1 }],\n  \t});\n\n    // add value to input box\n    const inputBox = findByTestAttr(wrapper, 'input-box');\n    const mockEvent = { target: { value: 'party' } };\n    inputBox.simulate('change', mockEvent);\n\n  \t// simulate click on submit button\n  \tconst submitButton = findByTestAttr(wrapper, 'submit-button');\n  \tsubmitButton.simulate('click', { preventDefault() {} });\n  });\n  test('adds row to guessedWords table', () => {\n  \tconst guessedWordNodes = findByTestAttr(wrapper, 'guessed-word');\n  \texpect(guessedWordNodes).toHaveLength(3);\n  });\n  test('displays congrats component', () => {\n  \tconst congrats = findByTestAttr(wrapper, 'component-congrats');\n  \texpect(congrats.text().length).toBeGreaterThan(0);\n  });\n  test('does not display input component contents', () => {\n    const inputBox = findByTestAttr(wrapper, \"input-box\");\n    expect(inputBox.exists()).toBe(false);\n\n    const submitButton = findByTestAttr(wrapper, \"submit-button\");\n    expect(submitButton.exists()).toBe(false);\n  });\n});\n"
  },
  {
    "path": "jotto-context/src/helpers/index.js",
    "content": "/**\n * @method getLetterMatchCount\n * @param {string} guessedWord - Guessed word.\n * @param {string} secretWord - Secret word.\n * @returns {number} - Number of letters matched between guessed word and secret word.\n */\n export function getLetterMatchCount(guessedWord, secretWord) {\n   const secretLetters = secretWord.split('');\n   const guessedLetterSet = new Set(guessedWord);\n   return secretLetters.filter(letter => guessedLetterSet.has(letter)).length;\n };\n"
  },
  {
    "path": "jotto-context/src/helpers/index.test.js",
    "content": "import { getLetterMatchCount } from './';\n\ndescribe('getLetterMatchCount', () => {\n  const secretWord = 'party';\n  test('returns correct count when there are no matching letters', () => {\n    const letterMatchCount = getLetterMatchCount('bones', secretWord);\n    expect(letterMatchCount).toBe(0);\n  });\n  test('returns the correct count when there are three matching letters', () => {\n    const letterMatchCount = getLetterMatchCount('train', secretWord);\n    expect(letterMatchCount).toBe(3);\n  });\n  test('returns the correct count when there are duplicate letters in the guess', () => {\n    const letterMatchCount = getLetterMatchCount('parka', secretWord);\n    expect(letterMatchCount).toBe(3);\n  });\n});\n"
  },
  {
    "path": "jotto-context/src/helpers/strings.js",
    "content": "const languageStrings = {\n  en: {\n   congrats: 'Congratulations! You guessed the word!',\n   submit: 'Submit',\n   guessPrompt: 'Try to guess the secret word!',\n   guessInputPlaceholder: 'enter guess',\n   guessColumnHeader: 'Guessed Words',\n   guessedWords: 'Guesses',\n   matchingLettersColumnHeader: 'Matching Letters',\n  },\n  emoji: {\n   congrats: '🎯🎉',\n   submit: '🚀',\n   guessPrompt: '🤔🤫🔤',\n   guessInputPlaceholder: '⌨️🤔',\n   guessedWords: '🤷‍🔤',\n   guessColumnHeader: '🤷‍',\n   matchingLettersColumnHeader: '✅',\n  }\n}\n\nfunction getStringByLanguage(languageCode, stringKey, strings=languageStrings) {\n  if (!strings[languageCode] || !strings[languageCode][stringKey]) {\n    console.warn(`Could not get string [${stringKey}] for [${languageCode}]`);\n\n    // fall back to english\n    return strings.en[stringKey];\n  }\n\n  return strings[languageCode][stringKey];\n}\n\n// for future mocking\nexport default {\n  getStringByLanguage,\n}\n"
  },
  {
    "path": "jotto-context/src/helpers/strings.test.js",
    "content": "import stringsModule from './strings';\nconst { getStringByLanguage } = stringsModule;\n\nconst strings = {\n  en: { submit: 'submit' },\n  emoji: { submit: '🚀' },\n  mermish: {},\n}\n\ndescribe('language string testing', () => {\n  const mockWarn = jest.fn();\n  let originalWarn;\n\n  beforeEach(() => {\n    originalWarn = console.warn;\n    console.warn = mockWarn;\n  });\n\n  afterEach(() => {\n    console.warn = originalWarn;\n  });\n\n  test('returns correct submit string for english', () => {\n    const string = getStringByLanguage('en', 'submit', strings);\n    expect(string).toBe('submit');\n    expect(mockWarn).not.toHaveBeenCalled();\n  });\n  test('returns the correct submit string for emoji', () => {\n    const string = getStringByLanguage('emoji', 'submit', strings);\n    expect(string).toBe('🚀');\n    expect(mockWarn).not.toHaveBeenCalled();\n  });\n  test('returns english submit string when language does not exist', () => {\n    const string = getStringByLanguage('notALanguage', 'submit', strings);\n    expect(string).toBe('submit');\n    expect(mockWarn).toHaveBeenCalledWith(\"Could not get string [submit] for [notALanguage]\");\n  });\n  test('returns english submit string when submit key does not exist for language', () => {\n    const string = getStringByLanguage('mermish', 'submit', strings);\n    expect(string).toBe('submit');\n    expect(mockWarn).toHaveBeenCalledWith(\"Could not get string [submit] for [mermish]\");\n  });\n});\n"
  },
  {
    "path": "jotto-context/src/index.css",
    "content": "body {\n  margin: 0;\n  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',\n    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',\n    sans-serif;\n  -webkit-font-smoothing: antialiased;\n  -moz-osx-font-smoothing: grayscale;\n}\n\ncode {\n  font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',\n    monospace;\n}\n"
  },
  {
    "path": "jotto-context/src/index.js",
    "content": "import React from 'react';\nimport ReactDOM from 'react-dom';\nimport './index.css';\nimport App from './App';\nimport reportWebVitals from './reportWebVitals';\n\nReactDOM.render(\n  <React.StrictMode>\n    <App />\n  </React.StrictMode>,\n  document.getElementById('root')\n);\n\n// If you want to start measuring performance in your app, pass a function\n// to log results (for example: reportWebVitals(console.log))\n// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals\nreportWebVitals();\n"
  },
  {
    "path": "jotto-context/src/reportWebVitals.js",
    "content": "const reportWebVitals = onPerfEntry => {\n  if (onPerfEntry && onPerfEntry instanceof Function) {\n    import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {\n      getCLS(onPerfEntry);\n      getFID(onPerfEntry);\n      getFCP(onPerfEntry);\n      getLCP(onPerfEntry);\n      getTTFB(onPerfEntry);\n    });\n  }\n};\n\nexport default reportWebVitals;\n"
  },
  {
    "path": "jotto-context/src/setupTests.js",
    "content": "import Enzyme from 'enzyme';\nimport EnzymeAdapter from '@wojtekmaj/enzyme-adapter-react-17';\n\nEnzyme.configure({ adapter: new EnzymeAdapter() });\n"
  },
  {
    "path": "jotto-context/test/testUtils.js",
    "content": "import checkPropTypes from 'check-prop-types';\n\n/**\n * Return node(s) with the given data-test attribute.\n * @param {ShallowWrapper} wrapper - Enzyme shallow wrapper.\n * @param {string} val - Value of data-test attribute for search.\n * @returns {ShallowWrapper}\n */\nexport const findByTestAttr = (wrapper, val) => {\n  return wrapper.find(`[data-test=\"${val}\"]`);\n}\n\n\n/**\n * Assert that expected conforming props conform to propTypes definiton.\n * @param {React.Component} component - React component.\n * @param {object} conformingProps - Object of conforming props.\n * @returns {undefined} - Throws error if props do not conform.\n */\nexport const checkProps = (component, conformingProps) => {\n  const propError = checkPropTypes(\n    component.propTypes,\n    conformingProps,\n    'prop',\n    component.name);\n  expect(propError).toBeUndefined();\n}\n"
  },
  {
    "path": "jotto-redux-hooks/.gitignore",
    "content": "# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.\n\n# dependencies\n/node_modules\n/.pnp\n.pnp.js\n\n# testing\n/coverage\n\n# production\n/build\n\n# misc\n.DS_Store\n.env.local\n.env.development.local\n.env.test.local\n.env.production.local\n\nnpm-debug.log*\nyarn-debug.log*\nyarn-error.log*\n"
  },
  {
    "path": "jotto-redux-hooks/.npmrc",
    "content": "fund=false\naudit=false\nloglevel=error\n"
  },
  {
    "path": "jotto-redux-hooks/README.md",
    "content": "# Getting Started with Create React App\n\nThis project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).\n\n## Available Scripts\n\nIn the project directory, you can run:\n\n### `npm start`\n\nRuns the app in the development mode.\\\nOpen [http://localhost:3000](http://localhost:3000) to view it in the browser.\n\nThe page will reload if you make edits.\\\nYou will also see any lint errors in the console.\n\n### `npm test`\n\nLaunches the test runner in the interactive watch mode.\\\nSee the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.\n\n### `npm run build`\n\nBuilds the app for production to the `build` folder.\\\nIt correctly bundles React in production mode and optimizes the build for the best performance.\n\nThe build is minified and the filenames include the hashes.\\\nYour app is ready to be deployed!\n\nSee the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.\n\n### `npm run eject`\n\n**Note: this is a one-way operation. Once you `eject`, you can’t go back!**\n\nIf you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.\n\nInstead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.\n\nYou don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.\n\n## Learn More\n\nYou can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).\n\nTo learn React, check out the [React documentation](https://reactjs.org/).\n\n### Code Splitting\n\nThis section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)\n\n### Analyzing the Bundle Size\n\nThis section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)\n\n### Making a Progressive Web App\n\nThis section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)\n\n### Advanced Configuration\n\nThis section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)\n\n### Deployment\n\nThis section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)\n\n### `npm run build` fails to minify\n\nThis section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)\n"
  },
  {
    "path": "jotto-redux-hooks/package.json",
    "content": "{\n  \"name\": \"jotto\",\n  \"version\": \"0.1.0\",\n  \"private\": true,\n  \"dependencies\": {\n    \"@testing-library/jest-dom\": \"^5.11.9\",\n    \"@testing-library/react\": \"^11.2.5\",\n    \"@testing-library/user-event\": \"^12.8.3\",\n    \"axios\": \"^0.21.1\",\n    \"react\": \"^17.0.1\",\n    \"react-dom\": \"^17.0.1\",\n    \"react-redux\": \"^7.2.2\",\n    \"react-scripts\": \"4.0.3\",\n    \"redux\": \"^4.0.5\",\n    \"redux-thunk\": \"^2.3.0\",\n    \"web-vitals\": \"^1.1.0\"\n  },\n  \"scripts\": {\n    \"start\": \"react-scripts start\",\n    \"build\": \"react-scripts build\",\n    \"test\": \"react-scripts test\",\n    \"eject\": \"react-scripts eject\"\n  },\n  \"eslintConfig\": {\n    \"extends\": [\n      \"react-app\",\n      \"react-app/jest\"\n    ]\n  },\n  \"browserslist\": {\n    \"production\": [\n      \">0.2%\",\n      \"not dead\",\n      \"not op_mini all\"\n    ],\n    \"development\": [\n      \"last 1 chrome version\",\n      \"last 1 firefox version\",\n      \"last 1 safari version\"\n    ]\n  },\n  \"devDependencies\": {\n    \"@wojtekmaj/enzyme-adapter-react-17\": \"^0.4.1\",\n    \"check-prop-types\": \"^1.1.2\",\n    \"enzyme\": \"^3.11.0\",\n    \"moxios\": \"^0.4.0\"\n  },\n  \"jest\": {\n    \"resetMocks\": false\n  }\n}\n"
  },
  {
    "path": "jotto-redux-hooks/public/index.html",
    "content": "<!DOCTYPE html>\n<html lang=\"en\">\n  <head>\n    <meta charset=\"utf-8\" />\n    <link rel=\"icon\" href=\"%PUBLIC_URL%/favicon.ico\" />\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n    <meta name=\"theme-color\" content=\"#000000\" />\n    <meta\n      name=\"description\"\n      content=\"Web site created using create-react-app\"\n    />\n    <link rel=\"apple-touch-icon\" href=\"%PUBLIC_URL%/logo192.png\" />\n    <!--\n      manifest.json provides metadata used when your web app is installed on a\n      user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/\n    -->\n    <link rel=\"manifest\" href=\"%PUBLIC_URL%/manifest.json\" />\n    <!--\n      Notice the use of %PUBLIC_URL% in the tags above.\n      It will be replaced with the URL of the `public` folder during the build.\n      Only files inside the `public` folder can be referenced from the HTML.\n\n      Unlike \"/favicon.ico\" or \"favicon.ico\", \"%PUBLIC_URL%/favicon.ico\" will\n      work correctly both with client-side routing and a non-root public URL.\n      Learn how to configure a non-root public URL by running `npm run build`.\n    -->\n    <link href=\"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css\" rel=\"stylesheet\" integrity=\"sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T\" crossorigin=\"anonymous\">\n    <script src=\"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js\" integrity=\"sha384-xrRywqdh3PHs8keKZN+8zzc5TX0GRTLCcmivcbNJWm2rs5C8PRhcEn3czEjhAO9o\" crossorigin=\"anonymous\"></script>\n    <title>React App</title>\n  </head>\n  <body>\n    <noscript>You need to enable JavaScript to run this app.</noscript>\n    <div id=\"root\"></div>\n    <!--\n      This HTML file is a template.\n      If you open it directly in the browser, you will see an empty page.\n\n      You can add webfonts, meta tags, or analytics to this file.\n      The build step will place the bundled scripts into the <body> tag.\n\n      To begin the development, run `npm start` or `yarn start`.\n      To create a production bundle, use `npm run build` or `yarn build`.\n    -->\n  </body>\n</html>\n"
  },
  {
    "path": "jotto-redux-hooks/public/manifest.json",
    "content": "{\n  \"short_name\": \"React App\",\n  \"name\": \"Create React App Sample\",\n  \"icons\": [\n    {\n      \"src\": \"favicon.ico\",\n      \"sizes\": \"64x64 32x32 24x24 16x16\",\n      \"type\": \"image/x-icon\"\n    },\n    {\n      \"src\": \"logo192.png\",\n      \"type\": \"image/png\",\n      \"sizes\": \"192x192\"\n    },\n    {\n      \"src\": \"logo512.png\",\n      \"type\": \"image/png\",\n      \"sizes\": \"512x512\"\n    }\n  ],\n  \"start_url\": \".\",\n  \"display\": \"standalone\",\n  \"theme_color\": \"#000000\",\n  \"background_color\": \"#ffffff\"\n}\n"
  },
  {
    "path": "jotto-redux-hooks/public/robots.txt",
    "content": "# https://www.robotstxt.org/robotstxt.html\nUser-agent: *\nDisallow:\n"
  },
  {
    "path": "jotto-redux-hooks/src/App.css",
    "content": ".App {\n  text-align: center;\n}\n\n.App-logo {\n  height: 40vmin;\n  pointer-events: none;\n}\n\n@media (prefers-reduced-motion: no-preference) {\n  .App-logo {\n    animation: App-logo-spin infinite 20s linear;\n  }\n}\n\n.App-header {\n  background-color: #282c34;\n  min-height: 100vh;\n  display: flex;\n  flex-direction: column;\n  align-items: center;\n  justify-content: center;\n  font-size: calc(10px + 2vmin);\n  color: white;\n}\n\n.App-link {\n  color: #61dafb;\n}\n\n@keyframes App-logo-spin {\n  from {\n    transform: rotate(0deg);\n  }\n  to {\n    transform: rotate(360deg);\n  }\n}\n"
  },
  {
    "path": "jotto-redux-hooks/src/App.js",
    "content": "import { useEffect } from \"react\";\nimport { useSelector, useDispatch } from \"react-redux\";\nimport \"./App.css\";\n\nimport Congrats from \"./Congrats\";\nimport GuessedWords from \"./GuessedWords\";\nimport Input from \"./Input\";\nimport { getSecretWord } from \"./actions\";\n\nfunction App() {\n  const success = useSelector((state) => state.success);\n  const guessedWords = useSelector((state) => state.guessedWords);\n  const secretWord = useSelector((state) => state.secretWord);\n\n  // so that we can dispatch an action\n  const dispatch = useDispatch();\n\n  useEffect(() => {\n    // get the secret word\n    dispatch(getSecretWord());\n  }, []);\n\n  return (\n    <div data-test=\"component-app\" className=\"container\">\n      <h1>Jotto</h1>\n      <Congrats success={success} />\n      <Input success={success} secretWord={secretWord} />\n      <GuessedWords guessedWords={guessedWords} />\n    </div>\n  );\n}\n\nexport default App;\n"
  },
  {
    "path": "jotto-redux-hooks/src/App.test.js",
    "content": "import React from \"react\";\nimport { mount } from \"enzyme\";\nimport { Provider } from \"react-redux\";\n\nimport { findByTestAttr, storeFactory } from \"../test/testUtils\";\nimport App from \"./App\";\n\n// activate global mock to make sure getSecretWord doesn't make network call\njest.mock(\"./actions\");\nimport { getSecretWord as mockGetSecretWord } from \"./actions\";\n\n/**\n * Setup function for App component\n * @returns {Wrapper}\n */\nconst setup = () => {\n  const store = storeFactory();\n  return mount(\n    <Provider store={store}>\n      <App />\n    </Provider>\n  );\n};\n\ntest(\"renders without error\", () => {\n  const wrapper = setup();\n  const appComponent = findByTestAttr(wrapper, \"component-app\");\n  expect(appComponent).toHaveLength(1);\n});\n\ndescribe(\"get secret word\", () => {\n  beforeEach(() => {\n    mockGetSecretWord.mockClear();\n  });\n  test(\"getSecretWord runs on app mount\", () => {\n    const wrapper = setup();\n    expect(mockGetSecretWord).toHaveBeenCalledTimes(1);\n  });\n  test(\"getSecretWord does not run on app update\", () => {\n    const wrapper = setup();\n    mockGetSecretWord.mockClear();\n\n    // using setProps because wrapper.update() doesn't trigger useEffect\n    // https://github.com/enzymejs/enzyme/issues/2254\n    wrapper.setProps();\n\n    expect(mockGetSecretWord).toHaveBeenCalledTimes(0);\n  });\n});\n"
  },
  {
    "path": "jotto-redux-hooks/src/Congrats.js",
    "content": "import React from 'react';\nimport PropTypes from 'prop-types';\n\n/**\n * Functional react component for congratulatory message.\n * @function\n * @param {object} props - React props.\n * @returns {JSX.Element} - Rendered component (or null if `success` prop is false).\n */\nconst Congrats = (props) => {\n  if (props.success) {\n    return (\n      <div data-test=\"component-congrats\" className=\"alert alert-success\">\n        <span data-test=\"congrats-message\">\n          Congratulations! You guessed the word!\n        </span>\n      </div>\n    );\n  } else {\n    return (\n      <div data-test=\"component-congrats\" />\n    );\n  }\n};\n\nCongrats.propTypes = {\n  success: PropTypes.bool.isRequired,\n};\n\nexport default Congrats;\n"
  },
  {
    "path": "jotto-redux-hooks/src/Congrats.test.js",
    "content": "import React from 'react';\nimport { shallow } from 'enzyme';\n\nimport { findByTestAttr, checkProps } from '../test/testUtils';\nimport Congrats from './Congrats';\n\nconst defaultProps = { success: false };\n\n/**\n* Factory function to create a ShallowWrapper for the Congrats component.\n* @function setup\n* @param {object} props - Component props specific to this setup.\n* @returns {ShallowWrapper}\n*/\nconst setup = (props={}) => {\n  const setupProps = { ...defaultProps, ...props };\n  return shallow(<Congrats {...setupProps} />)\n}\n\ntest('renders without error', () => {\n  const wrapper = setup();\n  const component = findByTestAttr(wrapper, 'component-congrats');\n  expect(component.length).toBe(1);\n});\ntest('renders no text when `success` prop is false', () => {\n  const wrapper = setup({ success: false });\n  const component = findByTestAttr(wrapper, 'component-congrats');\n  expect(component.text()).toBe('');\n});\ntest('renders non-empty congrats message when `success` prop is true', () => {\n  const wrapper = setup({ success: true });\n  const message = findByTestAttr(wrapper, 'congrats-message');\n  expect(message.text().length).not.toBe(0);\n});\ntest('does not throw warning with expected props', () => {\n  const expectedProps = { success: false };\n  checkProps(Congrats, expectedProps);\n});\n"
  },
  {
    "path": "jotto-redux-hooks/src/GuessedWords.js",
    "content": "import React from 'react';\nimport PropTypes from 'prop-types';\n\nconst GuessedWords = (props) => {\n  let contents\n  if (props.guessedWords.length === 0) {\n    contents = (\n      <span data-test=\"guess-instructions\">\n        Try to guess the secret word!\n      </span>\n    );\n  } else {\n    const guessedWordsRows = props.guessedWords.map((word, index) => (\n      <tr data-test=\"guessed-word\" key={ index }>\n        <td>{ word.guessedWord }</td>\n        <td>{ word.letterMatchCount }</td>\n      </tr>\n    ));\n    contents = (\n      <div data-test=\"guessed-words\">\n        <h3>Guessed Words</h3>\n        <table className=\"table table-sm\">\n          <thead className=\"thead-light\">\n            <tr><th>Guess</th><th>Matching Letters</th></tr>\n          </thead>\n          <tbody>\n            { guessedWordsRows }\n          </tbody>\n        </table>\n      </div>\n    );\n  }\n  return (\n    <div data-test=\"component-guessed-words\">\n      { contents }\n    </div>\n  );\n};\n\nGuessedWords.propTypes = {\n  guessedWords: PropTypes.arrayOf(\n    PropTypes.shape({\n      guessedWord: PropTypes.string.isRequired,\n      letterMatchCount: PropTypes.number.isRequired,\n    })\n  ).isRequired,\n};\n\nexport default GuessedWords;\n"
  },
  {
    "path": "jotto-redux-hooks/src/GuessedWords.test.js",
    "content": "import React from 'react';\nimport { shallow } from 'enzyme';\nimport { findByTestAttr, checkProps } from '../test/testUtils';\nimport GuessedWords from './GuessedWords';\n\nconst defaultProps = {\n  guessedWords: [{ guessedWord: 'train', letterMatchCount: 3 }],\n};\n\n/**\n* Factory function to create a ShallowWrapper for the GuessedWords component.\n* @function setup\n* @param {object} props - Component props specific to this setup.\n* @returns {ShallowWrapper}\n*/\nconst setup = (props={}) => {\n  const setupProps = { ...defaultProps, ...props };\n  return shallow(<GuessedWords {...setupProps } />)\n};\n\ntest('does not throw warning with expected props', () => {\n  checkProps(GuessedWords, defaultProps);\n});\n\ndescribe('if there are no words guessed', () => {\n  let wrapper\n  beforeEach(() => {\n    wrapper = setup({ guessedWords: [] });\n  });\n  test('renders without error', () => {\n    const component = findByTestAttr(wrapper, 'component-guessed-words');\n    expect(component.length).toBe(1);\n  });\n  test('renders instructions to guess a word', () => {\n    const instructions = findByTestAttr(wrapper, 'guess-instructions');\n    expect(instructions.text().length).not.toBe(0);\n  });\n});\ndescribe('if there are words guessed', () => {\n  let wrapper;\n  const guessedWords = [\n    { guessedWord: 'train', letterMatchCount: 3 },\n    { guessedWord: 'agile', letterMatchCount: 1 },\n    { guessedWord: 'party', letterMatchCount: 5 },\n  ];\n  beforeEach(() => {\n    wrapper = setup({ guessedWords });\n  });\n  test ('renders without error', () => {\n    const component = findByTestAttr(wrapper, 'component-guessed-words');\n    expect(component.length).toBe(1);\n  });\n  test('renders \"guessed words\" section', () => {\n    const guessedWordsNode = findByTestAttr(wrapper, 'guessed-words');\n    expect(guessedWordsNode.length).toBe(1);\n  });\n  test('correct number of guessed words', () => {\n    const guessedWordNodes = findByTestAttr(wrapper, 'guessed-word');\n    expect(guessedWordNodes.length).toBe(guessedWords.length);\n  });\n});\n"
  },
  {
    "path": "jotto-redux-hooks/src/Input.js",
    "content": "import React from 'react';\nimport PropTypes from 'prop-types';\nimport { useSelector, useDispatch } from 'react-redux';\n\nimport { guessWord } from './actions';\n\nfunction Input({ secretWord }) {\n  const [currentGuess, setCurrentGuess] = React.useState(\"\");\n  const dispatch = useDispatch();\n  const success = useSelector(state => state.success);\n\n  if (success) {\n    return <div data-test='component-input' />\n  }\n\n  return (\n    <div data-test='component-input'>\n      <form className=\"form-inline\">\n        <input\n          data-test=\"input-box\"\n          className=\"mb-2 mx-sm-3\"\n          type=\"text\"\n          placeholder=\"enter guess\"\n          value={currentGuess}\n          onChange={(event) => setCurrentGuess(event.target.value)}\n        />\n        <button\n          data-test=\"submit-button\"\n          onClick={(evt) => {\n            evt.preventDefault();\n            dispatch(guessWord(currentGuess));\n            setCurrentGuess(\"\");\n          }}\n          className=\"btn btn-primary mb-2\"\n        >\n        Submit\n        </button>\n      </form>\n    </div>\n  );\n}\n\nInput.propTypes = {\n  secretWord: PropTypes.string.isRequired,\n};\n\nexport default Input;\n"
  },
  {
    "path": "jotto-redux-hooks/src/Input.test.js",
    "content": "import React from 'react';\nimport { mount } from 'enzyme';\nimport { findByTestAttr, checkProps, storeFactory } from '../test/testUtils';\nimport { Provider } from 'react-redux';\n\nimport Input from './Input';\n\n// mock entire module for destructuring useState on import //////\n// const mockSetCurrentGuess = jest.fn();\n// jest.mock('react', () => ({\n//   ...jest.requireActual('react'),\n//   useState: (initialState) => [initialState, mockSetCurrentGuess]\n// }))\n\nconst setup = (initialState={}, secretWord='party') => {\n  const store = storeFactory(initialState);\n  return mount(<Provider store={store}><Input secretWord={secretWord} /></Provider>);\n}\n\ndescribe('render', () => {\n  describe('success is false', () => {\n    let wrapper;\n    beforeEach(() => {\n      wrapper = setup({ success: false });\n    })\n    test('Input renders without error', () => {\n      const inputComponent = findByTestAttr(wrapper, 'component-input');\n      expect(inputComponent.length).toBe(1);\n    });\n    test('input box displays', () => {\n      const inputBox = findByTestAttr(wrapper, 'input-box');\n      expect(inputBox.exists()).toBe(true);\n    });\n    test('submit button displays', () => {\n      const submitButton = findByTestAttr(wrapper, 'submit-button');\n      expect(submitButton.exists()).toBe(true);\n    });\n  });\n  describe('success is true', () => {\n    let wrapper;\n    beforeEach(() => {\n      wrapper = setup({ success: true });\n    })\n    test('Input renders without error', () => {\n      const inputComponent = findByTestAttr(wrapper, 'component-input');\n      expect(inputComponent.length).toBe(1);\n    });\n    test('input box does not display', () => {\n      const inputBox = findByTestAttr(wrapper, 'input-box');\n      expect(inputBox.exists()).toBe(false);\n    });\n    test('submit button does not display', () => {\n      const submitButton = findByTestAttr(wrapper, 'submit-button');\n      expect(submitButton.exists()).toBe(false);\n    });\n  });\n});\n\ntest('does not throw warning with expected props', () => {\n  checkProps(Input, { secretWord: 'party' });\n})\n\ndescribe('state controlled input field', () => {\n  let mockSetCurrentGuess = jest.fn();\n  let wrapper;\n\n  beforeEach(() => {\n    mockSetCurrentGuess.mockClear();\n    React.useState = () => [\"\", mockSetCurrentGuess];\n    wrapper = setup({ success: false });\n  });\n  test('state updates with value of input box upon change', () => {\n    const inputBox = findByTestAttr(wrapper, 'input-box');\n    const mockEvent = { target: { value: 'train' } };\n\n    inputBox.simulate(\"change\", mockEvent);\n    expect(mockSetCurrentGuess).toHaveBeenCalledWith('train');\n  });\n  test('field is cleared upon submit button click', () => {\n    const inputBox = findByTestAttr(wrapper, 'input-box');\n    const mockEvent = { target: { value: 'train' } };\n\n    inputBox.simulate(\"change\", mockEvent);\n    expect(mockSetCurrentGuess).toHaveBeenCalledWith('train');\n  });\n})\n"
  },
  {
    "path": "jotto-redux-hooks/src/actions/__mocks__/index.js",
    "content": "module.exports = {\n  ...jest.requireActual(\"..\"),\n  __esModule: true,\n  getSecretWord: jest.fn().mockReturnValue({ type: \"mock\" }),\n};\n"
  },
  {
    "path": "jotto-redux-hooks/src/actions/index.js",
    "content": "import { getLetterMatchCount } from '../helpers';\nimport axios from 'axios';\n\nexport const actionTypes = {\n  CORRECT_GUESS: 'CORRECT_GUESS',\n  GUESS_WORD: 'GUESS_WORD',\n  SET_SECRET_WORD: 'SET_SECRET_WORD',\n};\n\n/**\n * Returns Redux Thunk function that dispatches GUESS_WORD action\n *     and (conditionally) CORRECT_GUESS action\n * @function guessWord\n * @param {string} guessedWord - Guessed word.\n * @returns {function} - Redux Thunk function.\n*/\nexport const guessWord = (guessedWord) => {\n  return function(dispatch, getState) {\n    const secretWord = getState().secretWord;\n    const letterMatchCount = getLetterMatchCount(guessedWord, secretWord);\n\n    dispatch({\n      type: actionTypes.GUESS_WORD,\n      payload: { guessedWord, letterMatchCount }\n    });\n\n    if (guessedWord === secretWord) {\n      dispatch({ type: actionTypes.CORRECT_GUESS });\n    }\n  };\n};\n\n/**\n * Returns Redux Thunk function that initiates an axios request\n *    and dispatches the response as a 'SET_SECRET_WORD' action\n * @returns {function} - Redux Thunk function.\n */\nexport const getSecretWord = () => {\n  return function(dispatch) {\n    return axios.get('http://localhost:3030')\n      .then(response => {\n        dispatch({\n          type: actionTypes.SET_SECRET_WORD,\n          payload: response.data\n        })\n      });\n  }\n}\n"
  },
  {
    "path": "jotto-redux-hooks/src/actions/index.test.js",
    "content": "import moxios from 'moxios';\n\nimport { storeFactory } from '../../test/testUtils';\nimport { getSecretWord } from './';\n\ndescribe('getSecretWord', () => {\n  beforeEach(() => {\n    moxios.install();\n  });\n  afterEach(() => {\n    moxios.uninstall();\n  });\n  test('secretWord is returned', () => {\n    const store = storeFactory();\n    moxios.wait(() => {\n      const request = moxios.requests.mostRecent();\n      request.respondWith({\n        status: 200,\n        response: 'party',\n      });\n    });\n\n    return store.dispatch(getSecretWord())\n      .then(() => {\n        const secretWord = store.getState().secretWord;\n        expect(secretWord).toBe('party');\n      });\n  });\n});\n"
  },
  {
    "path": "jotto-redux-hooks/src/configureStore.js",
    "content": "import { createStore, applyMiddleware } from 'redux';\nimport ReduxThunk from 'redux-thunk';\nimport rootReducer from './reducers';\n\nexport const middlewares = [ReduxThunk];\n\nexport default createStore(rootReducer, {}, applyMiddleware(...middlewares));\n"
  },
  {
    "path": "jotto-redux-hooks/src/guessWord.test.js",
    "content": "import React from 'react';\nimport { mount } from 'enzyme';\nimport { Provider } from 'react-redux';\n\nimport App from './App';\nimport { findByTestAttr, storeFactory } from '../test/testUtils.js';\n\n// activate global mock to make sure getSecretWord doesn't make network call\njest.mock('./actions');\n\n/**\n * Create wrapper with specified initial conditions,\n * then submit a guessed word of 'train'\n # @function\n *\n * @param {object} state - Initial conditions.\n * @returns {Wrapper} - Enzyme wrapper of mounted App component\n */\nconst setup = (initialState = {}) => {\n  const store = storeFactory(initialState)\n  const wrapper = mount(<Provider store={store}><App /></Provider>);\n\n  // add value to input box\n  const inputBox = findByTestAttr(wrapper, 'input-box');\n  inputBox.simulate('change', { target: { value: 'train' } });\n\n  // simulate click on submit button\n  const submitButton = findByTestAttr(wrapper, 'submit-button');\n  submitButton.simulate('click', { preventDefault() {} });\n\n  return wrapper;\n}\n\ndescribe('no words guessed', () => {\n  let wrapper;\n  beforeEach(() => {\n    wrapper = setup({\n      secretWord: 'party',\n      success: false,\n      guessedWords: []\n    });\n  });\n  test('creates GuessedWords table with one row', () => {\n    const guessedWordRows = findByTestAttr(wrapper, 'guessed-word');\n    expect(guessedWordRows).toHaveLength(1);\n  });\n});\n\ndescribe('some words guessed', () => {\n  let wrapper;\n  beforeEach(() => {\n  \twrapper = setup({\n    \tsecretWord: 'party',\n    \tsuccess: false,\n    \tguessedWords: [{ guessedWord: 'agile', letterMatchCount: 1 }],\n  \t});\n  });\n  test('adds row to guessedWords table', () => {\n    const guessedWordNodes = findByTestAttr(wrapper, 'guessed-word');\n    expect(guessedWordNodes).toHaveLength(2);\n  });\n});\n\ndescribe('guess secret word', () => {\n  let wrapper;\n  beforeEach(() => {\n  \twrapper = setup({\n    \tsecretWord: 'party',\n    \tsuccess: false,\n    \tguessedWords: [{ guessedWord: 'agile', letterMatchCount: 1 }],\n  \t});\n\n    // add value to input box\n    const inputBox = findByTestAttr(wrapper, 'input-box');\n    const mockEvent = { target: { value: 'party' } };\n    inputBox.simulate('change', mockEvent);\n\n  \t// simulate click on submit button\n  \tconst submitButton = findByTestAttr(wrapper, 'submit-button');\n  \tsubmitButton.simulate('click', { preventDefault() {} });\n  });\n  test('adds row to guessedWords table', () => {\n  \tconst guessedWordNodes = findByTestAttr(wrapper, 'guessed-word');\n  \texpect(guessedWordNodes).toHaveLength(3);\n  });\n  test('displays congrats component', () => {\n  \tconst congrats = findByTestAttr(wrapper, 'component-congrats');\n  \texpect(congrats.text().length).toBeGreaterThan(0);\n  });\n  test('does not display input component contents', () => {\n    const inputBox = findByTestAttr(wrapper, \"input-box\");\n    expect(inputBox.exists()).toBe(false);\n\n    const submitButton = findByTestAttr(wrapper, \"submit-button\");\n    expect(submitButton.exists()).toBe(false);\n  });\n});\n"
  },
  {
    "path": "jotto-redux-hooks/src/helpers/index.js",
    "content": "/**\n * @method getLetterMatchCount\n * @param {string} guessedWord - Guessed word.\n * @param {string} secretWord - Secret word.\n * @returns {number} - Number of letters matched between guessed word and secret word.\n */\n export function getLetterMatchCount(guessedWord, secretWord) {\n   const secretLetters = secretWord.split('');\n   const guessedLetterSet = new Set(guessedWord);\n   return secretLetters.filter(letter => guessedLetterSet.has(letter)).length;\n };\n"
  },
  {
    "path": "jotto-redux-hooks/src/helpers/index.test.js",
    "content": "import { getLetterMatchCount } from './';\n\ndescribe('getLetterMatchCount', () => {\n  const secretWord = 'party';\n  test('returns correct count when there are no matching letters', () => {\n    const letterMatchCount = getLetterMatchCount('bones', secretWord);\n    expect(letterMatchCount).toBe(0);\n  });\n  test('returns the correct count when there are three matching letters', () => {\n    const letterMatchCount = getLetterMatchCount('train', secretWord);\n    expect(letterMatchCount).toBe(3);\n  });\n  test('returns the correct count when there are duplicate letters in the guess', () => {\n    const letterMatchCount = getLetterMatchCount('parka', secretWord);\n    expect(letterMatchCount).toBe(3);\n  });\n});\n"
  },
  {
    "path": "jotto-redux-hooks/src/index.css",
    "content": "body {\n  margin: 0;\n  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',\n    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',\n    sans-serif;\n  -webkit-font-smoothing: antialiased;\n  -moz-osx-font-smoothing: grayscale;\n}\n\ncode {\n  font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',\n    monospace;\n}\n"
  },
  {
    "path": "jotto-redux-hooks/src/index.js",
    "content": "import React from 'react';\nimport ReactDOM from 'react-dom';\nimport { Provider } from 'react-redux';\n\nimport './index.css';\nimport App from './App';\nimport store from './configureStore';\nimport reportWebVitals from './reportWebVitals';\n\nReactDOM.render(\n  <React.StrictMode>\n    <Provider store={store}>\n      <App />\n    </Provider>\n  </React.StrictMode>,\n  document.getElementById('root')\n);\n\n// If you want to start measuring performance in your app, pass a function\n// to log results (for example: reportWebVitals(console.log))\n// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals\nreportWebVitals();\n"
  },
  {
    "path": "jotto-redux-hooks/src/integration.test.js",
    "content": "import { storeFactory } from '../test/testUtils';\nimport { guessWord } from './actions';\n\ndescribe('guessWord action dispatcher', () => {\n  const secretWord = 'party';\n  const unsuccessfulGuess = 'train';\n\n  describe('no guessed words', () => {\n    let store;\n    const initialState = { secretWord };\n    beforeEach(() => {\n      store = storeFactory(initialState);\n    });\n    test('updates state correctly for unsuccessful guess', () => {\n      store.dispatch(guessWord(unsuccessfulGuess));\n      const newState = store.getState()\n\n      const expectedState = {\n        ...initialState,\n        success: false,\n        guessedWords: [{\n          guessedWord: unsuccessfulGuess,\n          letterMatchCount: 3\n        }]\n      }\n      expect(newState).toEqual(expectedState);\n    });\n    test('updates state correctly for successful guess', () => {\n      store.dispatch(guessWord(secretWord));\n      const newState = store.getState()\n\n      const expectedState = {\n        ...initialState,\n        success: true,\n        guessedWords: [{\n          guessedWord: secretWord,\n          letterMatchCount: 5\n        }]\n      }\n      expect(newState).toEqual(expectedState);\n    });\n  });\n  describe('some guessed words', () => {\n    const guessedWords = [{ guessedWord: 'agile', letterMatchCount: 1 }]\n    const initialState = { guessedWords, secretWord };\n    let store;\n    beforeEach(() => {\n      store = storeFactory(initialState);\n    });\n    test('updates state correctly for unsuccessful guess', () => {\n      store.dispatch(guessWord(unsuccessfulGuess));\n      const newState = store.getState();\n      const expectedState = {\n        secretWord,\n        success: false,\n        guessedWords: [\n          ...guessedWords,\n          { guessedWord: unsuccessfulGuess, letterMatchCount: 3 }\n        ]\n      }\n      expect(newState).toEqual(expectedState);\n    });\n    test('updates state correctly for successful guess', () => {\n      store.dispatch(guessWord(secretWord));\n      const newState = store.getState();\n      const expectedState = {\n        secretWord,\n        success: true,\n        guessedWords: [\n          ...guessedWords,\n          { guessedWord: secretWord, letterMatchCount: 5 }\n        ]\n      }\n      expect(newState).toEqual(expectedState);\n    });\n  });\n});\n"
  },
  {
    "path": "jotto-redux-hooks/src/reducers/guessedWordsReducer.js",
    "content": "import { actionTypes } from '../actions';\n\n/**\n * @function guessedWordsReducer\n * @param {array} state - Array of guessed words.\n * @param {object} action - action to be reduced.\n * @returns {array} - new guessedWords state.\n */\n export default (state=[], action) => {\n  switch(action.type) {\n    case actionTypes.GUESS_WORD:\n      return [...state, action.payload];\n    default:\n      return state;\n  }\n}\n"
  },
  {
    "path": "jotto-redux-hooks/src/reducers/index.js",
    "content": "import { combineReducers } from 'redux';\nimport success from './successReducer';\nimport guessedWords from './guessedWordsReducer';\nimport secretWord from './secretWordReducer';\n\nexport default combineReducers({\n  success,\n  guessedWords,\n  secretWord,\n});\n"
  },
  {
    "path": "jotto-redux-hooks/src/reducers/secretWordReducer.js",
    "content": "import { actionTypes } from '../actions';\n\n/**\n * @function secretWordReducer\n * @param {string} state - State before reducer.\n * @param {object} action - Action sent to reducer.\n * @returns {string} - New state (secret word payload from action).\n */\nexport default (state='', action) => {\n  switch(action.type) {\n    case actionTypes.SET_SECRET_WORD:\n      return action.payload\n    default:\n      return state;\n  }\n}\n"
  },
  {
    "path": "jotto-redux-hooks/src/reducers/successReducer.js",
    "content": "import { actionTypes } from '../actions';\n\n/**\n * @function successReducer\n * @param {boolean} state - previous state.\n * @param {object} action - action to be reduced.\n * @returns {boolean} - new success state.\n */\nexport default (state=false, action) => {\n  switch(action.type) {\n    case (actionTypes.CORRECT_GUESS):\n      return true;\n    default:\n      return state;\n  }\n}\n"
  },
  {
    "path": "jotto-redux-hooks/src/reducers/successReducer.test.js",
    "content": "import { actionTypes } from '../actions';\nimport successReducer from './successReducer';\n\ntest('when previous state is undefined, return false', () => {\n  const newState = successReducer(undefined, {});\n  expect(newState).toBe(false);\n});\n\ntest('return previous state when unknown action type', () => {\n  const newState = successReducer(false, { type: 'unknown' });\n  expect(newState).toBe(false);\n});\n\ntest('return `true` for action type CORRECT_GUESS', () => {\n  const newState = successReducer(false, { type: actionTypes.CORRECT_GUESS });\n  expect(newState).toBe(true);\n});\n"
  },
  {
    "path": "jotto-redux-hooks/src/reportWebVitals.js",
    "content": "const reportWebVitals = onPerfEntry => {\n  if (onPerfEntry && onPerfEntry instanceof Function) {\n    import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {\n      getCLS(onPerfEntry);\n      getFID(onPerfEntry);\n      getFCP(onPerfEntry);\n      getLCP(onPerfEntry);\n      getTTFB(onPerfEntry);\n    });\n  }\n};\n\nexport default reportWebVitals;\n"
  },
  {
    "path": "jotto-redux-hooks/src/setupTests.js",
    "content": "import Enzyme from 'enzyme';\nimport EnzymeAdapter from '@wojtekmaj/enzyme-adapter-react-17';\n\nEnzyme.configure({ adapter: new EnzymeAdapter() });\n"
  },
  {
    "path": "jotto-redux-hooks/test/testUtils.js",
    "content": "import checkPropTypes from 'check-prop-types';\nimport { createStore, applyMiddleware } from 'redux';\n\nimport rootReducer from '../src/reducers';\nimport { middlewares } from '../src/configureStore';\n\n/**\n * Create a testing store with imported reducers, middleware, and initial state.\n *  globals: rootReducer.\n * @param {object} initialState - Initial state for store.\n * @function storeFactory\n * @returns {Store} - Redux store.\n */\nexport const storeFactory = (initialState) => {\n  return createStore(rootReducer, initialState, applyMiddleware(...middlewares));\n}\n\n\n/**\n * Return node(s) with the given data-test attribute.\n * @param {ShallowWrapper} wrapper - Enzyme shallow wrapper.\n * @param {string} val - Value of data-test attribute for search.\n * @returns {ShallowWrapper}\n */\nexport const findByTestAttr = (wrapper, val) => {\n  return wrapper.find(`[data-test=\"${val}\"]`);\n}\n\n\n/**\n * Assert that expected conforming props conform to propTypes definiton.\n * @param {React.Component} component - React component.\n * @param {object} conformingProps - Object of conforming props.\n * @returns {undefined} - Throws error if props do not conform.\n */\nexport const checkProps = (component, conformingProps) => {\n  const propError = checkPropTypes(\n    component.propTypes,\n    conformingProps,\n    'prop',\n    component.name);\n  expect(propError).toBeUndefined();\n}\n"
  },
  {
    "path": "random-word-server/.gitignore",
    "content": "config.js\n"
  },
  {
    "path": "random-word-server/.npmrc",
    "content": "fund=false\naudit=false\nloglevel=error\n"
  },
  {
    "path": "random-word-server/README.md",
    "content": "# random-word-server\n### A random word server for the Jotto app in the Udemy course \"React / Redux Testing with Jest and Enzyme\"\n\n## Installing\n1. Clone or fork the course repository found at [https://github.com/flyrightsister/udemy-react-testing-projects]\n2. `cd` into the `random-word-server` directory (where this README is located).\n3. Run `npm install` \n\n## Starting the server\nRun `npm start`. The server will be found at [http://localhost:3030]\n\n## Using the server\nThis server has one purpose: return a response containing a random five-letter word (with no duplicate letters) at the `/` route.\n\n## Testing\nTo test, run `npm test`."
  },
  {
    "path": "random-word-server/five-letter-words.json",
    "content": "{\n  \"fiveLetterWords\": [\n    \"acorn\",\n    \"acrid\",\n    \"actor\",\n    \"adept\",\n    \"adobe\",\n    \"adorn\",\n    \"adult\",\n    \"agent\",\n    \"agony\",\n    \"aisle\",\n    \"alder\",\n    \"alien\",\n    \"alike\",\n    \"alive\",\n    \"alone\",\n    \"aloud\",\n    \"amber\",\n    \"ample\",\n    \"angel\",\n    \"angry\",\n    \"ankle\",\n    \"antic\",\n    \"arise\",\n    \"aspen\",\n    \"aspic\",\n    \"audio\",\n    \"awful\",\n    \"azure\",\n    \"balmy\",\n    \"bandy\",\n    \"basic\",\n    \"basin\",\n    \"batch\",\n    \"baton\",\n    \"bawdy\",\n    \"beady\",\n    \"beast\",\n    \"being\",\n    \"bigot\",\n    \"binge\",\n    \"bingo\",\n    \"biped\",\n    \"birch\",\n    \"birth\",\n    \"bison\",\n    \"blame\",\n    \"bland\",\n    \"blank\",\n    \"bleak\",\n    \"bleat\",\n    \"blind\",\n    \"bloat\",\n    \"blond\",\n    \"blunt\",\n    \"bodge\",\n    \"bogus\",\n    \"bonus\",\n    \"bound\",\n    \"boxer\",\n    \"braid\",\n    \"brand\",\n    \"brash\",\n    \"brave\",\n    \"brawl\",\n    \"brawn\",\n    \"brick\",\n    \"brief\",\n    \"brisk\",\n    \"broad\",\n    \"broke\",\n    \"brute\",\n    \"bugle\",\n    \"built\",\n    \"bulky\",\n    \"burly\",\n    \"bushy\",\n    \"butch\",\n    \"cadet\",\n    \"cadre\",\n    \"camel\",\n    \"caste\",\n    \"cedar\",\n    \"chaos\",\n    \"chard\",\n    \"cheap\",\n    \"chest\",\n    \"chief\",\n    \"china\",\n    \"chirp\",\n    \"chive\",\n    \"choir\",\n    \"chore\",\n    \"cleft\",\n    \"clerk\",\n    \"clove\",\n    \"clown\",\n    \"conga\",\n    \"coral\",\n    \"corny\",\n    \"corps\",\n    \"court\",\n    \"couth\",\n    \"cover\",\n    \"cramp\",\n    \"crash\",\n    \"crawl\",\n    \"crazy\",\n    \"cream\",\n    \"crime\",\n    \"crimp\",\n    \"croup\",\n    \"crown\",\n    \"crude\",\n    \"cruel\",\n    \"cruet\",\n    \"crypt\",\n    \"curve\",\n    \"daily\",\n    \"delta\",\n    \"demon\",\n    \"depth\",\n    \"diary\",\n    \"diner\",\n    \"dinge\",\n    \"disco\",\n    \"diver\",\n    \"dogma\",\n    \"doing\",\n    \"dough\",\n    \"downy\",\n    \"dowry\",\n    \"dozen\",\n    \"draft\",\n    \"drake\",\n    \"drift\",\n    \"drove\",\n    \"drunk\",\n    \"dumpy\",\n    \"dusky\",\n    \"dusty\",\n    \"dwarf\",\n    \"dying\",\n    \"debut\",\n    \"early\",\n    \"elfin\",\n    \"entry\",\n    \"envoy\",\n    \"epoch\",\n    \"equal\",\n    \"ethic\",\n    \"exact\",\n    \"exist\",\n    \"extra\",\n    \"faint\",\n    \"fairy\",\n    \"faker\",\n    \"fakir\",\n    \"false\",\n    \"fancy\",\n    \"fated\",\n    \"feint\",\n    \"felon\",\n    \"femur\",\n    \"feral\",\n    \"field\",\n    \"fiend\",\n    \"fiery\",\n    \"filet\",\n    \"final\",\n    \"finch\",\n    \"first\",\n    \"fishy\",\n    \"fitch\",\n    \"fiver\",\n    \"fixed\",\n    \"fixer\",\n    \"flair\",\n    \"flaky\",\n    \"flank\",\n    \"flask\",\n    \"flesh\",\n    \"flint\",\n    \"flirt\",\n    \"flora\",\n    \"fluid\",\n    \"fluke\",\n    \"flush\",\n    \"forte\",\n    \"forum\",\n    \"frail\",\n    \"frank\",\n    \"frisk\",\n    \"frond\",\n    \"fusty\",\n    \"gamut\",\n    \"gaunt\",\n    \"gauze\",\n    \"genus\",\n    \"getup\",\n    \"giant\",\n    \"glade\",\n    \"gland\",\n    \"glare\",\n    \"gloat\",\n    \"gnome\",\n    \"grail\",\n    \"grand\",\n    \"grate\",\n    \"grave\",\n    \"gravy\",\n    \"great\",\n    \"grief\",\n    \"grise\",\n    \"groat\",\n    \"group\",\n    \"grove\",\n    \"guild\",\n    \"gumbo\",\n    \"hardy\",\n    \"hazel\",\n    \"heady\",\n    \"heavy\",\n    \"hoary\",\n    \"honey\",\n    \"horde\",\n    \"hover\",\n    \"human\",\n    \"husky\",\n    \"idler\",\n    \"inert\",\n    \"inlet\",\n    \"irony\",\n    \"ivory\",\n    \"jerky\",\n    \"jihad\",\n    \"joust\",\n    \"juicy\",\n    \"jumbo\",\n    \"knave\",\n    \"labor\",\n    \"large\",\n    \"laser\",\n    \"later\",\n    \"latex\",\n    \"leafy\",\n    \"leaky\",\n    \"lemon\",\n    \"letch\",\n    \"limbo\",\n    \"lined\",\n    \"liner\",\n    \"lithe\",\n    \"liver\",\n    \"loath\",\n    \"locus\",\n    \"lofty\",\n    \"logic\",\n    \"lotus\",\n    \"lover\",\n    \"lower\",\n    \"lucid\",\n    \"lucky\",\n    \"lumen\",\n    \"lurid\",\n    \"lusty\",\n    \"lying\",\n    \"lyric\",\n    \"macro\",\n    \"madly\",\n    \"maize\",\n    \"major\",\n    \"mango\",\n    \"manly\",\n    \"manor\",\n    \"manse\",\n    \"maybe\",\n    \"mealy\",\n    \"meaty\",\n    \"media\",\n    \"medic\",\n    \"midge\",\n    \"miner\",\n    \"minor\",\n    \"mirth\",\n    \"miser\",\n    \"misty\",\n    \"mixed\",\n    \"mixer\",\n    \"mocha\",\n    \"modal\",\n    \"model\",\n    \"moist\",\n    \"molar\",\n    \"moral\",\n    \"morel\",\n    \"mould\",\n    \"mousy\",\n    \"mover\",\n    \"movie\",\n    \"mufti\",\n    \"murky\",\n    \"mushy\",\n    \"music\",\n    \"musty\",\n    \"nadir\",\n    \"naive\",\n    \"naked\",\n    \"nasty\",\n    \"navel\",\n    \"neigh\",\n    \"nervy\",\n    \"night\",\n    \"noble\",\n    \"noisy\",\n    \"north\",\n    \"noted\",\n    \"nymph\",\n    \"oared\",\n    \"ocean\",\n    \"often\",\n    \"olive\",\n    \"omega\",\n    \"opera\",\n    \"optic\",\n    \"ounce\",\n    \"outer\",\n    \"ovary\",\n    \"ovine\",\n    \"palsy\",\n    \"panic\",\n    \"pants\",\n    \"party\",\n    \"pasty\",\n    \"peach\",\n    \"pecan\",\n    \"pedal\",\n    \"phony\",\n    \"piano\",\n    \"piety\",\n    \"pilot\",\n    \"pinch\",\n    \"pinky\",\n    \"pious\",\n    \"pithy\",\n    \"plain\",\n    \"plumb\",\n    \"plush\",\n    \"poker\",\n    \"pokey\",\n    \"polar\",\n    \"polka\",\n    \"porch\",\n    \"prawn\",\n    \"prime\",\n    \"primo\",\n    \"privy\",\n    \"prize\",\n    \"prone\",\n    \"prose\",\n    \"proud\",\n    \"proxy\",\n    \"pylon\",\n    \"quack\",\n    \"qualm\",\n    \"quart\",\n    \"quick\",\n    \"quiet\",\n    \"quint\",\n    \"quirk\",\n    \"quite\",\n    \"quota\",\n    \"rabid\",\n    \"rapid\",\n    \"ratio\",\n    \"raven\",\n    \"rayon\",\n    \"ready\",\n    \"regal\",\n    \"reign\",\n    \"reins\",\n    \"relax\",\n    \"relay\",\n    \"relic\",\n    \"right\",\n    \"rocky\",\n    \"rogue\",\n    \"rouge\",\n    \"rough\",\n    \"royal\",\n    \"rusty\",\n    \"sable\",\n    \"sabre\",\n    \"salon\",\n    \"salty\",\n    \"salvo\",\n    \"sandy\",\n    \"satin\",\n    \"satyr\",\n    \"saucy\",\n    \"scald\",\n    \"scaly\",\n    \"scant\",\n    \"scape\",\n    \"scary\",\n    \"scion\",\n    \"scrim\",\n    \"scrip\",\n    \"setup\",\n    \"shady\",\n    \"shaky\",\n    \"shank\",\n    \"shard\",\n    \"shine\",\n    \"shiny\",\n    \"shire\",\n    \"shlep\",\n    \"shoal\",\n    \"shock\",\n    \"short\",\n    \"showy\",\n    \"sigma\",\n    \"siren\",\n    \"skate\",\n    \"skein\",\n    \"skimp\",\n    \"slate\",\n    \"slave\",\n    \"slick\",\n    \"slimy\",\n    \"sloth\",\n    \"smock\",\n    \"smoky\",\n    \"snail\",\n    \"snake\",\n    \"snaky\",\n    \"snowy\",\n    \"soapy\",\n    \"sober\",\n    \"solar\",\n    \"solid\",\n    \"sough\",\n    \"south\",\n    \"spare\",\n    \"spate\",\n    \"spelt\",\n    \"spent\",\n    \"sperm\",\n    \"spick\",\n    \"spicy\",\n    \"splat\",\n    \"splay\",\n    \"split\",\n    \"spore\",\n    \"sport\",\n    \"spume\",\n    \"spunk\",\n    \"squab\",\n    \"squat\",\n    \"squid\",\n    \"stair\",\n    \"stale\",\n    \"stang\",\n    \"stark\",\n    \"steam\",\n    \"stern\",\n    \"stock\",\n    \"stoic\",\n    \"stole\",\n    \"stone\",\n    \"straw\",\n    \"stuck\",\n    \"suite\",\n    \"sulky\",\n    \"sumac\",\n    \"super\",\n    \"swain\",\n    \"swank\",\n    \"swing\",\n    \"sworn\",\n    \"sylph\",\n    \"synod\",\n    \"syrup\",\n    \"talon\",\n    \"tango\",\n    \"tawny\",\n    \"teary\",\n    \"tempo\",\n    \"tenor\",\n    \"thick\",\n    \"thief\",\n    \"thing\",\n    \"think\",\n    \"thong\",\n    \"throb\",\n    \"thunk\",\n    \"tiger\",\n    \"tiler\",\n    \"timer\",\n    \"tipsy\",\n    \"tired\",\n    \"topaz\",\n    \"topic\",\n    \"torus\",\n    \"tough\",\n    \"touse\",\n    \"trace\",\n    \"trial\",\n    \"trice\",\n    \"tripe\",\n    \"trope\",\n    \"truck\",\n    \"truly\",\n    \"trunk\",\n    \"tuber\",\n    \"tulip\",\n    \"tumid\",\n    \"tumor\",\n    \"tuner\",\n    \"tunic\",\n    \"twice\",\n    \"twink\",\n    \"ultra\",\n    \"umber\",\n    \"umbra\",\n    \"unfit\",\n    \"unite\",\n    \"upset\",\n    \"urban\",\n    \"valor\",\n    \"velum\",\n    \"video\",\n    \"vinyl\",\n    \"viola\",\n    \"viper\",\n    \"vista\",\n    \"vital\",\n    \"vixen\",\n    \"vocal\",\n    \"vogue\",\n    \"wader\",\n    \"waste\",\n    \"waver\",\n    \"waxen\",\n    \"weald\",\n    \"weary\",\n    \"weird\",\n    \"wench\",\n    \"wheat\",\n    \"white\",\n    \"wince\",\n    \"windy\",\n    \"wiper\",\n    \"wired\",\n    \"world\",\n    \"worse\",\n    \"worth\",\n    \"wound\",\n    \"woven\",\n    \"wrath\",\n    \"wrong\",\n    \"yacht\",\n    \"zebra\"\n  ]\n}"
  },
  {
    "path": "random-word-server/package.json",
    "content": "{\n  \"name\": \"random-word-server\",\n  \"version\": \"1.0.0\",\n  \"author\": \"Bonnie Schulkin\",\n  \"license\": \"AGPL-3.0\",\n  \"repository\": {\n    \"type\": \"git\",\n    \"url\": \"git+https://github.com/flyrightsister/udemy-react-testing-projects.git\"\n  },\n  \"scripts\": {\n    \"start\": \"node server.js\",\n    \"test\": \"jest --forceExit\"\n  },\n  \"devDependencies\": {\n    \"jest\": \"^22.4.3\"\n  },\n  \"dependencies\": {\n    \"cors\": \"^2.8.4\",\n    \"express\": \"^4.16.3\",\n    \"supertest\": \"^3.0.0\"\n  }\n}\n"
  },
  {
    "path": "random-word-server/server.js",
    "content": "const express = require('express');\nconst cors = require('cors');\nconst fs = require('fs');\n\nconst app = express();\n\n// CORS for react app, assuming port 3000\napp.use(cors({\n  origin: 'http://localhost:3000',\n  credentials: true\n}))\n\n// read words from json file\nconst fileContents = fs.readFileSync('./five-letter-words.json', 'utf-8');\nconst words = JSON.parse(fileContents);\nconst { fiveLetterWords } = words;\n\napp.get('/', (req, res) => {\n  // select a random word\n  const word = fiveLetterWords[Math.floor(Math.random() * fiveLetterWords.length)]\n\n  // return it as the response\n  res.send(word)\n})\n\napp.listen(3030, () => console.log('Word server listening on port 3030!'))\n\nmodule.exports = app;"
  },
  {
    "path": "random-word-server/server.test.js",
    "content": "const request = require('supertest');\nconst app = require('./server.js');\n\ndescribe('root path', () => {\n  test('responds with status 200 the GET method', () => {\n    return request(app).get(\"/\").then(response => {\n      expect(response.statusCode).toBe(200);\n    })\n  });\n  test('response is a five-letter word', () => {\n    return request(app).get(\"/\").then(response => {\n      expect(response.text.length).toBe(5);\n    })\n  });\n})"
  }
]