Skip to content

Commit

Permalink
Release 1.1.6
Browse files Browse the repository at this point in the history
Changelog : 
- [Hotfix] fix migration errors #350
- [Hotfix] disable Sentry performance monitoring #349
- [Aide à la saisie] set float as answer value and set total km instead of "real" km to be consistent with the model (NGC-389) #348
  • Loading branch information
florianpanchout authored Jan 18, 2024
1 parent aaf04ae commit 16e7616
Show file tree
Hide file tree
Showing 12 changed files with 184 additions and 90 deletions.
1 change: 1 addition & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ jobs:
spec: cypress/e2e/integration/**/*.cy.js
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
SERVER_URL: ${{ secrets.SERVER_URL }}
GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
7 changes: 7 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { addMatchImageSnapshotPlugin } from '@simonsmith/cypress-image-snapshot/plugin'
import { defineConfig } from 'cypress'
import dotenv from 'dotenv'

dotenv.config()

export default defineConfig({
projectId: 'bkkrae',
Expand All @@ -11,6 +14,10 @@ export default defineConfig({
localisation_param: 'FR',
language_param: 'fr',
testLangURL: process.env.CYPRESS_testLangURL ?? 'fr',
server_url: process.env.CYPRESS_baseUrl
? 'nosgestesclimat.osc-fr1.scalingo.io'
: 'localhost:3001',
...process.env,
},
e2e: {
baseUrl: process.env.CYPRESS_baseUrl ?? 'http://localhost:3000',
Expand Down
137 changes: 87 additions & 50 deletions cypress/e2e/integration/pages/groupes.cy.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,106 @@
import {
clickAmisLink,
clickSkipTutorialButton,
} from '../../../helpers/elements/buttons'
import { clickSkipTutorialButton } from '../../../helpers/elements/buttons'
import { recursivelyFillSimulation } from '../../../helpers/simulation/recursivelyFillSimulation'

describe(
'The Group creation page /amis/creer',
{ testIsolation: false },
() => {
it('allows to create a new group and displays it afterwards', () => {
cy.visit('/amis')
describe('The Group creation page /amis/creer', () => {
let ownerUserId = ''

cy.clearLocalStorage()
it('allows to create a new group and displays it afterwards', () => {
cy.visit('/amis')

// Check that we can create our first group
cy.get('[data-cypress-id="button-create-first-group"]').click()
cy.get('input[data-cypress-id="group-input-owner-name"]').type(
'Jean-Marc'
)
cy.get('[data-cypress-id="button-create-group"]').click()
cy.clearLocalStorage()

// Fill simulation
clickSkipTutorialButton()
recursivelyFillSimulation(null, 'group')
// Check that we can create our first group
cy.get('[data-cypress-id="button-create-first-group"]').click()
cy.get('input[data-cypress-id="group-input-owner-name"]').type('Jean-Marc')
cy.get('[data-cypress-id="button-create-group"]').click()

cy.get('[data-cypress-id="group-name"]')
cy.wait(2000)

// Check that we can create a second group
clickAmisLink()
cy.get('[data-cypress-id="button-create-other-group"]').click()
// Fill simulation
clickSkipTutorialButton()

cy.get('input[data-cypress-id="group-input-owner-name"]').clear()
cy.wait(2000)

cy.get('input[data-cypress-id="group-input-owner-name"]').type(
'Jean-Marc groupe 2'
)
cy.get('[data-cypress-id="button-create-group"]').click()
cy.get('[data-cypress-id="group-name"]')
recursivelyFillSimulation(null, 'group')

// And that we can update its name
cy.get('[data-cypress-id="group-name-edit-button"]').click()
cy.wait(4000)

const newName = 'Les amis de Jean-Marc'
cy.get('[data-cypress-id="group-name"]')

cy.get('input[data-cypress-id="group-edit-input-name"]').clear()
cy.get('input[data-cypress-id="group-edit-input-name"]').type(newName)
cy.get('[data-cypress-id="button-inline-input"]').click()
cy.get('[data-cypress-id="group-name"]').contains(newName)
// And that we can delete it
cy.get('[data-cypress-id="button-delete-group"]').click()
cy.get('[data-cypress-id="button-confirm-delete-group"]').click()

// Check that we can create a second group
cy.wait(2000)

cy.get('[data-cypress-id="button-create-first-group"]').click()

cy.get('input[data-cypress-id="group-input-owner-name"]').clear()

cy.get('input[data-cypress-id="group-input-owner-name"]').type(
'Jean-Marc groupe 2'
)
cy.get('[data-cypress-id="button-create-group"]').click()
cy.get('[data-cypress-id="group-name"]')

// And that we can update its name
cy.get('[data-cypress-id="group-name-edit-button"]').click()

const newName = 'Les amis de Jean-Marc'

cy.get('input[data-cypress-id="group-edit-input-name"]').clear()
cy.get('input[data-cypress-id="group-edit-input-name"]').type(newName)
cy.get('[data-cypress-id="button-inline-input"]').click()
cy.get('[data-cypress-id="group-name"]').contains(newName)

// Save the owner user id in order to be able to delete the group later on
cy.getAllLocalStorage().then((result) => {
ownerUserId =
result[Cypress.config('baseUrl')]?.['nosgestesclimat::v3'] &&
JSON.parse(result[Cypress.config('baseUrl')]?.['nosgestesclimat::v3'])
?.user?.id
})

it('allows to join a group with the invitation link and display ', () => {
cy.clearLocalStorage()
cy.reload()
cy.clearLocalStorage()
cy.reload()

cy.wait(3000)

cy.get('[data-cypress-id="member-name"]').type('Jean-Claude')
cy.get('[data-cypress-id="button-join-group"]').click()

clickSkipTutorialButton()
recursivelyFillSimulation(null, 'group')

cy.wait(3000)

cy.get('[data-cypress-id="group-name"]')

// Check that the main sections are displayed
cy.get('[data-cypress-id="points-fort-faibles-title"]')
cy.get('[data-cypress-id="votre-empreinte-title"]')

let currentUrl = ''

cy.get('[data-cypress-id="member-name"]').type('Jean-Claude')
cy.get('[data-cypress-id="button-join-group"]').click()
// Delete the group via the API
cy.url().then((url) => {
currentUrl = url

clickSkipTutorialButton()
recursivelyFillSimulation(null, 'group')
const groupId = currentUrl?.split('groupId=')?.[1]

cy.get('[data-cypress-id="group-name"]')
const SERVER_URL = Cypress.env('server_url')

// Check that the main sections are displayed
cy.get('[data-cypress-id="points-fort-faibles-title"]')
cy.get('[data-cypress-id="votre-empreinte-title"]')
cy.request(
'POST',
`http${
SERVER_URL === 'localhost:3001' ? '' : 's'
}://${SERVER_URL}/group/delete`,
{
groupId,
userId: ownerUserId,
}
).as('response')
})
}
)
})
})
2 changes: 2 additions & 0 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const { addMatchImageSnapshotPlugin } = require('cypress-image-snapshot/plugin')

module.exports = (on, config) => {
config.env = process.env

addMatchImageSnapshotPlugin(on, config)
}
5 changes: 3 additions & 2 deletions sentry.client.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import * as Sentry from '@sentry/nextjs'
Sentry.init({
dsn: 'https://[email protected]/118',

// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 0.05,
enableTracing: false,

// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: false,

sampleRate: 0.1,

replaysOnErrorSampleRate: 1.0,

// This sets the sample rate to be 10%. You may want this to be 100% while
Expand Down
5 changes: 3 additions & 2 deletions sentry.edge.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import * as Sentry from '@sentry/nextjs'
Sentry.init({
dsn: 'https://[email protected]/118',

// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 0.05,
enableTracing: false,

// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: false,

sampleRate: 0.1,
})
5 changes: 3 additions & 2 deletions sentry.server.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import * as Sentry from '@sentry/nextjs'
Sentry.init({
dsn: 'https://[email protected]/118',

// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 0.05,
enableTracing: false,

// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: false,

sampleRate: 0.1,

// Disable sentry for development based on local data
enabled: !process.env.NEXT_PUBLIC_LOCAL_DATA,
})
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,22 @@ export default function OwnerAdminSection({ group }: Props) {
Annuler
</Button>

<Button onClick={handleDelete} size="sm" color="primary">
<Button
onClick={handleDelete}
size="sm"
color="primary"
data-cypress-id="button-confirm-delete-group">
Supprimer
</Button>
</div>
</Card>
)}

{!isConfirming && !isSuccess && (
<Button color="link" onClick={() => setIsConfirming(true)}>
<Button
color="link"
onClick={() => setIsConfirming(true)}
data-cypress-id="button-delete-group">
Supprimer le groupe
</Button>
)}
Expand Down
54 changes: 27 additions & 27 deletions src/components/questions/voiture/JourneysInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ const periods: Record<string, number> = {
year: 1,
}

function roundFloat(value: number, precision: number = 10): number {
return Math.round(value * precision) / precision
}

export default function JourneysInput({ question }: Props) {
const { setValue } = useRule(question)

Expand All @@ -39,24 +43,24 @@ export default function JourneysInput({ question }: Props) {
}
}, [journeys, isInitialized, question])

const total = useMemo(
() =>
journeys.reduce(
(accumulator, currentValue) =>
accumulator +
currentValue.distance *
currentValue.reccurrence *
periods[currentValue.period],
0
),
[journeys]
)
const total = useMemo(() => {
const rawTotal = journeys.reduce(
(accumulator, currentValue) =>
accumulator +
currentValue.distance *
currentValue.reccurrence *
periods[currentValue.period],
0
)
const roundedTotal = roundFloat(rawTotal)
return roundedTotal
}, [journeys])

const averagePassengers = useMemo(() => {
if (!total) {
return 1
} else {
return (
const rawAveragePassengers =
journeys.reduce(
(accumulator, currentValue) =>
accumulator +
Expand All @@ -66,29 +70,25 @@ export default function JourneysInput({ question }: Props) {
periods[currentValue.period],
0
) / total
)
const roundedAveragePassengers = roundFloat(rawAveragePassengers)
return roundedAveragePassengers
}
}, [journeys, total])

const totalForOnePassenger = useMemo(
() => (journeys.length ? total / averagePassengers : 0),
() => (journeys.length ? roundFloat(total / averagePassengers) : 0),
[journeys, total, averagePassengers]
)
const prevTotalForOnePassenger = useRef(totalForOnePassenger)

const prevTotal = useRef(total)

useEffect(() => {
if (prevTotalForOnePassenger.current !== totalForOnePassenger) {
setValue(totalForOnePassenger.toFixed(1), question)
setNumPassengers(averagePassengers.toFixed(1))
if (prevTotal.current !== total) {
setValue(total, question)
setNumPassengers(averagePassengers)
}
prevTotalForOnePassenger.current = totalForOnePassenger
}, [
totalForOnePassenger,
averagePassengers,
setValue,
setNumPassengers,
question,
])
prevTotal.current = total
}, [total, averagePassengers, setValue, setNumPassengers, question])

return (
<>
Expand Down
28 changes: 27 additions & 1 deletion src/constants/dottedNamesMigration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,36 @@ export const dottedNamesMigration: migrationType = {
keysToMigrate: {
'logement . chauffage . bois . type . bûche . consommation':
'logement . chauffage . bois . type . bûches . consommation',
'divers . loisirs . culture . musées et monuments . fréquence': '',
'logement . vacances . maison secondaire . présent':
'logement . vacances . résidence secondaire . présent',
'divers . ameublement . meubles . salon de jardin résine ou métal . nombre':
'',
'divers . ameublement . meubles . salon de jardin bois . nombre': '',
'divers . électroménager . appareils . tondeuse électrique . nombre': '',
'logement . éco-construit': '',
'transport . ferry . présent': 'transport . ferry . usager',
'divers . loisirs . culture . édition . fréquence': '',
'divers . animaux domestiques . empreinte . choix utilisateur': '',
'transport . voiture . propriétaire': '',
'transport . voiture . âge': '',
'logement . gaz . biogaz . part': 'logement . chauffage . biogaz . part',
},
valuesToMigrate: {
'logement . chauffage . bois . type': { "'bûche'": 'bûches' },
'transport . boulot . commun . type': { "'vélo'": '' },
'alimentation . petit déjeuner . type': {"'français'": 'continental'}
'alimentation . petit déjeuner . type': { "'français'": 'continental' },
'alimentation . boisson . eau en bouteille . consommateur': {
"'négatif'": 'non',
"'affirmatif'": 'oui',
},
'transport . deux roues . usager': {
"'négatif'": 'non',
"'affirmatif'": 'oui',
},
'transport . ferry . usager': {
"'négatif'": 'non',
"'affirmatif'": 'oui',
},
},
}
3 changes: 2 additions & 1 deletion src/publicodes-state/helpers/safeGetSituation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ export const safeGetSituation = ({
)
console.warn(error)
captureException(error)
return true
return false
}
return false
}
)

Expand Down
Loading

0 comments on commit 16e7616

Please sign in to comment.