From 5a43542820b0a88df4b864eb0749f28e66c3789f Mon Sep 17 00:00:00 2001
From: gcarron <gcarron@grandlyon.com>
Date: Fri, 4 Dec 2020 17:19:46 +0100
Subject: [PATCH] Fix some card test + add tests todo

---
 src/components/Season/SeasonCard.spec.tsx         | 13 -------------
 src/components/Season/SeasonCardUnlocked.spec.tsx | 15 +++++++++++----
 src/components/Season/SeasonView.spec.tsx         |  2 ++
 src/components/Season/SeasonView.tsx              |  2 +-
 .../Season/__snapshots__/SeasonCard.spec.tsx.snap |  2 +-
 test/__mocks__/seasonEntity.mock.ts               |  2 +-
 test/__mocks__/userSeasonData.mock.ts             | 12 ++++++------
 7 files changed, 22 insertions(+), 26 deletions(-)

diff --git a/src/components/Season/SeasonCard.spec.tsx b/src/components/Season/SeasonCard.spec.tsx
index 8496d1de2..8c44452c8 100644
--- a/src/components/Season/SeasonCard.spec.tsx
+++ b/src/components/Season/SeasonCard.spec.tsx
@@ -5,10 +5,6 @@ import SeasonCardLocked from './SeasonCardLocked'
 import SeasonCardUnlocked from './SeasonCardUnlocked'
 import SeasonCardOnGoing from './SeasonCardOnGoing'
 import { userSeasonData } from '../../../test/__mocks__/userSeasonData.mock'
-import StyledButtonValid from 'components/CommonKit/Button/StyledButtonValid'
-import MockTheme from './MockTheme'
-import * as Style from '@material-ui/core/styles'
-import { createMuiTheme } from '@material-ui/core/styles'
 
 jest.mock('cozy-ui/transpiled/react/I18n', () => {
   return {
@@ -21,18 +17,9 @@ jest.mock('cozy-ui/transpiled/react/I18n', () => {
 })
 
 jest.mock('@material-ui/core/styles/createMuiTheme', () => jest.fn())
-// const mockTheme = createMuiTheme({})
-// jest.spyOn(Style, 'createMuiTheme').mockReturnValue(mockTheme)
-// const mockStyle = new CSSStyleDeclaration().setProperty('main', '#fff')
 
-// jest.spyOn(window, 'getComputedStyle').mockReturnValue(mockStyle)
-//TODO fis MUI theme error
 describe('SeasonCard component', () => {
   it('should be rendered correctly', () => {
-    // const mockStyle = new CSSStyleDeclaration()
-    // mockStyle.setProperty('color', '#fff')
-    // console.log('prop', mockStyle.getPropertyValue('color'))
-    // jest.spyOn(window, 'getComputedStyle').mockReturnValue(mockStyle)
     const component = shallow(
       <SeasonCard
         userSeason={userSeasonData[1]}
diff --git a/src/components/Season/SeasonCardUnlocked.spec.tsx b/src/components/Season/SeasonCardUnlocked.spec.tsx
index b46ae8b0c..dfa739de7 100644
--- a/src/components/Season/SeasonCardUnlocked.spec.tsx
+++ b/src/components/Season/SeasonCardUnlocked.spec.tsx
@@ -3,6 +3,7 @@ import { shallow } from 'enzyme'
 import SeasonCardUnlocked from './SeasonCardUnlocked'
 import { userSeasonData } from '../../../test/__mocks__/userSeasonData.mock'
 import { globalStateData } from '../../../test/__mocks__/globalStateData.mock'
+import StyledButtonValid from 'components/CommonKit/Button/StyledButtonValid'
 
 jest.mock('cozy-ui/transpiled/react/I18n', () => {
   return {
@@ -13,13 +14,16 @@ jest.mock('cozy-ui/transpiled/react/I18n', () => {
     }),
   }
 })
+jest.mock('@material-ui/core/styles/createMuiTheme', () => jest.fn())
+const mocklaunchSeason = jest.fn()
+
 const mockUseSelector = globalStateData
 jest.mock('react-redux', () => ({
   useSelector: jest.fn().mockResolvedValue(mockUseSelector),
   useDispatch: () => jest.fn(),
 }))
 
-//TODO fis MUI theme error
+//TODO fix click test
 describe('SeasonCardUnlocked component', () => {
   it('should be rendered correctly', () => {
     const component = shallow(
@@ -29,12 +33,15 @@ describe('SeasonCardUnlocked component', () => {
   })
 
   it('should launch the season', () => {
-    const mocklaunchSeason = jest.fn()
     const wrapper = shallow(
       <SeasonCardUnlocked userSeason={userSeasonData[0]} />
     )
-    wrapper.find('.launchButton').simulate('click')
-    expect(mocklaunchSeason).toBeCalledTimes(1)
+    wrapper
+      .find(StyledButtonValid)
+      .first()
+      .simulate('click')
+    console.log('button', wrapper.find(StyledButtonValid).first())
+    expect(mocklaunchSeason).toHaveBeenCalled()
   })
   // it('should open the fluid modal', () => {})
 })
diff --git a/src/components/Season/SeasonView.spec.tsx b/src/components/Season/SeasonView.spec.tsx
index fa6fa808e..02a0159ef 100644
--- a/src/components/Season/SeasonView.spec.tsx
+++ b/src/components/Season/SeasonView.spec.tsx
@@ -8,12 +8,14 @@ const mockaHandleTouchStart = jest.fn()
 // const mockaHandleTouchEnd = jest.fn()
 
 const mockUseSelector = seasonStateDataFull
+jest.mock('@material-ui/core/styles/createMuiTheme', () => jest.fn())
 
 jest.mock('react-redux', () => ({
   useSelector: jest.fn().mockResolvedValue(mockUseSelector),
   useDispatch: () => jest.fn(),
 }))
 
+//TODO fix error userseasonlist undefined
 describe('SeasonView component', () => {
   it('should be rendered correctly', () => {
     const component = shallow(<SeasonView />).getElement()
diff --git a/src/components/Season/SeasonView.tsx b/src/components/Season/SeasonView.tsx
index 18274eb39..560b50d61 100644
--- a/src/components/Season/SeasonView.tsx
+++ b/src/components/Season/SeasonView.tsx
@@ -92,7 +92,7 @@ const SeasonView: React.FC = () => {
       setTouchEnd(e.targetTouches[0].clientX)
     if (e.nativeEvent instanceof MouseEvent) setTouchEnd(e.clientX)
   }
-  console.log('userseasonlist', userSeasonList)
+
   return (
     <>
       <CozyBar titleKey={'COMMON.APP_CHALLENGE_TITLE'} />
diff --git a/src/components/Season/__snapshots__/SeasonCard.spec.tsx.snap b/src/components/Season/__snapshots__/SeasonCard.spec.tsx.snap
index c5904934a..ff491cc77 100644
--- a/src/components/Season/__snapshots__/SeasonCard.spec.tsx.snap
+++ b/src/components/Season/__snapshots__/SeasonCard.spec.tsx.snap
@@ -32,7 +32,7 @@ exports[`SeasonCard component should be rendered correctly 1`] = `
         "startDate": null,
         "state": 0,
         "success": 0,
-        "target": 40,
+        "target": 15,
         "title": "Tata",
       }
     }
diff --git a/test/__mocks__/seasonEntity.mock.ts b/test/__mocks__/seasonEntity.mock.ts
index e4bc32585..00abc464f 100644
--- a/test/__mocks__/seasonEntity.mock.ts
+++ b/test/__mocks__/seasonEntity.mock.ts
@@ -5,7 +5,7 @@ export const seasonEntityData: SeasonEntity = {
   id: 'SEASON0001',
   title: 'Nicolas Hublot',
   description: 'foobar',
-  target: 40,
+  target: 15,
   boss: bossEntity,
   quizType: 'cultureG',
 }
diff --git a/test/__mocks__/userSeasonData.mock.ts b/test/__mocks__/userSeasonData.mock.ts
index 78f017d67..f1bcd3478 100644
--- a/test/__mocks__/userSeasonData.mock.ts
+++ b/test/__mocks__/userSeasonData.mock.ts
@@ -8,7 +8,7 @@ export const userSeasonData: UserSeason[] = [
     title: 'Nicolas Hublot',
     description: 'foobar',
     state: UserSeasonState.UNLOCKED,
-    target: 40,
+    target: 15,
     progress: 0,
     boss: bossData,
     success: UserSeasonSuccess.ONGOING,
@@ -21,7 +21,7 @@ export const userSeasonData: UserSeason[] = [
     title: 'Tata',
     description: 'foobar',
     state: UserSeasonState.LOCKED,
-    target: 40,
+    target: 15,
     progress: 0,
     boss: bossData,
     success: UserSeasonSuccess.ONGOING,
@@ -34,7 +34,7 @@ export const userSeasonData: UserSeason[] = [
     title: 'Toto',
     description: 'foobar',
     state: UserSeasonState.ONGOING,
-    target: 40,
+    target: 15,
     progress: 0,
     boss: bossData,
     success: UserSeasonSuccess.ONGOING,
@@ -50,7 +50,7 @@ export const userSeasonDefault: UserSeason[] = [
     title: 'Nicolas Hublot',
     description: 'foobar',
     state: UserSeasonState.UNLOCKED,
-    target: 40,
+    target: 15,
     progress: 0,
     boss: bossDefault,
     success: UserSeasonSuccess.ONGOING,
@@ -63,7 +63,7 @@ export const userSeasonDefault: UserSeason[] = [
     title: 'titi',
     description: 'foobar',
     state: UserSeasonState.LOCKED,
-    target: 40,
+    target: 15,
     progress: 0,
     boss: bossDefault,
     success: UserSeasonSuccess.ONGOING,
@@ -76,7 +76,7 @@ export const userSeasonDefault: UserSeason[] = [
     title: 'tata',
     description: 'foobar',
     state: UserSeasonState.LOCKED,
-    target: 40,
+    target: 15,
     progress: 0,
     boss: bossDefault,
     success: UserSeasonSuccess.ONGOING,
-- 
GitLab