diff --git a/.gitignore b/.gitignore index 6e34e83..b1db79d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,22 +1,7 @@ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. # dependencies -/node_modules -/.pnp -.pnp.js - -# testing -/coverage - -# production -/build - -# misc -.DS_Store -.env.local -.env.development.local -.env.test.local -.env.production.local +*/node_modules npm-debug.log* yarn-debug.log* @@ -25,4 +10,4 @@ yarn-error.log* .idea #No queremos usar npm asi que lo ignoramos por si alguien lo usa por error -.package-lock.json \ No newline at end of file +.package-lock.json diff --git a/.travis.yml b/.travis.yml index dc599bf..1032288 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ cache: directories: - node_modules script: + - cd frontend - yarn install - yarn lint - "CI=true yarn test" @@ -16,7 +17,7 @@ deploy: provider: pages skip_cleanup: true github_token: $github_token - local_dir: build + local_dir: frontend/build on: branch: master diff --git a/backend/.gitignore b/backend/.gitignore new file mode 100644 index 0000000..3deadac --- /dev/null +++ b/backend/.gitignore @@ -0,0 +1,13 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules + +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +.idea + +#No queremos usar npm asi que lo ignoramos por si alguien lo usa por error +.package-lock.json diff --git a/backend/index.js b/backend/index.js new file mode 100644 index 0000000..7ea3b57 --- /dev/null +++ b/backend/index.js @@ -0,0 +1,11 @@ +var express = require('express'); +var app = express(); + +app.get('/', function (req, res) { + res.send('Hello World!'); +}); + +app.listen(3000, function () { + console.log('Example app listening on port 3000!'); +}); + diff --git a/backend/package.json b/backend/package.json new file mode 100644 index 0000000..51ed59d --- /dev/null +++ b/backend/package.json @@ -0,0 +1,22 @@ +{ + "name": "pdes-tp-chinwenwenchas-backend", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "start": "node index.js" + }, + "repository": { + "type": "git", + "url": "git@github.com/PracticaDS/pdes-tp-chinwewenchas.git" + }, + "author": "", + "license": "GPL-2.0", + "bugs": { + "url": "https://github.com/PracticaDS/pdes-tp-chinwewenchas/issues" + }, + "homepage": "https://github.com/PracticaDS/pdes-tp-chinwewenchas#readme", + "dependencies": { + "express": "^4.17.1" + } +} diff --git a/backend/yarn.lock b/backend/yarn.lock new file mode 100644 index 0000000..4e9cdd0 --- /dev/null +++ b/backend/yarn.lock @@ -0,0 +1,352 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +accepts@~1.3.7: + version "1.3.7" + resolved "https://registry.yarnpkg.com/accepts/-/accepts-1.3.7.tgz#531bc726517a3b2b41f850021c6cc15eaab507cd" + integrity sha512-Il80Qs2WjYlJIBNzNkK6KYqlVMTbZLXgHx2oT0pU/fjRHyEp+PEfEPY0R3WCwAGVOtauxh1hOxNgIf5bv7dQpA== + dependencies: + mime-types "~2.1.24" + negotiator "0.6.2" + +array-flatten@1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/array-flatten/-/array-flatten-1.1.1.tgz#9a5f699051b1e7073328f2a008968b64ea2955d2" + integrity sha1-ml9pkFGx5wczKPKgCJaLZOopVdI= + +body-parser@1.19.0: + version "1.19.0" + resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.19.0.tgz#96b2709e57c9c4e09a6fd66a8fd979844f69f08a" + integrity sha512-dhEPs72UPbDnAQJ9ZKMNTP6ptJaionhP5cBb541nXPlW60Jepo9RV/a4fX4XWW9CuFNK22krhrj1+rgzifNCsw== + dependencies: + bytes "3.1.0" + content-type "~1.0.4" + debug "2.6.9" + depd "~1.1.2" + http-errors "1.7.2" + iconv-lite "0.4.24" + on-finished "~2.3.0" + qs "6.7.0" + raw-body "2.4.0" + type-is "~1.6.17" + +bytes@3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.1.0.tgz#f6cf7933a360e0588fa9fde85651cdc7f805d1f6" + integrity sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg== + +content-disposition@0.5.3: + version "0.5.3" + resolved "https://registry.yarnpkg.com/content-disposition/-/content-disposition-0.5.3.tgz#e130caf7e7279087c5616c2007d0485698984fbd" + integrity sha512-ExO0774ikEObIAEV9kDo50o+79VCUdEB6n6lzKgGwupcVeRlhrj3qGAfwq8G6uBJjkqLrhT0qEYFcWng8z1z0g== + dependencies: + safe-buffer "5.1.2" + +content-type@~1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/content-type/-/content-type-1.0.4.tgz#e138cc75e040c727b1966fe5e5f8c9aee256fe3b" + integrity sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA== + +cookie-signature@1.0.6: + version "1.0.6" + resolved "https://registry.yarnpkg.com/cookie-signature/-/cookie-signature-1.0.6.tgz#e303a882b342cc3ee8ca513a79999734dab3ae2c" + integrity sha1-4wOogrNCzD7oylE6eZmXNNqzriw= + +cookie@0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.4.0.tgz#beb437e7022b3b6d49019d088665303ebe9c14ba" + integrity sha512-+Hp8fLp57wnUSt0tY0tHEXh4voZRDnoIrZPqlo3DPiI4y9lwg/jqx+1Om94/W6ZaPDOUbnjOt/99w66zk+l1Xg== + +debug@2.6.9: + version "2.6.9" + resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" + integrity sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA== + dependencies: + ms "2.0.0" + +depd@~1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.2.tgz#9bcd52e14c097763e749b274c4346ed2e560b5a9" + integrity sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak= + +destroy@~1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.0.4.tgz#978857442c44749e4206613e37946205826abd80" + integrity sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA= + +ee-first@1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d" + integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0= + +encodeurl@~1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59" + integrity sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k= + +escape-html@~1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988" + integrity sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg= + +etag@~1.8.1: + version "1.8.1" + resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887" + integrity sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc= + +express@^4.17.1: + version "4.17.1" + resolved "https://registry.yarnpkg.com/express/-/express-4.17.1.tgz#4491fc38605cf51f8629d39c2b5d026f98a4c134" + integrity sha512-mHJ9O79RqluphRrcw2X/GTh3k9tVv8YcoyY4Kkh4WDMUYKRZUq0h1o0w2rrrxBqM7VoeUVqgb27xlEMXTnYt4g== + dependencies: + accepts "~1.3.7" + array-flatten "1.1.1" + body-parser "1.19.0" + content-disposition "0.5.3" + content-type "~1.0.4" + cookie "0.4.0" + cookie-signature "1.0.6" + debug "2.6.9" + depd "~1.1.2" + encodeurl "~1.0.2" + escape-html "~1.0.3" + etag "~1.8.1" + finalhandler "~1.1.2" + fresh "0.5.2" + merge-descriptors "1.0.1" + methods "~1.1.2" + on-finished "~2.3.0" + parseurl "~1.3.3" + path-to-regexp "0.1.7" + proxy-addr "~2.0.5" + qs "6.7.0" + range-parser "~1.2.1" + safe-buffer "5.1.2" + send "0.17.1" + serve-static "1.14.1" + setprototypeof "1.1.1" + statuses "~1.5.0" + type-is "~1.6.18" + utils-merge "1.0.1" + vary "~1.1.2" + +finalhandler@~1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/finalhandler/-/finalhandler-1.1.2.tgz#b7e7d000ffd11938d0fdb053506f6ebabe9f587d" + integrity sha512-aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA== + dependencies: + debug "2.6.9" + encodeurl "~1.0.2" + escape-html "~1.0.3" + on-finished "~2.3.0" + parseurl "~1.3.3" + statuses "~1.5.0" + unpipe "~1.0.0" + +forwarded@~0.1.2: + version "0.1.2" + resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.1.2.tgz#98c23dab1175657b8c0573e8ceccd91b0ff18c84" + integrity sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ= + +fresh@0.5.2: + version "0.5.2" + resolved "https://registry.yarnpkg.com/fresh/-/fresh-0.5.2.tgz#3d8cadd90d976569fa835ab1f8e4b23a105605a7" + integrity sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac= + +http-errors@1.7.2, http-errors@~1.7.2: + version "1.7.2" + resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-1.7.2.tgz#4f5029cf13239f31036e5b2e55292bcfbcc85c8f" + integrity sha512-uUQBt3H/cSIVfch6i1EuPNy/YsRSOUBXTVfZ+yR7Zjez3qjBz6i9+i4zjNaoqcoFVI4lQJ5plg63TvGfRSDCRg== + dependencies: + depd "~1.1.2" + inherits "2.0.3" + setprototypeof "1.1.1" + statuses ">= 1.5.0 < 2" + toidentifier "1.0.0" + +iconv-lite@0.4.24: + version "0.4.24" + resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b" + integrity sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA== + dependencies: + safer-buffer ">= 2.1.2 < 3" + +inherits@2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" + integrity sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4= + +ipaddr.js@1.9.0: + version "1.9.0" + resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-1.9.0.tgz#37df74e430a0e47550fe54a2defe30d8acd95f65" + integrity sha512-M4Sjn6N/+O6/IXSJseKqHoFc+5FdGJ22sXqnjTpdZweHK64MzEPAyQZyEU3R/KRv2GLoa7nNtg/C2Ev6m7z+eA== + +media-typer@0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748" + integrity sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g= + +merge-descriptors@1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/merge-descriptors/-/merge-descriptors-1.0.1.tgz#b00aaa556dd8b44568150ec9d1b953f3f90cbb61" + integrity sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E= + +methods@~1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee" + integrity sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4= + +mime-db@1.40.0: + version "1.40.0" + resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.40.0.tgz#a65057e998db090f732a68f6c276d387d4126c32" + integrity sha512-jYdeOMPy9vnxEqFRRo6ZvTZ8d9oPb+k18PKoYNYUe2stVEBPPwsln/qWzdbmaIvnhZ9v2P+CuecK+fpUfsV2mA== + +mime-types@~2.1.24: + version "2.1.24" + resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.24.tgz#b6f8d0b3e951efb77dedeca194cff6d16f676f81" + integrity sha512-WaFHS3MCl5fapm3oLxU4eYDw77IQM2ACcxQ9RIxfaC3ooc6PFuBMGZZsYpvoXS5D5QTWPieo1jjLdAm3TBP3cQ== + dependencies: + mime-db "1.40.0" + +mime@1.6.0: + version "1.6.0" + resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1" + integrity sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg== + +ms@2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" + integrity sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g= + +ms@2.1.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.1.tgz#30a5864eb3ebb0a66f2ebe6d727af06a09d86e0a" + integrity sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg== + +negotiator@0.6.2: + version "0.6.2" + resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.2.tgz#feacf7ccf525a77ae9634436a64883ffeca346fb" + integrity sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw== + +on-finished@~2.3.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/on-finished/-/on-finished-2.3.0.tgz#20f1336481b083cd75337992a16971aa2d906947" + integrity sha1-IPEzZIGwg811M3mSoWlxqi2QaUc= + dependencies: + ee-first "1.1.1" + +parseurl@~1.3.3: + version "1.3.3" + resolved "https://registry.yarnpkg.com/parseurl/-/parseurl-1.3.3.tgz#9da19e7bee8d12dff0513ed5b76957793bc2e8d4" + integrity sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ== + +path-to-regexp@0.1.7: + version "0.1.7" + resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c" + integrity sha1-32BBeABfUi8V60SQ5yR6G/qmf4w= + +proxy-addr@~2.0.5: + version "2.0.5" + resolved "https://registry.yarnpkg.com/proxy-addr/-/proxy-addr-2.0.5.tgz#34cbd64a2d81f4b1fd21e76f9f06c8a45299ee34" + integrity sha512-t/7RxHXPH6cJtP0pRG6smSr9QJidhB+3kXu0KgXnbGYMgzEnUxRQ4/LDdfOwZEMyIh3/xHb8PX3t+lfL9z+YVQ== + dependencies: + forwarded "~0.1.2" + ipaddr.js "1.9.0" + +qs@6.7.0: + version "6.7.0" + resolved "https://registry.yarnpkg.com/qs/-/qs-6.7.0.tgz#41dc1a015e3d581f1621776be31afb2876a9b1bc" + integrity sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ== + +range-parser@~1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.1.tgz#3cf37023d199e1c24d1a55b84800c2f3e6468031" + integrity sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg== + +raw-body@2.4.0: + version "2.4.0" + resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.4.0.tgz#a1ce6fb9c9bc356ca52e89256ab59059e13d0332" + integrity sha512-4Oz8DUIwdvoa5qMJelxipzi/iJIi40O5cGV1wNYp5hvZP8ZN0T+jiNkL0QepXs+EsQ9XJ8ipEDoiH70ySUJP3Q== + dependencies: + bytes "3.1.0" + http-errors "1.7.2" + iconv-lite "0.4.24" + unpipe "1.0.0" + +safe-buffer@5.1.2: + version "5.1.2" + resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d" + integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g== + +"safer-buffer@>= 2.1.2 < 3": + version "2.1.2" + resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" + integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== + +send@0.17.1: + version "0.17.1" + resolved "https://registry.yarnpkg.com/send/-/send-0.17.1.tgz#c1d8b059f7900f7466dd4938bdc44e11ddb376c8" + integrity sha512-BsVKsiGcQMFwT8UxypobUKyv7irCNRHk1T0G680vk88yf6LBByGcZJOTJCrTP2xVN6yI+XjPJcNuE3V4fT9sAg== + dependencies: + debug "2.6.9" + depd "~1.1.2" + destroy "~1.0.4" + encodeurl "~1.0.2" + escape-html "~1.0.3" + etag "~1.8.1" + fresh "0.5.2" + http-errors "~1.7.2" + mime "1.6.0" + ms "2.1.1" + on-finished "~2.3.0" + range-parser "~1.2.1" + statuses "~1.5.0" + +serve-static@1.14.1: + version "1.14.1" + resolved "https://registry.yarnpkg.com/serve-static/-/serve-static-1.14.1.tgz#666e636dc4f010f7ef29970a88a674320898b2f9" + integrity sha512-JMrvUwE54emCYWlTI+hGrGv5I8dEwmco/00EvkzIIsR7MqrHonbD9pO2MOfFnpFntl7ecpZs+3mW+XbQZu9QCg== + dependencies: + encodeurl "~1.0.2" + escape-html "~1.0.3" + parseurl "~1.3.3" + send "0.17.1" + +setprototypeof@1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.1.1.tgz#7e95acb24aa92f5885e0abef5ba131330d4ae683" + integrity sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw== + +"statuses@>= 1.5.0 < 2", statuses@~1.5.0: + version "1.5.0" + resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.5.0.tgz#161c7dac177659fd9811f43771fa99381478628c" + integrity sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow= + +toidentifier@1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.0.tgz#7e1be3470f1e77948bc43d94a3c8f4d7752ba553" + integrity sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw== + +type-is@~1.6.17, type-is@~1.6.18: + version "1.6.18" + resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.18.tgz#4e552cd05df09467dcbc4ef739de89f2cf37c131" + integrity sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g== + dependencies: + media-typer "0.3.0" + mime-types "~2.1.24" + +unpipe@1.0.0, unpipe@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec" + integrity sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw= + +utils-merge@1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713" + integrity sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM= + +vary@~1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc" + integrity sha1-IpnwLG3tMNSllhsLn3RSShj2NPw= diff --git a/.eslintrc b/frontend/.eslintrc similarity index 100% rename from .eslintrc rename to frontend/.eslintrc diff --git a/frontend/.gitignore b/frontend/.gitignore new file mode 100644 index 0000000..ee58c20 --- /dev/null +++ b/frontend/.gitignore @@ -0,0 +1,28 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +.idea + +#No queremos usar npm asi que lo ignoramos por si alguien lo usa por error +.package-lock.json diff --git a/.storybook/config.js b/frontend/.storybook/config.js similarity index 100% rename from .storybook/config.js rename to frontend/.storybook/config.js diff --git a/README.md b/frontend/README.md similarity index 100% rename from README.md rename to frontend/README.md diff --git a/package.json b/frontend/package.json similarity index 96% rename from package.json rename to frontend/package.json index 9dd85f9..132e2eb 100644 --- a/package.json +++ b/frontend/package.json @@ -5,10 +5,12 @@ "homepage": "https://practicads.github.io/pdes-tp-chinwewenchas/", "dependencies": { "@types/lodash": "^4.14.123", + "core-js": "^3.1.3", "daggy": "^1.4.0", "gh-pages": "^2.0.1", "lodash": "^4.17.11", "react": "^16.8.6", + "react-app-polyfill": "^1.0.1", "react-dom": "^16.8.6", "react-redux": "^7.0.2", "react-scripts": "2.1.8", diff --git a/public/favicon.ico b/frontend/public/favicon.ico similarity index 100% rename from public/favicon.ico rename to frontend/public/favicon.ico diff --git a/public/icons/crafter.svg b/frontend/public/icons/crafter.svg similarity index 100% rename from public/icons/crafter.svg rename to frontend/public/icons/crafter.svg diff --git a/public/icons/crafter_activo.svg b/frontend/public/icons/crafter_activo.svg similarity index 100% rename from public/icons/crafter_activo.svg rename to frontend/public/icons/crafter_activo.svg diff --git a/public/icons/eliminar.svg b/frontend/public/icons/eliminar.svg similarity index 100% rename from public/icons/eliminar.svg rename to frontend/public/icons/eliminar.svg diff --git a/public/icons/eliminar_activo.svg b/frontend/public/icons/eliminar_activo.svg similarity index 100% rename from public/icons/eliminar_activo.svg rename to frontend/public/icons/eliminar_activo.svg diff --git a/public/icons/furnace.svg b/frontend/public/icons/furnace.svg similarity index 100% rename from public/icons/furnace.svg rename to frontend/public/icons/furnace.svg diff --git a/public/icons/furnace_active.svg b/frontend/public/icons/furnace_active.svg similarity index 100% rename from public/icons/furnace_active.svg rename to frontend/public/icons/furnace_active.svg diff --git a/public/icons/mover.svg b/frontend/public/icons/mover.svg similarity index 100% rename from public/icons/mover.svg rename to frontend/public/icons/mover.svg diff --git a/public/icons/mover_activo.svg b/frontend/public/icons/mover_activo.svg similarity index 100% rename from public/icons/mover_activo.svg rename to frontend/public/icons/mover_activo.svg diff --git a/public/icons/rotar.svg b/frontend/public/icons/rotar.svg similarity index 100% rename from public/icons/rotar.svg rename to frontend/public/icons/rotar.svg diff --git a/public/icons/rotar_activo.svg b/frontend/public/icons/rotar_activo.svg similarity index 100% rename from public/icons/rotar_activo.svg rename to frontend/public/icons/rotar_activo.svg diff --git a/public/icons/seller.svg b/frontend/public/icons/seller.svg similarity index 100% rename from public/icons/seller.svg rename to frontend/public/icons/seller.svg diff --git a/public/icons/seller_active.svg b/frontend/public/icons/seller_active.svg similarity index 100% rename from public/icons/seller_active.svg rename to frontend/public/icons/seller_active.svg diff --git a/public/icons/starter.svg b/frontend/public/icons/starter.svg similarity index 100% rename from public/icons/starter.svg rename to frontend/public/icons/starter.svg diff --git a/public/icons/starter_active.svg b/frontend/public/icons/starter_active.svg similarity index 100% rename from public/icons/starter_active.svg rename to frontend/public/icons/starter_active.svg diff --git a/public/icons/transporter.svg b/frontend/public/icons/transporter.svg similarity index 100% rename from public/icons/transporter.svg rename to frontend/public/icons/transporter.svg diff --git a/public/icons/transporter_active.svg b/frontend/public/icons/transporter_active.svg similarity index 100% rename from public/icons/transporter_active.svg rename to frontend/public/icons/transporter_active.svg diff --git a/public/index.html b/frontend/public/index.html similarity index 100% rename from public/index.html rename to frontend/public/index.html diff --git a/public/manifest.json b/frontend/public/manifest.json similarity index 100% rename from public/manifest.json rename to frontend/public/manifest.json diff --git a/src/App.css b/frontend/src/App.css similarity index 100% rename from src/App.css rename to frontend/src/App.css diff --git a/frontend/src/App.js b/frontend/src/App.js new file mode 100644 index 0000000..f34d094 --- /dev/null +++ b/frontend/src/App.js @@ -0,0 +1,21 @@ +import React from 'react' +import './App.css' +import { ToolBox } from './components/toolbox/ToolBox' +import { storeInstance } from './store' +import { Provider } from 'react-redux' +import Factory from './components/factory/Factory' +import Sells from './components/sells/Sells' + +const App = () => { + return ( + +
+ + + +
+
+ ) +} + +export default App diff --git a/src/App.test.js b/frontend/src/App.test.js similarity index 100% rename from src/App.test.js rename to frontend/src/App.test.js diff --git a/src/components/action_machine/ActionForMachine.css b/frontend/src/components/action_machine/ActionForMachine.css similarity index 100% rename from src/components/action_machine/ActionForMachine.css rename to frontend/src/components/action_machine/ActionForMachine.css diff --git a/src/components/action_machine/ActionForMachine.js b/frontend/src/components/action_machine/ActionForMachine.js similarity index 100% rename from src/components/action_machine/ActionForMachine.js rename to frontend/src/components/action_machine/ActionForMachine.js diff --git a/src/components/actions/move/Move.css b/frontend/src/components/actions/move/Move.css similarity index 100% rename from src/components/actions/move/Move.css rename to frontend/src/components/actions/move/Move.css diff --git a/src/components/actions/move/Move.js b/frontend/src/components/actions/move/Move.js similarity index 100% rename from src/components/actions/move/Move.js rename to frontend/src/components/actions/move/Move.js diff --git a/src/components/actions/remove/Remove.css b/frontend/src/components/actions/remove/Remove.css similarity index 100% rename from src/components/actions/remove/Remove.css rename to frontend/src/components/actions/remove/Remove.css diff --git a/src/components/actions/remove/Remove.js b/frontend/src/components/actions/remove/Remove.js similarity index 100% rename from src/components/actions/remove/Remove.js rename to frontend/src/components/actions/remove/Remove.js diff --git a/src/components/actions/rotate/Rotate.css b/frontend/src/components/actions/rotate/Rotate.css similarity index 100% rename from src/components/actions/rotate/Rotate.css rename to frontend/src/components/actions/rotate/Rotate.css diff --git a/src/components/actions/rotate/Rotate.js b/frontend/src/components/actions/rotate/Rotate.js similarity index 100% rename from src/components/actions/rotate/Rotate.js rename to frontend/src/components/actions/rotate/Rotate.js diff --git a/src/components/add_machine/AddMachine.css b/frontend/src/components/add_machine/AddMachine.css similarity index 100% rename from src/components/add_machine/AddMachine.css rename to frontend/src/components/add_machine/AddMachine.css diff --git a/src/components/add_machine/AddMachine.js b/frontend/src/components/add_machine/AddMachine.js similarity index 100% rename from src/components/add_machine/AddMachine.js rename to frontend/src/components/add_machine/AddMachine.js diff --git a/src/components/cell/Cell.css b/frontend/src/components/cell/Cell.css similarity index 100% rename from src/components/cell/Cell.css rename to frontend/src/components/cell/Cell.css diff --git a/src/components/cell/Cell.js b/frontend/src/components/cell/Cell.js similarity index 100% rename from src/components/cell/Cell.js rename to frontend/src/components/cell/Cell.js diff --git a/src/components/factory/Factory.css b/frontend/src/components/factory/Factory.css similarity index 100% rename from src/components/factory/Factory.css rename to frontend/src/components/factory/Factory.css diff --git a/src/components/factory/Factory.js b/frontend/src/components/factory/Factory.js similarity index 100% rename from src/components/factory/Factory.js rename to frontend/src/components/factory/Factory.js diff --git a/src/components/factory/actions.js b/frontend/src/components/factory/actions.js similarity index 91% rename from src/components/factory/actions.js rename to frontend/src/components/factory/actions.js index 978434a..d86388a 100644 --- a/src/components/factory/actions.js +++ b/frontend/src/components/factory/actions.js @@ -23,6 +23,12 @@ export const materialForStarter = (position, material) => { } } +export const RESET_FACTORY = 'RESET_FACTORY' +export const resetFactory = () => { + return { + type: RESET_FACTORY + } +} export const ADD_MACHINE = 'ADD_MACHINE' export const addMachine = (position, machineType) => { return { @@ -56,14 +62,16 @@ export const moveMachine = position => { } } +export const makeTick = () => { + return (dispatch, getState) => { + dispatch(doTick(findMachinesToTick(getState().factory))) + } +} export const TICK = 'TICK' export const tick = () => { return (dispatch, getState) => { if (!getState().factory.timer) { - let timer = setInterval( - () => dispatch(doTick(findMachinesToTick(getState().factory))), - 5000 - ) + let timer = setInterval(() => dispatch(makeTick()), 5000) dispatch(tickTimer(timer)) } } diff --git a/src/components/factory/factoryLib.js b/frontend/src/components/factory/factoryLib.js similarity index 71% rename from src/components/factory/factoryLib.js rename to frontend/src/components/factory/factoryLib.js index 50ea9b8..7886e74 100644 --- a/src/components/factory/factoryLib.js +++ b/frontend/src/components/factory/factoryLib.js @@ -1,7 +1,10 @@ import { + MATERIAL_ADDITION, + MATERIAL_DELETION, newMachine, NONE_MACHINE, rotateMachine, + SELLS, tickMachine, withMaterial } from '../machines/machines' @@ -48,11 +51,45 @@ export const addToSells = (sells, factory) => { } } -export const tick = (machinesPositions, state) => { - return machinesPositions.reduce( - (newState, position) => tickMachine(newState, position), - state - ) +export const tick = (machinesPositions, factory) => { + const machineMutations = machinesPositions + .map(position => tickMachine(factory, position)) + .flat(2) + + let newFactory = factory + + newFactory = machineMutations + .filter(mutation => mutation.type === SELLS) + .reduce( + (mutatedFactory, mutation) => mutation.action(mutatedFactory), + newFactory + ) + + newFactory = machineMutations + .filter(mutation => mutation.type === MATERIAL_DELETION) + .reduce( + (mutatedFactory, mutation) => + updatePositionWith( + mutation.position, + _ => mutation.action(), + mutatedFactory + ), + newFactory + ) + + newFactory = machineMutations + .filter(mutation => mutation.type === MATERIAL_ADDITION) + .reduce( + (mutatedFactory, mutation) => + updatePositionWith( + mutation.position, + _ => mutation.action(mutatedFactory), + mutatedFactory + ), + newFactory + ) + + return newFactory } export const addMachine = (position, machineType, factory) => { diff --git a/src/components/factory/factoryLib.spec.js b/frontend/src/components/factory/factoryLib.spec.js similarity index 100% rename from src/components/factory/factoryLib.spec.js rename to frontend/src/components/factory/factoryLib.spec.js diff --git a/src/components/factory/reducer.js b/frontend/src/components/factory/reducer.js similarity index 94% rename from src/components/factory/reducer.js rename to frontend/src/components/factory/reducer.js index 43f03e4..9e73e3c 100644 --- a/src/components/factory/reducer.js +++ b/frontend/src/components/factory/reducer.js @@ -3,6 +3,7 @@ import { MATERIAL_FOR_STARTER, MOVE_MACHINE, REMOVE_MACHINE, + RESET_FACTORY, ROTATE, SELECT_ACTION, SET_TICK_TIMER, @@ -24,6 +25,8 @@ const initialState = createFactoryBoard(5) export default (state = initialState, action) => { switch (action.type) { + case RESET_FACTORY: + return createFactoryBoard(state.rows) case MATERIAL_FOR_STARTER: return updatePositionWith( action.position, diff --git a/src/components/machines/crafter/Crafter.css b/frontend/src/components/machines/crafter/Crafter.css similarity index 100% rename from src/components/machines/crafter/Crafter.css rename to frontend/src/components/machines/crafter/Crafter.css diff --git a/src/components/machines/crafter/Crafter.js b/frontend/src/components/machines/crafter/Crafter.js similarity index 100% rename from src/components/machines/crafter/Crafter.js rename to frontend/src/components/machines/crafter/Crafter.js diff --git a/src/components/machines/direction.js b/frontend/src/components/machines/direction.js similarity index 98% rename from src/components/machines/direction.js rename to frontend/src/components/machines/direction.js index f47f4eb..b4bbd19 100644 --- a/src/components/machines/direction.js +++ b/frontend/src/components/machines/direction.js @@ -77,7 +77,7 @@ export const isPositionAtDirection = (position, direction, toPosition) => { return equals(positionAt(position, direction), toPosition) } -const equals = (left, right) => { +export const equals = (left, right) => { return left.x === right.x && left.y === right.y } diff --git a/src/components/machines/direction.spec.js b/frontend/src/components/machines/direction.spec.js similarity index 100% rename from src/components/machines/direction.spec.js rename to frontend/src/components/machines/direction.spec.js diff --git a/src/components/machines/furnace/Furnace.css b/frontend/src/components/machines/furnace/Furnace.css similarity index 100% rename from src/components/machines/furnace/Furnace.css rename to frontend/src/components/machines/furnace/Furnace.css diff --git a/src/components/machines/furnace/Furnace.js b/frontend/src/components/machines/furnace/Furnace.js similarity index 100% rename from src/components/machines/furnace/Furnace.js rename to frontend/src/components/machines/furnace/Furnace.js diff --git a/src/components/machines/machine/Machine.js b/frontend/src/components/machines/machine/Machine.js similarity index 100% rename from src/components/machines/machine/Machine.js rename to frontend/src/components/machines/machine/Machine.js diff --git a/src/components/machines/machine/Machine.spec.js b/frontend/src/components/machines/machine/Machine.spec.js similarity index 100% rename from src/components/machines/machine/Machine.spec.js rename to frontend/src/components/machines/machine/Machine.spec.js diff --git a/src/components/machines/machineCreator/MachineCreator.js b/frontend/src/components/machines/machineCreator/MachineCreator.js similarity index 75% rename from src/components/machines/machineCreator/MachineCreator.js rename to frontend/src/components/machines/machineCreator/MachineCreator.js index 93f9eee..67924fa 100644 --- a/src/components/machines/machineCreator/MachineCreator.js +++ b/frontend/src/components/machines/machineCreator/MachineCreator.js @@ -1,4 +1,4 @@ -import React, { Fragment } from 'react' +import React from 'react' import PropTypes from 'prop-types' import Starter from '../starter/Starter' import NoneMachine from '../none_machine/NoneMachine' @@ -7,12 +7,13 @@ import Furnace from '../furnace/Furnace' import Seller from '../seller/Seller' import Crafter from '../crafter/Crafter' import { + CRAFTER_MACHINE, FURNACE_MACHINE, SELLER_MACHINE, STARTER_MACHINE, - TRANSPORTER_MACHINE, - CRAFTER_MACHINE + TRANSPORTER_MACHINE } from '../machines' +import { column, row } from '../direction' function mapMachine (machine) { switch (machine.type) { @@ -32,7 +33,15 @@ function mapMachine (machine) { } export const MachineCreator = ({ machine }) => { - return {mapMachine(machine)} + let position = machine.props.position + return ( +
+ {mapMachine(machine)} +
+ ) } MachineCreator.propTypes = { diff --git a/src/components/machines/machineCreator/MachineCreator.spec.js b/frontend/src/components/machines/machineCreator/MachineCreator.spec.js similarity index 80% rename from src/components/machines/machineCreator/MachineCreator.spec.js rename to frontend/src/components/machines/machineCreator/MachineCreator.spec.js index dacf2f1..3b00459 100644 --- a/src/components/machines/machineCreator/MachineCreator.spec.js +++ b/frontend/src/components/machines/machineCreator/MachineCreator.spec.js @@ -8,14 +8,17 @@ import { import React from 'react' import { mount } from 'enzyme' import { TestProvider } from '../../tests_helpers/TestProvider' -import { south } from '../direction' +import { south, position } from '../direction' describe('machineCreator component', () => { describe('when machineCreator type is starter', () => { it('render the starter machineCreator', function () { let machineToRender = { type: STARTER_MACHINE, - props: { direction: south() } + props: { + direction: south(), + position: position(1, 1) + } } let machine = mount( @@ -29,7 +32,10 @@ describe('machineCreator component', () => { it('render the transporter machine', function () { let machineToRender = { type: TRANSPORTER_MACHINE, - props: { direction: south() } + props: { + direction: south(), + position: position(1, 1) + } } let machine = mount( @@ -43,7 +49,10 @@ describe('machineCreator component', () => { it('render the furnace machine', function () { let machineToRender = { type: FURNACE_MACHINE, - props: { direction: south() } + props: { + direction: south(), + position: position(1, 1) + } } let machine = mount( @@ -57,7 +66,10 @@ describe('machineCreator component', () => { it('render the seller machine', function () { let machineToRender = { type: SELLER_MACHINE, - props: { direction: south() } + props: { + direction: south(), + position: position(1, 1) + } } let machine = mount( @@ -69,7 +81,12 @@ describe('machineCreator component', () => { }) describe('when machineCreator type any other', () => { it('render the none machineCreator', function () { - let machineToRender = { type: 'lalala', props: {} } + let machineToRender = { + type: 'lalala', + props: { + position: position(1, 1) + } + } let machine = mount( diff --git a/src/components/machines/machines.js b/frontend/src/components/machines/machines.js similarity index 78% rename from src/components/machines/machines.js rename to frontend/src/components/machines/machines.js index 6b1c00f..53b2453 100644 --- a/src/components/machines/machines.js +++ b/frontend/src/components/machines/machines.js @@ -6,12 +6,7 @@ import { south, turnClockwise } from './direction' -import { - addToSells, - machineAt, - materialTo, - updatePositionWith -} from '../factory/factoryLib' +import { addToSells, machineAt } from '../factory/factoryLib' import { materialProfit, meltMaterials } from './materials' export const STARTER_MACHINE = 'STARTER_MACHINE' @@ -110,7 +105,7 @@ export const newMachine = (position, machineType) => { } export const tickMachine = (factory, position) => { - const machine = factory[position.y][position.x] + const machine = machineAt(position, factory) switch (machine.type) { case STARTER_MACHINE: return tickToStarter(factory, machine) @@ -123,82 +118,102 @@ export const tickMachine = (factory, position) => { case CRAFTER_MACHINE: return tickToCrafter(factory, machine) default: - return factory + return [] } } -const withMaterialsTick = (factory, machine, materials) => { +const withMaterialsTick = (factory, machine, materials, actions) => { let positionToDeliverMaterials = positionAt( machine.props.position, machine.props.direction ) if (canSendMaterials(factory, materials, positionToDeliverMaterials)) { - return materialTo( - positionToDeliverMaterials, - materials, - factory, - machine.props.position - ) + return [ + ...actions, + { + type: MATERIAL_ADDITION, + action: theFactory => + withMaterial( + machineAt(positionToDeliverMaterials, theFactory), + materials, + machine.props.position + ), + position: positionToDeliverMaterials + } + ] } - return factory + return actions } +const sell = (sells, actions) => { + return [ + ...actions, + { + type: SELLS, + action: factory => addToSells(sells, factory) + } + ] +} const tickToSeller = (factory, machine) => { const sells = machine.props.materials .map(material => materialProfit(material)) .reduce((totalSells, materialProfit) => totalSells + materialProfit, 0) - return updatePositionWith( - machine.props.position, - machine => clearMaterials(machine), - addToSells(sells, factory) - ) + let actions = [] + actions = clearMaterials(machine, actions) + actions = sell(sells, actions) + return actions } + const tickToFurnace = (factory, machine) => { const materials = meltMaterials(machine.props.materials) - const newfactory = withMaterialsTick(factory, machine, materials) - return updatePositionWith( - machine.props.position, - machine => clearMaterials(machine), - newfactory - ) + let actions = [] + actions = withMaterialsTick(factory, machine, materials, actions) + actions = clearMaterials(machine, actions) + return actions } const tickToTransporter = (factory, machine) => { const materials = machine.props.materials - const newfactory = withMaterialsTick(factory, machine, materials) - return updatePositionWith( - machine.props.position, - transporter => clearMaterials(transporter), - newfactory - ) + let actions = [] + actions = withMaterialsTick(factory, machine, materials, actions) + actions = clearMaterials(machine, actions) + return actions } const tickToCrafter = (factory, machine) => { + // TODO terminar de implementar el crafter const materials = machine.props.materials - const newfactory = withMaterialsTick(factory, machine, materials) - return updatePositionWith( - machine.props.position, - machine => clearMaterials(machine), - newfactory - ) + let actions = [] + actions = withMaterialsTick(factory, machine, materials, actions) + actions = clearMaterials(machine, actions) + return actions } -const clearMaterials = transporter => { - return { - ...transporter, +const clearMaterials = (machine, actions) => { + const newMachine = { + ...machine, props: { - ...transporter.props, + ...machine.props, materials: [], active: false } } + return [ + ...actions, + { + type: MATERIAL_DELETION, + action: () => newMachine, + position: machine.props.position + } + ] } const tickToStarter = (factory, machine) => { return withMaterialsTick( factory, machine, - machine.props.material ? [machine.props.material] : [] + machine.props.material ? [machine.props.material] : [], + [] ) } @@ -220,7 +235,7 @@ export const pointTo = (machine, direction) => { return { ...machine, props: { ...machine.props, direction: direction } } } -export const withMaterial = (machine, materials, fromPosition = undefined) => { +export const withMaterial = (machine, materials, fromPosition) => { switch (machine.type) { case NONE_MACHINE: return materialForNoneMachine(machine, materials) @@ -349,3 +364,7 @@ export const activate = machine => { export const isOfType = (machine, type) => { return machine.type === type } + +export const MATERIAL_ADDITION = 'MATERIAL_ADDITION' +export const MATERIAL_DELETION = 'MATERIAL_DELETION' +export const SELLS = 'SELLS' diff --git a/src/components/machines/machines.spec.js b/frontend/src/components/machines/machines.spec.js similarity index 87% rename from src/components/machines/machines.spec.js rename to frontend/src/components/machines/machines.spec.js index 039d530..2f7e1a0 100644 --- a/src/components/machines/machines.spec.js +++ b/frontend/src/components/machines/machines.spec.js @@ -2,11 +2,14 @@ import { east, north, position, positionAt, south, west } from './direction' import { FURNACE_MACHINE, isNoneMachine, + MATERIAL_ADDITION, + MATERIAL_DELETION, newMachine, NONE_MACHINE, pointTo, rotateMachine, SELLER_MACHINE, + SELLS, STARTER_MACHINE, tickMachine, TRANSPORTER_MACHINE, @@ -15,11 +18,10 @@ import { import { addMachine, emptyFactory, - machineAt, materialTo, updatePositionWith } from '../factory/factoryLib' -import { GOLD, isSolid, materialProfit, newMaterial, SILVER } from './materials' +import { GOLD, newMaterial, SILVER } from './materials' describe('machines', function () { let machinePosition = position(1, 1) @@ -301,14 +303,14 @@ describe('machines', function () { ) } - function itReturnsTheFactoryUnmodified (machinePosition, newFactory) { - expect(tickMachine(newFactory, machinePosition)).toEqual(newFactory) + function itReturnEmptyMutationList (machinePosition, newFactory) { + expect(tickMachine(newFactory, machinePosition)).toEqual([]) } function andTheMachineDirectionIs (direction, factory) { describe(`and the machine direction is ${direction.direction}`, () => { it('because there are no machineCreator there', () => { - itReturnsTheFactoryUnmodified( + itReturnEmptyMutationList( machinePosition, machineDirectionTo(machinePosition, direction, factory) ) @@ -321,7 +323,7 @@ describe('machines', function () { describe('and cant deliver material', () => { it('because the starter dont have a material selected', () => { - itReturnsTheFactoryUnmodified(machinePosition, newFactory) + itReturnEmptyMutationList(machinePosition, newFactory) }) andTheMachineDirectionIs(south(), newFactory) andTheMachineDirectionIs(north(), newFactory) @@ -350,13 +352,13 @@ describe('machines', function () { NONE_MACHINE, successTickFactory ) - it('deliver material there', () => { - expect( - machineAt( - newMachinePosition, - tickMachine(successTickFactory, machinePosition) - ).props.materialCount - ).toEqual(1) + it('returns the intetion to deliver the material there', () => { + const action = tickMachine( + successTickFactory, + machinePosition + )[0] + expect(action.type).toBe(MATERIAL_ADDITION) + expect(action.position).toEqual(newMachinePosition) }) }) }) @@ -376,7 +378,9 @@ describe('machines', function () { ) }) it('when the transporter is empty', function () { - itReturnsTheFactoryUnmodified(machinePosition, newFactory) + const action = tickMachine(newFactory, machinePosition)[0] + expect(action.type).toBe(MATERIAL_DELETION) + expect(action.position).toEqual(machinePosition) }) it('when the transporter has materials to deliver', () => { const otherMachinePosition = positionAt(transporterPosition, south()) @@ -394,17 +398,11 @@ describe('machines', function () { newFactory, fromPosition ) - newFactory = tickMachine(newFactory, transporterPosition) - - expect( - machineAt(transporterPosition, newFactory).props.materials.length - ).toBe(0) - expect(machineAt(transporterPosition, newFactory).props.active).toBe( - false - ) - expect( - machineAt(otherMachinePosition, newFactory).props.materialCount - ).toBe(2) + const actions = tickMachine(newFactory, transporterPosition) + expect(actions[0].type).toBe(MATERIAL_ADDITION) + expect(actions[0].position).toEqual(otherMachinePosition) + expect(actions[1].type).toBe(MATERIAL_DELETION) + expect(actions[1].position).toEqual(transporterPosition) }) }) describe('when tick on a furnace machine', () => { @@ -416,7 +414,9 @@ describe('machines', function () { newFactory = addMachine(furnacePosition, FURNACE_MACHINE, factory) }) it('when the furnace is empty', function () { - itReturnsTheFactoryUnmodified(machinePosition, newFactory) + const actions = tickMachine(newFactory, machinePosition) + expect(actions[0].type).toBe(MATERIAL_DELETION) + expect(actions[0].position).toEqual(machinePosition) }) it('when the furnace has materials to melt', () => { const otherMachinePosition = positionAt(furnacePosition, south()) @@ -434,15 +434,11 @@ describe('machines', function () { newFactory, fromPosition ) - newFactory = tickMachine(newFactory, furnacePosition) - const expectedFurnace = machineAt(furnacePosition, newFactory) - const expectedTransporter = machineAt(otherMachinePosition, newFactory) - - expect(expectedFurnace.props.materials.length).toBe(0) - expect(expectedFurnace.props.active).toBe(false) - expect(expectedTransporter.props.materials.length).toBe(2) - expect(isSolid(expectedTransporter.props.materials[0])).toBe(false) - expect(isSolid(expectedTransporter.props.materials[1])).toBe(false) + const actions = tickMachine(newFactory, furnacePosition) + expect(actions[0].type).toBe(MATERIAL_ADDITION) + expect(actions[0].position).toEqual(otherMachinePosition) + expect(actions[1].type).toBe(MATERIAL_DELETION) + expect(actions[1].position).toEqual(furnacePosition) }) }) describe('when tick on a seller machine', () => { @@ -454,7 +450,9 @@ describe('machines', function () { newFactory = addMachine(sellerPosition, SELLER_MACHINE, factory) }) it('when the seller is empty', function () { - itReturnsTheFactoryUnmodified(machinePosition, newFactory) + const actions = tickMachine(newFactory, machinePosition) + expect(actions[0].type).toBe(MATERIAL_DELETION) + expect(actions[0].position).toEqual(machinePosition) }) it('when the seller has materials to sell', () => { const fromPosition = positionAt(sellerPosition, north()) @@ -467,19 +465,15 @@ describe('machines', function () { newFactory, fromPosition ) - newFactory = tickMachine(newFactory, sellerPosition) - - const expectedSeller = machineAt(sellerPosition, newFactory) - const expectedSells = materialProfit(gold) + materialProfit(silver) - - expect(expectedSeller.props.materials.length).toBe(0) - expect(expectedSeller.props.active).toBe(false) - expect(newFactory.totalSells).toBe(expectedSells) + const actions = tickMachine(newFactory, sellerPosition) + expect(actions[0].type).toBe(MATERIAL_DELETION) + expect(actions[0].position).toEqual(sellerPosition) + expect(actions[1].type).toBe(SELLS) }) }) it('when tick on any other machineCreator', () => { let newFactory = addMachine(machinePosition, NONE_MACHINE, factory) - itReturnsTheFactoryUnmodified(machinePosition, newFactory) + itReturnEmptyMutationList(machinePosition, newFactory) }) }) }) diff --git a/src/components/machines/materials.js b/frontend/src/components/machines/materials.js similarity index 100% rename from src/components/machines/materials.js rename to frontend/src/components/machines/materials.js diff --git a/src/components/machines/materials.spec.js b/frontend/src/components/machines/materials.spec.js similarity index 100% rename from src/components/machines/materials.spec.js rename to frontend/src/components/machines/materials.spec.js diff --git a/src/components/machines/none_machine/NoneMachine.css b/frontend/src/components/machines/none_machine/NoneMachine.css similarity index 100% rename from src/components/machines/none_machine/NoneMachine.css rename to frontend/src/components/machines/none_machine/NoneMachine.css diff --git a/src/components/machines/none_machine/NoneMachine.js b/frontend/src/components/machines/none_machine/NoneMachine.js similarity index 100% rename from src/components/machines/none_machine/NoneMachine.js rename to frontend/src/components/machines/none_machine/NoneMachine.js diff --git a/src/components/machines/seller/Seller.css b/frontend/src/components/machines/seller/Seller.css similarity index 100% rename from src/components/machines/seller/Seller.css rename to frontend/src/components/machines/seller/Seller.css diff --git a/src/components/machines/seller/Seller.js b/frontend/src/components/machines/seller/Seller.js similarity index 100% rename from src/components/machines/seller/Seller.js rename to frontend/src/components/machines/seller/Seller.js diff --git a/src/components/machines/seller/Seller.storybook.js b/frontend/src/components/machines/seller/Seller.storybook.js similarity index 100% rename from src/components/machines/seller/Seller.storybook.js rename to frontend/src/components/machines/seller/Seller.storybook.js diff --git a/src/components/machines/starter/Starter.css b/frontend/src/components/machines/starter/Starter.css similarity index 100% rename from src/components/machines/starter/Starter.css rename to frontend/src/components/machines/starter/Starter.css diff --git a/src/components/machines/starter/Starter.js b/frontend/src/components/machines/starter/Starter.js similarity index 100% rename from src/components/machines/starter/Starter.js rename to frontend/src/components/machines/starter/Starter.js diff --git a/src/components/machines/starter/Starter.spec.js b/frontend/src/components/machines/starter/Starter.spec.js similarity index 100% rename from src/components/machines/starter/Starter.spec.js rename to frontend/src/components/machines/starter/Starter.spec.js diff --git a/src/components/machines/starter/Starter.storybook.js b/frontend/src/components/machines/starter/Starter.storybook.js similarity index 100% rename from src/components/machines/starter/Starter.storybook.js rename to frontend/src/components/machines/starter/Starter.storybook.js diff --git a/src/components/machines/starter/StarterToolbox.js b/frontend/src/components/machines/starter/StarterToolbox.js similarity index 100% rename from src/components/machines/starter/StarterToolbox.js rename to frontend/src/components/machines/starter/StarterToolbox.js diff --git a/src/components/machines/transporter/Transporter.css b/frontend/src/components/machines/transporter/Transporter.css similarity index 100% rename from src/components/machines/transporter/Transporter.css rename to frontend/src/components/machines/transporter/Transporter.css diff --git a/src/components/machines/transporter/Transporter.js b/frontend/src/components/machines/transporter/Transporter.js similarity index 100% rename from src/components/machines/transporter/Transporter.js rename to frontend/src/components/machines/transporter/Transporter.js diff --git a/src/components/machines/transporter/Transporter.storybook.js b/frontend/src/components/machines/transporter/Transporter.storybook.js similarity index 100% rename from src/components/machines/transporter/Transporter.storybook.js rename to frontend/src/components/machines/transporter/Transporter.storybook.js diff --git a/src/components/occultable/Occultable.js b/frontend/src/components/occultable/Occultable.js similarity index 100% rename from src/components/occultable/Occultable.js rename to frontend/src/components/occultable/Occultable.js diff --git a/src/components/occultable/Occultable.spec.js b/frontend/src/components/occultable/Occultable.spec.js similarity index 100% rename from src/components/occultable/Occultable.spec.js rename to frontend/src/components/occultable/Occultable.spec.js diff --git a/src/components/occultable/Occultable.storybook.js b/frontend/src/components/occultable/Occultable.storybook.js similarity index 100% rename from src/components/occultable/Occultable.storybook.js rename to frontend/src/components/occultable/Occultable.storybook.js diff --git a/src/components/raw_material/RawMaterial.css b/frontend/src/components/raw_material/RawMaterial.css similarity index 100% rename from src/components/raw_material/RawMaterial.css rename to frontend/src/components/raw_material/RawMaterial.css diff --git a/src/components/raw_material/RawMaterial.js b/frontend/src/components/raw_material/RawMaterial.js similarity index 100% rename from src/components/raw_material/RawMaterial.js rename to frontend/src/components/raw_material/RawMaterial.js diff --git a/src/components/raw_material/RawMaterial.spec.js b/frontend/src/components/raw_material/RawMaterial.spec.js similarity index 100% rename from src/components/raw_material/RawMaterial.spec.js rename to frontend/src/components/raw_material/RawMaterial.spec.js diff --git a/src/components/raw_material/RawMaterial.storybook.js b/frontend/src/components/raw_material/RawMaterial.storybook.js similarity index 100% rename from src/components/raw_material/RawMaterial.storybook.js rename to frontend/src/components/raw_material/RawMaterial.storybook.js diff --git a/src/components/raw_material_popup/RawMaterialPopup.css b/frontend/src/components/raw_material_popup/RawMaterialPopup.css similarity index 100% rename from src/components/raw_material_popup/RawMaterialPopup.css rename to frontend/src/components/raw_material_popup/RawMaterialPopup.css diff --git a/src/components/raw_material_popup/RawMaterialPopup.js b/frontend/src/components/raw_material_popup/RawMaterialPopup.js similarity index 100% rename from src/components/raw_material_popup/RawMaterialPopup.js rename to frontend/src/components/raw_material_popup/RawMaterialPopup.js diff --git a/src/components/raw_material_popup/RawMaterialPopup.spec.js b/frontend/src/components/raw_material_popup/RawMaterialPopup.spec.js similarity index 100% rename from src/components/raw_material_popup/RawMaterialPopup.spec.js rename to frontend/src/components/raw_material_popup/RawMaterialPopup.spec.js diff --git a/src/components/raw_material_popup/RawMaterialPopup.storybook.js b/frontend/src/components/raw_material_popup/RawMaterialPopup.storybook.js similarity index 100% rename from src/components/raw_material_popup/RawMaterialPopup.storybook.js rename to frontend/src/components/raw_material_popup/RawMaterialPopup.storybook.js diff --git a/src/components/raw_material_popup/actions.js b/frontend/src/components/raw_material_popup/actions.js similarity index 100% rename from src/components/raw_material_popup/actions.js rename to frontend/src/components/raw_material_popup/actions.js diff --git a/src/components/raw_material_popup/reducer.js b/frontend/src/components/raw_material_popup/reducer.js similarity index 100% rename from src/components/raw_material_popup/reducer.js rename to frontend/src/components/raw_material_popup/reducer.js diff --git a/src/components/raw_material_selector/RawMaterialSelector.css b/frontend/src/components/raw_material_selector/RawMaterialSelector.css similarity index 100% rename from src/components/raw_material_selector/RawMaterialSelector.css rename to frontend/src/components/raw_material_selector/RawMaterialSelector.css diff --git a/src/components/raw_material_selector/RawMaterialSelector.js b/frontend/src/components/raw_material_selector/RawMaterialSelector.js similarity index 100% rename from src/components/raw_material_selector/RawMaterialSelector.js rename to frontend/src/components/raw_material_selector/RawMaterialSelector.js diff --git a/src/components/raw_material_selector/RawMaterialSelector.spec.js b/frontend/src/components/raw_material_selector/RawMaterialSelector.spec.js similarity index 100% rename from src/components/raw_material_selector/RawMaterialSelector.spec.js rename to frontend/src/components/raw_material_selector/RawMaterialSelector.spec.js diff --git a/src/components/raw_material_selector/RawMaterialSelector.storybook.js b/frontend/src/components/raw_material_selector/RawMaterialSelector.storybook.js similarity index 100% rename from src/components/raw_material_selector/RawMaterialSelector.storybook.js rename to frontend/src/components/raw_material_selector/RawMaterialSelector.storybook.js diff --git a/src/components/raw_material_selector/actions.js b/frontend/src/components/raw_material_selector/actions.js similarity index 100% rename from src/components/raw_material_selector/actions.js rename to frontend/src/components/raw_material_selector/actions.js diff --git a/src/components/raw_material_selector/reducer.js b/frontend/src/components/raw_material_selector/reducer.js similarity index 100% rename from src/components/raw_material_selector/reducer.js rename to frontend/src/components/raw_material_selector/reducer.js diff --git a/src/components/sells/Sells.css b/frontend/src/components/sells/Sells.css similarity index 100% rename from src/components/sells/Sells.css rename to frontend/src/components/sells/Sells.css diff --git a/src/components/sells/Sells.js b/frontend/src/components/sells/Sells.js similarity index 100% rename from src/components/sells/Sells.js rename to frontend/src/components/sells/Sells.js diff --git a/src/components/tests_helpers/TestProvider.jsx b/frontend/src/components/tests_helpers/TestProvider.jsx similarity index 100% rename from src/components/tests_helpers/TestProvider.jsx rename to frontend/src/components/tests_helpers/TestProvider.jsx diff --git a/src/components/toolbox/ToolBox.css b/frontend/src/components/toolbox/ToolBox.css similarity index 100% rename from src/components/toolbox/ToolBox.css rename to frontend/src/components/toolbox/ToolBox.css diff --git a/src/components/toolbox/ToolBox.js b/frontend/src/components/toolbox/ToolBox.js similarity index 100% rename from src/components/toolbox/ToolBox.js rename to frontend/src/components/toolbox/ToolBox.js diff --git a/src/index.css b/frontend/src/index.css similarity index 100% rename from src/index.css rename to frontend/src/index.css diff --git a/src/index.js b/frontend/src/index.js similarity index 100% rename from src/index.js rename to frontend/src/index.js diff --git a/src/rootReducer.js b/frontend/src/rootReducer.js similarity index 100% rename from src/rootReducer.js rename to frontend/src/rootReducer.js diff --git a/src/serviceWorker.js b/frontend/src/serviceWorker.js similarity index 100% rename from src/serviceWorker.js rename to frontend/src/serviceWorker.js diff --git a/frontend/src/setupTests.js b/frontend/src/setupTests.js new file mode 100644 index 0000000..5dd2056 --- /dev/null +++ b/frontend/src/setupTests.js @@ -0,0 +1,15 @@ +// setup file +import { configure } from 'enzyme' +import Adapter from 'enzyme-adapter-react-16' +import 'core-js/features/array/flat' +import 'core-js/features/array/map' +import 'core-js/features/array/reduce' +import 'core-js/features/array/find' +import 'core-js/features/object/entries' +import 'core-js/features/object/keys' +import 'core-js/features/object/values' +import 'core-js/features/object/to-string' + +import 'react-app-polyfill/jsdom' + +configure({ adapter: new Adapter() }) diff --git a/frontend/src/specs/addMachines.spec.js b/frontend/src/specs/addMachines.spec.js new file mode 100644 index 0000000..d3e372f --- /dev/null +++ b/frontend/src/specs/addMachines.spec.js @@ -0,0 +1,91 @@ +import React from 'react' +import App from '../App' +import { mount } from 'enzyme' +import { click, onFactoryPosition, onMachine, onToolbox } from './helpper' + +describe('App', () => { + let app + beforeEach(() => { + app = mount() + }) + afterEach(() => { + app.unmount() + }) + describe('Machines addition', () => { + describe('When clicked on Starter button and then on board position (1,1)', () => { + test('creates a Starter machine at (1,1) on the board', () => { + onToolbox(app, toolbox => onMachine('.starter', click, toolbox)) + onFactoryPosition(app, 11, position => + onMachine('.none_machine', click, position) + ) + + const assert = starter => { + expect(starter.length).toBe(1) + } + onFactoryPosition(app, 11, position => + onMachine('.starter', assert, position) + ) + }) + }) + describe('When clicked on Transporter button and then on board position (2,1)', () => { + test('creates a Transporter machine at (2,1) on the board', () => { + onToolbox(app, toolbox => onMachine('.transporter', click, toolbox)) + onFactoryPosition(app, 21, position => + onMachine('.none_machine', click, position) + ) + + const assert = transporter => { + expect(transporter.length).toBe(1) + } + onFactoryPosition(app, 21, position => + onMachine('.transporter', assert, position) + ) + }) + }) + describe('When clicked on Seller button and then on board position (3,1)', () => { + test('creates a Seller machine at (3,1) on the board', () => { + onToolbox(app, toolbox => onMachine('.seller', click, toolbox)) + onFactoryPosition(app, 31, position => + onMachine('.none_machine', click, position) + ) + + const assert = seller => { + expect(seller.length).toBe(1) + } + onFactoryPosition(app, 31, position => + onMachine('.seller', assert, position) + ) + }) + }) + describe('When clicked on Furnace button and then on board position (4,1)', () => { + test('creates a Furnace machine at (4,1) on the board', () => { + onToolbox(app, toolbox => onMachine('.furnace', click, toolbox)) + onFactoryPosition(app, 41, position => + onMachine('.none_machine', click, position) + ) + + const assert = furnace => { + expect(furnace.length).toBe(1) + } + onFactoryPosition(app, 41, position => + onMachine('.furnace', assert, position) + ) + }) + }) + describe('When clicked on Crafter button and then on board position (5,1)', () => { + test('creates a Crafter machine at (4,4) on the board', () => { + onToolbox(app, toolbox => onMachine('.crafter', click, toolbox)) + onFactoryPosition(app, 44, position => + onMachine('.none_machine', click, position) + ) + + const assert = crafter => { + expect(crafter.length).toBe(1) + } + onFactoryPosition(app, 44, position => + onMachine('.crafter', assert, position) + ) + }) + }) + }) +}) diff --git a/frontend/src/specs/deleteMachines.spec.js b/frontend/src/specs/deleteMachines.spec.js new file mode 100644 index 0000000..b5cab02 --- /dev/null +++ b/frontend/src/specs/deleteMachines.spec.js @@ -0,0 +1,40 @@ +import React from 'react' +import App from '../App' +import { mount } from 'enzyme' +import { + deleteOn, + machineAbsent, + machinePresent, + onFactoryPosition, + onMachine, + withMachine +} from './helpper' + +describe('App', () => { + let app + beforeEach(() => { + app = mount() + }) + afterEach(() => { + app.unmount() + }) + describe('Machines deletion', () => { + describe('with a starter on 1,1 and a transporter on 1,2', () => { + beforeEach(() => { + withMachine('.starter', 11, app) + withMachine('.transporter', 12, app) + }) + describe('When clicked on the deletion button and then on board position (1,1)', () => { + test('only deletes the starter', () => { + deleteOn(11, '.starter', app) + onFactoryPosition(app, 11, position => + onMachine('.starter', machineAbsent, position) + ) + onFactoryPosition(app, 12, position => + onMachine('.transporter', machinePresent, position) + ) + }) + }) + }) + }) +}) diff --git a/frontend/src/specs/factoryTicks.spec.js b/frontend/src/specs/factoryTicks.spec.js new file mode 100644 index 0000000..92cae8f --- /dev/null +++ b/frontend/src/specs/factoryTicks.spec.js @@ -0,0 +1,121 @@ +import React from 'react' +import App from '../App' +import { mount } from 'enzyme' +import { storeInstance } from '../store' +import { + materialProfit, + meltMaterials, + newMaterial, + SILVER +} from '../components/machines/materials' +import { machineAt } from '../components/factory/factoryLib' +import { position } from '../components/machines/direction' +import { + onFactoryPosition, + onMachine, + rotateOn, + tickFactory, + withMachine +} from './helpper' +import { materialForStarter, resetFactory } from '../components/factory/actions' + +describe('App', () => { + let app + beforeEach(() => { + app = mount() + storeInstance.dispatch(resetFactory()) + }) + afterEach(() => { + app.unmount() + }) + describe('factory board', () => { + beforeEach(() => { + clearInterval(storeInstance.getState().factory.timer) + }) + describe('with some machines in it', () => { + beforeEach(() => { + withMachine('.starter', '03', app) + storeInstance.dispatch( + materialForStarter(position(0, 3), newMaterial(SILVER)) + ) + withMachine('.furnace', '13', app) + withMachine('.transporter', '23', app) + rotateOn('23', '.transporter', app) + withMachine('.transporter', '22', app) + rotateOn('22', '.transporter', app) + rotateOn('22', '.transporter', app) + withMachine('.seller', '12', app) + }) + const hasImageActive = machine => { + expect( + machine + .find('img') + .html() + .includes('_active.svg') + ).toBe(true) + } + test('after one tick ', () => { + tickFactory() + expect( + machineAt(position(1, 3), state().factory).props.materials[0] + ).toEqual(newMaterial(SILVER)) + onFactoryPosition(app, '03', position => { + onMachine('.starter', hasImageActive, position) + }) + }) + test('after two ticks ', () => { + tickFactory() + tickFactory() + let state1 = storeInstance.getState() + expect( + machineAt(position(2, 3), state1.factory).props.materials[0] + ).toEqual(meltMaterials([newMaterial(SILVER)])[0]) + onFactoryPosition(app, '13', position => { + onMachine('.furnace', hasImageActive, position) + }) + }) + test('after three ticks ', () => { + tickFactory() + tickFactory() + tickFactory() + expect( + machineAt(position(2, 2), storeInstance.getState().factory).props + .materials[0] + ).toEqual(meltMaterials([newMaterial(SILVER)])[0]) + onFactoryPosition(app, '23', position => { + onMachine('.transporter', hasImageActive, position) + }) + }) + test('after four ticks ', () => { + tickFactory() + tickFactory() + tickFactory() + tickFactory() + expect( + machineAt(position(1, 2), storeInstance.getState().factory).props + .materials[0] + ).toEqual(meltMaterials([newMaterial(SILVER)])[0]) + onFactoryPosition(app, '22', position => { + onMachine('.transporter', hasImageActive, position) + }) + }) + test('after five ticks ', () => { + tickFactory() + tickFactory() + tickFactory() + tickFactory() + tickFactory() + expect(storeInstance.getState().factory.totalSells).toBe( + materialProfit(meltMaterials([newMaterial(SILVER)])[0]) + ) + onFactoryPosition(app, '12', position => { + onMachine('.seller', hasImageActive, position) + }) + }) + }) + }) +}) + +const state = () => { + return storeInstance.getState() +} diff --git a/frontend/src/specs/helpper.js b/frontend/src/specs/helpper.js new file mode 100644 index 0000000..0387244 --- /dev/null +++ b/frontend/src/specs/helpper.js @@ -0,0 +1,71 @@ +import { storeInstance } from '../store' +import { makeTick } from '../components/factory/actions' + +export const onToolbox = (app, callback) => { + callback(app.find('.toolbox-board')) +} +export const onMachine = (machine, callback, app) => { + callback(app.find(machine)) +} +export const click = app => { + app.simulate('click') +} + +export const onFactoryPosition = (app, position, callback) => { + callback(app.find('.factory').find(`[position="${position}"]`)) +} + +export const onMaterial = (material, callback, app) => { + callback( + app + .find('.raw_material-name') + .filterWhere(item => item.props().children === material) + .parent() + ) +} + +export const onRawMaterialPopUp = (app, callback) => { + callback(app.find('.raw-material-selector')) +} + +export const withMachine = (machine, position, app) => { + onToolbox(app, toolbox => onMachine(machine, click, toolbox)) + onFactoryPosition(app, position, position => + onMachine('.none_machine', click, position) + ) +} + +export const machineAbsent = machine => { + expect(machine.length).toBe(0) +} +export const machinePresent = machine => { + expect(machine.length).toBe(1) +} + +export const deleteOn = (position, machine, app) => { + onToolbox(app, toolbox => onMachine('.remove', click, toolbox)) + onFactoryPosition(app, position, position => + onMachine(machine, click, position) + ) +} + +export const rotateOn = (position, machine, app) => { + onToolbox(app, toolbox => onMachine('.rotate', click, toolbox)) + onFactoryPosition(app, position, position => + onMachine(machine, click, position) + ) +} + +export const moveFromTo = (positionFrom, positionTo, machine, app) => { + onToolbox(app, toolbox => onMachine('.move', click, toolbox)) + onFactoryPosition(app, positionFrom, position => + onMachine(machine, click, position) + ) + onFactoryPosition(app, positionTo, position => + onMachine('.none_machine', click, position) + ) +} + +export const tickFactory = () => { + storeInstance.dispatch(makeTick()) +} diff --git a/frontend/src/specs/moveMachines.spec.js b/frontend/src/specs/moveMachines.spec.js new file mode 100644 index 0000000..63a505c --- /dev/null +++ b/frontend/src/specs/moveMachines.spec.js @@ -0,0 +1,43 @@ +import React from 'react' +import App from '../App' +import { mount } from 'enzyme' +import { + machineAbsent, + machinePresent, + moveFromTo, + onFactoryPosition, + onMachine, + withMachine +} from './helpper' + +describe('App', () => { + let app + beforeEach(() => { + app = mount() + }) + afterEach(() => { + app.unmount() + }) + describe('Machines move', () => { + describe('with a starter on 1,1 and a transporter on 1,2', () => { + beforeEach(() => { + withMachine('.starter', 11, app) + withMachine('.transporter', 12, app) + }) + describe('When clicked on the move button then on board position (1,1) and then on the position (1,3)', () => { + test('move the starter', () => { + moveFromTo(11, 13, '.starter', app) + onFactoryPosition(app, 11, position => + onMachine('.starter', machineAbsent, position) + ) + onFactoryPosition(app, 12, position => + onMachine('.transporter', machinePresent, position) + ) + onFactoryPosition(app, 13, position => + onMachine('.starter', machinePresent, position) + ) + }) + }) + }) + }) +}) diff --git a/frontend/src/specs/rotateMachines.spec.js b/frontend/src/specs/rotateMachines.spec.js new file mode 100644 index 0000000..2cc7da0 --- /dev/null +++ b/frontend/src/specs/rotateMachines.spec.js @@ -0,0 +1,43 @@ +import React from 'react' +import App from '../App' +import { mount } from 'enzyme' +import { onFactoryPosition, onMachine, rotateOn, withMachine } from './helpper' + +describe('App', () => { + let app + beforeEach(() => { + app = mount() + }) + afterEach(() => { + app.unmount() + }) + describe('Machines rotation', () => { + describe('with a starter on 1,1 and a transporter on 1,2', () => { + beforeEach(() => { + withMachine('.starter', 11, app) + withMachine('.transporter', 12, app) + }) + describe('When clicked on the rotate button and then on board position (1,1)', () => { + const machineRotates = machine => { + expect(machine.find('img').props().style.transform).toEqual( + 'rotate(0.25turn)' + ) + } + const machineNotRotates = machine => { + expect(machine.find('img').props().style.transform).toEqual( + 'rotate(0turn)' + ) + } + test('only rotates the starter', () => { + rotateOn(11, '.starter', app) + onFactoryPosition(app, 11, position => + onMachine('.starter', machineRotates, position) + ) + onFactoryPosition(app, 12, position => + onMachine('.transporter', machineNotRotates, position) + ) + }) + }) + }) + }) +}) diff --git a/src/store.js b/frontend/src/store.js similarity index 100% rename from src/store.js rename to frontend/src/store.js diff --git a/src/stories/index.js b/frontend/src/stories/index.js similarity index 100% rename from src/stories/index.js rename to frontend/src/stories/index.js diff --git a/yarn.lock b/frontend/yarn.lock similarity index 99% rename from yarn.lock rename to frontend/yarn.lock index 86b1bbe..059dd75 100755 --- a/yarn.lock +++ b/frontend/yarn.lock @@ -4152,6 +4152,11 @@ core-js@^2.5.7, core-js@^2.6.5: resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.5.tgz#44bc8d249e7fb2ff5d00e0341a7ffb94fbf67895" integrity sha512-klh/kDpwX8hryYL14M9w/xei6vrv6sE8gTHDG7/T/+SEovB/G4ejwcfE/CBzO6Edsu+OETZMZ3wcX/EjUkrl5A== +core-js@^3.1.3: + version "3.1.3" + resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.1.3.tgz#95700bca5f248f5f78c0ec63e784eca663ec4138" + integrity sha512-PWZ+ZfuaKf178BIAg+CRsljwjIMRV8MY00CbZczkR6Zk5LfkSkjGoaab3+bqRQWVITNZxQB7TFYz+CFcyuamvA== + core-util-is@1.0.2, core-util-is@~1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" @@ -10804,6 +10809,18 @@ react-app-polyfill@^0.2.2: raf "3.4.1" whatwg-fetch "3.0.0" +react-app-polyfill@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/react-app-polyfill/-/react-app-polyfill-1.0.1.tgz#809a858e44f9564c7f4205e173076f90048274f1" + integrity sha512-LbVpT1NdzTdDDs7xEZdebjDrqsvKi5UyVKUQqtTYYNyC1JJYVAwNQWe4ybWvoT2V2WW9PGVO2u5Y6aVj4ER/Ow== + dependencies: + core-js "3.0.1" + object-assign "4.1.1" + promise "8.0.2" + raf "3.4.1" + regenerator-runtime "0.13.2" + whatwg-fetch "3.0.0" + react-clientside-effect@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/react-clientside-effect/-/react-clientside-effect-1.2.0.tgz#db823695f75e9616a5e4dd6d908e5ea627fb2516" @@ -11324,6 +11341,11 @@ regenerate@^1.2.1, regenerate@^1.4.0: resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.4.0.tgz#4a856ec4b56e4077c557589cae85e7a4c8869a11" integrity sha512-1G6jJVDWrt0rK99kBjvEtziZNCICAuvIPkSiUFIQxVP06RCVpq3dmDo2oi6ABpYaDYaTRr67BEhL8r1wgEZZKg== +regenerator-runtime@0.13.2, regenerator-runtime@^0.13.2: + version "0.13.2" + resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.2.tgz#32e59c9a6fb9b1a4aff09b4930ca2d4477343447" + integrity sha512-S/TQAZJO+D3m9xeN1WTI8dLKBBiRgXBlTJvbWjCThHWZj9EvHK70Ff50/tYj2J/fvBY6JtFVwRuazHN2E7M9BA== + regenerator-runtime@^0.11.0: version "0.11.1" resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz#be05ad7f9bf7d22e056f9726cee5017fbf19e2e9" @@ -11334,11 +11356,6 @@ regenerator-runtime@^0.12.0, regenerator-runtime@^0.12.1: resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.12.1.tgz#fa1a71544764c036f8c49b13a08b2594c9f8a0de" integrity sha512-odxIc1/vDlo4iZcfXqRYFj0vpXFNoGdKMAUieAlFYO6m/nl5e9KR/beGf41z4a1FI+aQgtjhuaSlDxQ0hmkrHg== -regenerator-runtime@^0.13.2: - version "0.13.2" - resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.2.tgz#32e59c9a6fb9b1a4aff09b4930ca2d4477343447" - integrity sha512-S/TQAZJO+D3m9xeN1WTI8dLKBBiRgXBlTJvbWjCThHWZj9EvHK70Ff50/tYj2J/fvBY6JtFVwRuazHN2E7M9BA== - regenerator-transform@^0.13.3: version "0.13.3" resolved "https://registry.yarnpkg.com/regenerator-transform/-/regenerator-transform-0.13.3.tgz#264bd9ff38a8ce24b06e0636496b2c856b57bcbb" diff --git a/src/App.js b/src/App.js deleted file mode 100644 index 121c5c2..0000000 --- a/src/App.js +++ /dev/null @@ -1,30 +0,0 @@ -import React, { Component } from 'react' -import './App.css' -import { ToolBox } from './components/toolbox/ToolBox' -import { storeInstance } from './store' -import { Provider } from 'react-redux' -import Factory from './components/factory/Factory' -import Sells from './components/sells/Sells' - -class App extends Component { - constructor (props) { - super(props) - this.user = { - incomes: 0 - } - } - - render () { - return ( - -
- - - -
-
- ) - } -} - -export default App diff --git a/src/setupTests.js b/src/setupTests.js deleted file mode 100644 index 1b4377f..0000000 --- a/src/setupTests.js +++ /dev/null @@ -1,5 +0,0 @@ -// setup file -import { configure } from 'enzyme' -import Adapter from 'enzyme-adapter-react-16' - -configure({ adapter: new Adapter() })