From 06e16dad17595c971abd439101a3968d295cb193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Fut=C3=B3?= Date: Sun, 6 Jun 2021 01:23:07 +0100 Subject: [PATCH] Added cypress + pages/new.js redirect --- fb/bin/fb | 6 ++ fb/src/cypress.json | 3 + fb/src/cypress/integration/pages.js | 100 ++++++++++++++++++++++++++++ fb/src/pages/new.js | 4 +- 4 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 fb/src/cypress.json create mode 100644 fb/src/cypress/integration/pages.js diff --git a/fb/bin/fb b/fb/bin/fb index 34ad23e..0696d8b 100755 --- a/fb/bin/fb +++ b/fb/bin/fb @@ -60,6 +60,12 @@ case $1 in gcloud iam service-accounts keys create /tmp/keys --iam-account=$iamaccount keysbase64="$( cat /tmp/keys | base64 )" # Is used at the ending prompts + # CYPRESS INSTALL & CONFIGURATION + npm install cypress --save-dev + cp $dir/src/cypress.json . + cp -r $dir/src/cypress . + sed -i '' "s/\(^\/coverage\)/\1\n\/cypress\/screenshots\n\/cypress\/videos/g" .gitignore + ## MAIN npm install uuid cp $dir/src/next.config.js . diff --git a/fb/src/cypress.json b/fb/src/cypress.json new file mode 100644 index 0000000..17ef242 --- /dev/null +++ b/fb/src/cypress.json @@ -0,0 +1,3 @@ +{ + "baseUrl": "http://localhost:3000" +} diff --git a/fb/src/cypress/integration/pages.js b/fb/src/cypress/integration/pages.js new file mode 100644 index 0000000..46bc561 --- /dev/null +++ b/fb/src/cypress/integration/pages.js @@ -0,0 +1,100 @@ +describe('pages/', () => { + context('[username].js', () => { + it('works', () => cy.visit("/random")) + context('if user does not exist', () => { + it('redirects to /index.js', () => { + cy.visit('/random'); + cy.location().should(loc => { + expect(loc.pathname).to.eq('/'); + }) + }) + }) + + context('user with username "optimistavf" does exist', () => { + it('contains @optimistavf', () => { + cy.visit('/optimistavf'); + cy.contains("@optimistavf"); + }) + }) + }); + + context('account/reset.js', () => { + it('works', () => cy.visit("/account/reset")) + }); + + context('account/confirm.js', () => { + it('works', () => cy.visit("/account/confirm")) + context('if not provided oobCode', () => { + it('redirects to /account/reset.js', () => { + cy.visit('/account/confirm'); + cy.location().should(loc => { + expect(loc.pathname).to.eq('/account/reset'); + }) + }) + }) + }); + + context('index.js', () => { + it('works', () => cy.visit("/")) + }); + + context('join.js', () => { + it('works', () => cy.visit("/join")) + }); + + context('login.js', () => { + it('works', () => cy.visit("/login")) + }); + + context('new.js', () => { + it('works', () => cy.visit("/new")) + context('if user is not logged in', () => { + it('redirects to /index.js', () => { + cy.visit('/new'); + cy.location().should(loc => { + expect(loc.pathname).to.eq('/'); + }) + }) + }) + }); + + context('s/[id].js', () => { + it('works', () => cy.visit("/s/random")); + context('if story does not exist', () => { + it('redirects to /index.js', () => { + cy.visit('/s/random'); + cy.location().should(loc => { + expect(loc.pathname).to.eq('/'); + }) + }) + }) + }); + + context('s/[id]/edit.js', () => { + it('works', () => cy.visit("/s/random/edit")); + context('if story does not exist', () => { + it('redirects to /index.js', () => { + cy.visit('/s/random/edit'); + cy.location().should(loc => { + expect(loc.pathname).to.eq('/'); + }) + }) + }) + }); + + context('stories.js', () => { + it('works', () => cy.visit("/stories")) + context('if user is not logged in', () => { + it('redirects to /index.js', () => { + cy.visit('/stories'); + cy.location().should(loc => { + expect(loc.pathname).to.eq('/'); + }) + }) + }) + }); + + context('theme.js', () => { + it('works', () => cy.visit("/theme")) + }); +}) diff --git a/fb/src/pages/new.js b/fb/src/pages/new.js index 7dcfca5..1e8d29f 100644 --- a/fb/src/pages/new.js +++ b/fb/src/pages/new.js @@ -15,9 +15,9 @@ const StoryNewPage = () => { auth = useAuth(), router = useRouter(), { id } = router.query, autosave = useAutosave({ query: () => Stories.doc(id).set(state.story) }); - useEffect(() => auth.isReady && + useEffect(() => auth.isReady && (auth.isLoggedIn ? Stories.add({ ...state.story, profileId: auth.uid }).then(doc => router.replace(storyEditPath(doc), null, { shallow: true })) && - dispatch(state => ({ type: "STORY_LOAD", value: { ...state.story, profileId: auth.uid } })) + dispatch(state => ({ type: "STORY_LOAD", value: { ...state.story, profileId: auth.uid } })) : router.replace("/")) , [auth.isReady]); return (