diff --git a/client/src/redux/create-store.js b/client/src/redux/create-store.js index b890f4bc8ec..7f35b8a1df2 100644 --- a/client/src/redux/create-store.js +++ b/client/src/redux/create-store.js @@ -30,16 +30,18 @@ const composeEnhancers = composeWithDevTools({ // options like actionSanitizer, stateSanitizer }); -export const createStore = () => { +export const createStore = (preloadedState = {}) => { let store; if (environment === 'production') { store = reduxCreateStore( rootReducer, + preloadedState, applyMiddleware(sagaMiddleware, epicMiddleware) ); } else { store = reduxCreateStore( rootReducer, + preloadedState, composeEnhancers(applyMiddleware(sagaMiddleware, epicMiddleware)) ); } diff --git a/client/src/templates/Challenges/components/completion-modal.test.tsx b/client/src/templates/Challenges/components/completion-modal.test.tsx index 7d151bd0588..3f17a48f380 100644 --- a/client/src/templates/Challenges/components/completion-modal.test.tsx +++ b/client/src/templates/Challenges/components/completion-modal.test.tsx @@ -1,6 +1,15 @@ +import React from 'react'; +import { render } from '../../../../utils/test-utils'; + import { getCompletedPercentage } from '../../../utils/get-completion-percentage'; +import { fireConfetti } from '../../../utils/fire-confetti'; +import { createStore } from '../../../redux/create-store'; +import CompletionModal from './completion-modal'; jest.mock('../../../analytics'); +jest.mock('../../../utils/fire-confetti'); +jest.mock('../../../components/ProgressBar'); +const mockFireConfetti = fireConfetti as jest.Mock; const completedChallengesIds = ['1', '3', '5'], currentBlockIds = ['1', '3', '5', '7'], @@ -8,6 +17,43 @@ const completedChallengesIds = ['1', '3', '5'], fakeCompletedChallengesIds = ['1', '3', '5', '7', '8']; describe('', () => { + describe('fireConfetti', () => { + beforeEach(() => { + mockFireConfetti.mockClear(); + }); + test('should fire if certification project has been completed', () => { + const store = createStore({ + challenge: { + modal: { completion: true }, + challengeMeta: { + // Build a Tribute Page's id: + id: 'bd7158d8c442eddfaeb5bd18' + } + } + }); + + render(, store); + + expect(mockFireConfetti).toHaveBeenCalledTimes(1); + }); + + test('should NOT fire if the challenge is not a project', () => { + const store = createStore({ + challenge: { + modal: { completion: true }, + challengeMeta: { + // id from learn-advanced-array-methods-by-building-a-statistics-calculator: + id: '6352e79d15aae30fac58f48e' + } + } + }); + + render(, store); + + expect(mockFireConfetti).toHaveBeenCalledTimes(0); + }); + }); + describe('getCompletedPercentage', () => { it('returns 25 if one out of four challenges are complete', () => { expect( diff --git a/cypress/e2e/default/learn/challenges/multifile-cert-project.ts b/cypress/e2e/default/learn/challenges/multifile-cert-project.ts index be6d41eddb0..e7f40a11a71 100644 --- a/cypress/e2e/default/learn/challenges/multifile-cert-project.ts +++ b/cypress/e2e/default/learn/challenges/multifile-cert-project.ts @@ -8,34 +8,6 @@ const editorElements = { closeFlash: '.close' }; -const portfolioChallenge = { - url: '/learn/2022/responsive-web-design/build-a-personal-portfolio-webpage-project/build-a-personal-portfolio-webpage' -}; - -const portfolioChallengeSolution = ` - - - - -
-
-

text

-

-
-

Projects

-

text

-

- -`; - describe('multifileCertProjects', function () { before(() => { cy.task('seed'); @@ -67,8 +39,6 @@ describe('multifileCertProjects', function () { // since rapid clicks will cause the save requests to be ignored, we have to // purge the db: cy.task('seed'); - // and the redux store: - cy.reload(); cy.get(editorElements.container).find(editorElements.editor).click(); cy.focused().clear().click().type(`${save2text}{ctrl+s}`); cy.get(editorElements.editor).contains(save2text); @@ -91,17 +61,4 @@ describe('multifileCertProjects', function () { .type(`{ctrl+s}`); cy.contains('Your code was not saved.'); }); - - it('Should show the confetti when a cert challenge is completed', () => { - cy.visit(portfolioChallenge.url); - cy.get('[data-cy=editor-container-indexhtml]') - .click() - .type(portfolioChallengeSolution) - .type('{ctrl}{enter}', { release: false, delay: 100 }); - cy.get('canvas').then(canvases => { - const currentCanvasCount = canvases.length; - cy.contains('Run the Tests (Ctrl + Enter)').click(); - cy.get('canvas').should('have.length', currentCanvasCount + 1); - }); - }); });