From 9788c265fecd2f0241df8fdef050ec630df592dd Mon Sep 17 00:00:00 2001 From: AlfonsoGhislieri Date: Wed, 8 Mar 2023 11:21:42 +0000 Subject: [PATCH 1/7] fix: move initialization boolean inside component --- .../Howto/Content/Howto/HowtoDescription/HowtoDescription.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/Howto/Content/Howto/HowtoDescription/HowtoDescription.tsx b/src/pages/Howto/Content/Howto/HowtoDescription/HowtoDescription.tsx index 364bfb762f..2e72c01aed 100644 --- a/src/pages/Howto/Content/Howto/HowtoDescription/HowtoDescription.tsx +++ b/src/pages/Howto/Content/Howto/HowtoDescription/HowtoDescription.tsx @@ -53,14 +53,13 @@ interface IProps { onUsefulClick: () => void } -let didInit = false - const HowtoDescription = ({ howto, loggedInUser, ...props }: IProps) => { const [fileDownloadCount, setFileDownloadCount] = useState( howto.total_downloads, ) const [viewCount, setViewCount] = useState() const { stores } = useCommonStores() + let didInit = false const incrementDownloadCount = async () => { const updatedDownloadCount = await stores.howtoStore.incrementDownloadCount( @@ -109,6 +108,7 @@ const HowtoDescription = ({ howto, loggedInUser, ...props }: IProps) => { } useEffect(() => { + console.log(didInit) if (!didInit) { didInit = true incrementViewCount() From c2aaf606d6ccc88a4d8f77e87536c627fbfce4d1 Mon Sep 17 00:00:00 2001 From: AlfonsoGhislieri Date: Wed, 8 Mar 2023 11:24:01 +0000 Subject: [PATCH 2/7] fix: moved boolean initialization inside reasearch description --- src/pages/Research/Content/ResearchDescription.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/Research/Content/ResearchDescription.tsx b/src/pages/Research/Content/ResearchDescription.tsx index 00d90047f0..a551c58eef 100644 --- a/src/pages/Research/Content/ResearchDescription.tsx +++ b/src/pages/Research/Content/ResearchDescription.tsx @@ -33,8 +33,6 @@ interface IProps { onUsefulClick: () => void } -let didInit = false - const ResearchDescription = ({ research, isEditable, ...props }: IProps) => { const dateLastUpdateText = (research: IResearch.ItemDB): string => { const lastModifiedDate = format(new Date(research._modified), 'DD-MM-YYYY') @@ -45,6 +43,8 @@ const ResearchDescription = ({ research, isEditable, ...props }: IProps) => { return '' } } + let didInit = false + const store = useResearchStore() const [viewCount, setViewCount] = useState() From 35fd3ddf16b8b92a73da62744f9ccb7baed7e556 Mon Sep 17 00:00:00 2001 From: AlfonsoGhislieri Date: Wed, 8 Mar 2023 11:26:06 +0000 Subject: [PATCH 3/7] chore: removed console log --- .../Howto/Content/Howto/HowtoDescription/HowtoDescription.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/Howto/Content/Howto/HowtoDescription/HowtoDescription.tsx b/src/pages/Howto/Content/Howto/HowtoDescription/HowtoDescription.tsx index 2e72c01aed..d77a03f807 100644 --- a/src/pages/Howto/Content/Howto/HowtoDescription/HowtoDescription.tsx +++ b/src/pages/Howto/Content/Howto/HowtoDescription/HowtoDescription.tsx @@ -108,7 +108,6 @@ const HowtoDescription = ({ howto, loggedInUser, ...props }: IProps) => { } useEffect(() => { - console.log(didInit) if (!didInit) { didInit = true incrementViewCount() From 5438eab60c076fcadd9ecfa6c2e444415bfe8271 Mon Sep 17 00:00:00 2001 From: AlfonsoGhislieri Date: Wed, 8 Mar 2023 11:26:47 +0000 Subject: [PATCH 4/7] chore: removed unecessary spacing --- .../Howto/Content/Howto/HowtoDescription/HowtoDescription.tsx | 2 +- src/pages/Research/Content/ResearchDescription.tsx | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/pages/Howto/Content/Howto/HowtoDescription/HowtoDescription.tsx b/src/pages/Howto/Content/Howto/HowtoDescription/HowtoDescription.tsx index d77a03f807..c7347ac917 100644 --- a/src/pages/Howto/Content/Howto/HowtoDescription/HowtoDescription.tsx +++ b/src/pages/Howto/Content/Howto/HowtoDescription/HowtoDescription.tsx @@ -57,9 +57,9 @@ const HowtoDescription = ({ howto, loggedInUser, ...props }: IProps) => { const [fileDownloadCount, setFileDownloadCount] = useState( howto.total_downloads, ) + let didInit = false const [viewCount, setViewCount] = useState() const { stores } = useCommonStores() - let didInit = false const incrementDownloadCount = async () => { const updatedDownloadCount = await stores.howtoStore.incrementDownloadCount( diff --git a/src/pages/Research/Content/ResearchDescription.tsx b/src/pages/Research/Content/ResearchDescription.tsx index a551c58eef..d6c160d1a7 100644 --- a/src/pages/Research/Content/ResearchDescription.tsx +++ b/src/pages/Research/Content/ResearchDescription.tsx @@ -44,9 +44,7 @@ const ResearchDescription = ({ research, isEditable, ...props }: IProps) => { } } let didInit = false - const store = useResearchStore() - const [viewCount, setViewCount] = useState() const incrementViewCount = async () => { From e8f1b687f40cb15624dc1d53e1a1d450d509e228 Mon Sep 17 00:00:00 2001 From: AlfonsoGhislieri Date: Sun, 19 Mar 2023 13:08:27 +0000 Subject: [PATCH 5/7] chore: added cypress end to end testing for views --- .../src/ViewsCounter/ViewsCounter.tsx | 1 + .../src/integration/howto/read.spec.ts | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/packages/components/src/ViewsCounter/ViewsCounter.tsx b/packages/components/src/ViewsCounter/ViewsCounter.tsx index 6dc2b5e083..17f3c05f87 100644 --- a/packages/components/src/ViewsCounter/ViewsCounter.tsx +++ b/packages/components/src/ViewsCounter/ViewsCounter.tsx @@ -7,6 +7,7 @@ export interface IProps { export const ViewsCounter = (props: IProps) => ( { cy.get(`[data-cy="comments-form"]`).should('not.exist') }) + + it('[Views only visible for beta-testers]', () => { + cy.visit(specificHowtoUrl) + cy.step(`ViewsCounter should be visible`) + cy.get('[data-cy="ViewsCounter"]').should('not.exist') + }) }) describe('[By Authenticated]', () => { @@ -200,6 +206,30 @@ describe('[How To]', () => { }) }) + describe('[By Beta-Tester]', () => { + it('[Views show on multiple howtos]', () => { + cy.login('demo_beta_tester@example.com', 'demo_beta_tester') + + cy.step('Views show on first howto') + cy.visit(specificHowtoUrl) + cy.get('[data-cy="ViewsCounter"]').should('exist') + + cy.step('Go back') + cy.get('[data-cy="go-back"]:eq(0)').as('topBackButton').click() + + cy.step('Views show on second howto') + cy.visit('/how-to/make-glass-like-beams') + cy.get('[data-cy="ViewsCounter"]').should('exist') + + cy.step('Go back') + cy.get('[data-cy="go-back"]:eq(0)').as('topBackButton').click() + + cy.step('Views show on third howto') + cy.visit('/how-to/set-up-devsite-to-help-coding') + cy.get('[data-cy="ViewsCounter"]').should('exist') + }) + }) + it('[By Owner]', () => { cy.step('Edit button is available to the owner') cy.visit(specificHowtoUrl) From de2334e7e3c08af5837939be35ae8b23fd8ee6ff Mon Sep 17 00:00:00 2001 From: AlfonsoGhislieri Date: Mon, 20 Mar 2023 17:48:10 +0000 Subject: [PATCH 6/7] chore: added tests for research viewcounter --- .../src/integration/howto/read.spec.ts | 9 +-- .../src/integration/research/read.spec.ts | 68 ++++++++++++++----- shared/mocks/data/research.ts | 15 ++++ 3 files changed, 67 insertions(+), 25 deletions(-) diff --git a/packages/cypress/src/integration/howto/read.spec.ts b/packages/cypress/src/integration/howto/read.spec.ts index 98274e84a9..9d574c197d 100644 --- a/packages/cypress/src/integration/howto/read.spec.ts +++ b/packages/cypress/src/integration/howto/read.spec.ts @@ -161,7 +161,7 @@ describe('[How To]', () => { it('[Views only visible for beta-testers]', () => { cy.visit(specificHowtoUrl) - cy.step(`ViewsCounter should be visible`) + cy.step(`ViewsCounter should not be visible`) cy.get('[data-cy="ViewsCounter"]').should('not.exist') }) }) @@ -220,13 +220,6 @@ describe('[How To]', () => { cy.step('Views show on second howto') cy.visit('/how-to/make-glass-like-beams') cy.get('[data-cy="ViewsCounter"]').should('exist') - - cy.step('Go back') - cy.get('[data-cy="go-back"]:eq(0)').as('topBackButton').click() - - cy.step('Views show on third howto') - cy.visit('/how-to/set-up-devsite-to-help-coding') - cy.get('[data-cy="ViewsCounter"]').should('exist') }) }) diff --git a/packages/cypress/src/integration/research/read.spec.ts b/packages/cypress/src/integration/research/read.spec.ts index f4eb3bd140..3026cf9a0d 100644 --- a/packages/cypress/src/integration/research/read.spec.ts +++ b/packages/cypress/src/integration/research/read.spec.ts @@ -1,9 +1,8 @@ describe('[Research]', () => { const SKIP_TIMEOUT = { timeout: 300 } - const totalResearchCount = 1 + const totalResearchCount = 2 describe('[List research articles]', () => { - const researchArticleUrl = '/research/qwerty' beforeEach(() => { cy.visit('/research') }) @@ -14,24 +13,59 @@ describe('[Research]', () => { cy.get('[data-cy="ResearchListItem"]') .its('length') .should('be.eq', totalResearchCount) + }) + }) + + describe('[Read a research article]', () => { + const researchArticleUrl = '/research/qwerty' + const researchArticleUrl2 = 'A%20test%20research' + beforeEach(() => { + cy.visit('/research') + }) - cy.step('Research cards has basic info') - cy.get( - `[data-cy="ResearchListItem"] a[href="${researchArticleUrl}"]`, - ).within(() => { - cy.contains('qwerty').should('be.exist') - cy.contains('event_reader').should('be.exist') - cy.get('[data-cy="ItemUpdateText"]').contains('1').should('be.exist') + describe('[By Everyone]', () => { + it('[See all info]', () => { + cy.step('Research cards has basic info') + cy.get( + `[data-cy="ResearchListItem"] a[href="${researchArticleUrl}"]`, + ).within(() => { + cy.contains('qwerty').should('be.exist') + cy.contains('event_reader').should('be.exist') + cy.get('[data-cy="ItemUpdateText"]').contains('1').should('be.exist') + }) + + cy.step( + `Open Research details when click on a Research ${researchArticleUrl}`, + ) + cy.get( + `[data-cy="ResearchListItem"] a[href="${researchArticleUrl}"]`, + SKIP_TIMEOUT, + ).click() + cy.url().should('include', researchArticleUrl) + }) + + it('[Views only visible for beta-testers]', () => { + cy.step(`ViewsCounter should not be visible`) + cy.visit(researchArticleUrl) + cy.get('[data-cy="ViewsCounter"]').should('not.exist') }) + }) - cy.step( - `Open Research details when click on a Research ${researchArticleUrl}`, - ) - cy.get( - `[data-cy="ResearchListItem"] a[href="${researchArticleUrl}"]`, - SKIP_TIMEOUT, - ).click() - cy.url().should('include', researchArticleUrl) + describe('[Beta-tester]', () => { + it('[Views show on multiple research articles]', () => { + cy.login('demo_beta_tester@example.com', 'demo_beta_tester') + + cy.step('Views show on first research article') + cy.visit(researchArticleUrl) + cy.get('[data-cy="ViewsCounter"]').should('exist') + + cy.step('Go back') + cy.get('[data-cy="go-back"]:eq(0)').as('topBackButton').click() + + cy.step('Views show on second research article') + cy.visit('/research/A%20test%20research') + cy.get('[data-cy="ViewsCounter"]').should('exist') + }) }) }) }) diff --git a/shared/mocks/data/research.ts b/shared/mocks/data/research.ts index 3c53d5de9d..31d16eabf0 100644 --- a/shared/mocks/data/research.ts +++ b/shared/mocks/data/research.ts @@ -388,4 +388,19 @@ export const research = { }, ], }, + '0up6oJCTT3M9bDYx34Et': { + _created: '2023-02-27T22:08:25.999Z', + _createdBy: 'test user', + _deleted: false, + _id: '0up6oJCTT3M9bDYx34Et', + _modified: '2023-03-01T19:12:11.271Z', + creatorCountry: 'it', + description: 'A test!', + moderation: 'accepted', + slug: 'A test research', + tags: { + h1wCs0o9j60lkw3AYPB1: true, + }, + title: 'A test research', + }, } From d1d8ba4fa7eb3cdce421ae3f26bf4be8b0dcefe6 Mon Sep 17 00:00:00 2001 From: AlfonsoGhislieri Date: Tue, 21 Mar 2023 09:04:52 +0000 Subject: [PATCH 7/7] chore: removed unused variable --- packages/cypress/src/integration/research/read.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/cypress/src/integration/research/read.spec.ts b/packages/cypress/src/integration/research/read.spec.ts index 3026cf9a0d..1de2a8d494 100644 --- a/packages/cypress/src/integration/research/read.spec.ts +++ b/packages/cypress/src/integration/research/read.spec.ts @@ -18,7 +18,6 @@ describe('[Research]', () => { describe('[Read a research article]', () => { const researchArticleUrl = '/research/qwerty' - const researchArticleUrl2 = 'A%20test%20research' beforeEach(() => { cy.visit('/research') })