Skip to content

Commit

Permalink
Release 1.3.0
Browse files Browse the repository at this point in the history
Changelog :
- Réactive l'option de partage des données dans l'iframe (NGC-538) #391
- Fix: use the official v2 release of the model and use patched publicodes packages #385
  • Loading branch information
florianpanchout authored Mar 1, 2024
1 parent fa30c8d commit a0828fb
Show file tree
Hide file tree
Showing 51 changed files with 2,212 additions and 430 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ jobs:
id: waitForVercel
with:
token: ${{ secrets.GITHUB_TOKEN }}
max_timeout: 300
max_timeout: 600
check_interval: 30

cypress-run:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -58,7 +59,7 @@ jobs:
- name: Test - e2e [${{ env.MODE }}]
uses: cypress-io/github-action@v5.6.1
with:
build: yarn run e2e:generate:personas
build: yarn run e2e:generate
browser: chrome
parallel: true
record: true
Expand Down
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,15 @@ If you want to run the automatic localisation, which depends on a Netlify Edge f

### 🇬🇧 Tests

You can run e2e tests (Cypress) by firt starting a local server with `yarn run
serve`, then, run cypress tests with `yarn run test` (or `yarn run e2e` to open
the Cypress GUI) -- it will generate [personas spec
files](https://github.com/incubateur-ademe/nosgestesclimat-site-nextjs/wiki/Contributing#tests).
#### End-to-end tests

We use [Cypress](https://www.cypress.io/) for end-to-end tests.

To run the tests:

1. you need to start a local server with `yarn run dev`
2. you need to generate the personas spec files with `yarn run e2e:generate`
3. then run the tests with `yarn run e2e` to open the Cypress GUI.

## Réutilisations de ce code

Expand Down
2 changes: 0 additions & 2 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ export default defineConfig({
viewportWidth: 1920,
viewportHeight: 960,
env: {
// This is the URL of the local server that will be used for testing
personas_fr_url: 'https://data.nosgestesclimat.fr/personas-fr.json',
localisation_param: 'FR',
language_param: 'fr',
testLangURL: process.env.CYPRESS_testLangURL ?? 'fr',
Expand Down
11 changes: 7 additions & 4 deletions cypress/scripts/generateSpecsFromPersonas.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { writeFileSync } from 'fs'

const personas = await fetch(
`https://nosgestesclimat-api.osc-fr1.scalingo.io/latest/fr/personas`
).then((r) => r.json())
import personas from '@incubateur-ademe/nosgestesclimat/public/personas-fr.json' assert { type: 'json' }

/**
* @param {string} name
* @param {Record<string, string | number>} data
* @returns {string}
*/
const getFileContent = (name, data) => `
import { recursivelyFillSimulation } from '../../../helpers/simulation/recursivelyFillSimulation'
import { setupSimulation } from '../../../helpers/simulation/setupSimulation'
Expand All @@ -25,7 +28,7 @@ Object.entries(personas).map(([dottedName, data]) => {
const name = dottedName.split(' . ')[1]
writeFileSync(
`./cypress/e2e/integration/test-completion/persona-${name}.cy.js`,
getFileContent(name, data)
getFileContent(name, data.situation)
)
console.log(`[OK] persona-${name}.cy.js`)
})
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "nosgestesclimat-site-nextjs",
"license": "MIT",
"version": "1.2.1",
"version": "1.3.0",
"description": "The leading open source climate footprint calculator",
"repository": {
"type": "git",
Expand All @@ -12,12 +12,11 @@
},
"scripts": {
"dev": "next dev",
"dev:model": "NEXT_PUBLIC_LOCAL_DATA=nosgestesclimat next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"e2e": "cypress open --e2e",
"e2e:generate:personas": "node cypress/scripts/generateSpecsFromPersonas.mjs",
"e2e:generate": "node cypress/scripts/generateSpecsFromPersonas.mjs",
"ui:parse": "node scripts/i18n/generate-ui.js",
"ui:check": "yarn run ui:parse && node scripts/i18n/check-ui.js",
"ui:translate": "node scripts/i18n/translate-ui.js",
Expand All @@ -30,10 +29,11 @@
},
"dependencies": {
"@babel/runtime": "^7.23.1",
"@incubateur-ademe/nosgestesclimat": "^1.5.5",
"@incubateur-ademe/nosgestesclimat": "^2.0.0",
"@mdx-js/loader": "^3.0.0",
"@mdx-js/react": "^3.0.0",
"@next/mdx": "^14.0.2",
"@publicodes/react-ui": "^1.1.0",
"@sentry/nextjs": "^7.80.0",
"@sentry/react": "^7.80.0",
"@svgr/webpack": "8.1.0",
Expand All @@ -57,8 +57,7 @@
"next-i18n-router": "^4.1.1",
"postcss": "8.4.31",
"process": "^0.11.10",
"publicodes": "^1.0.0-beta.77",
"publicodes-react": "^1.0.0-beta.76",
"publicodes": "^1.1.0",
"puppeteer-core": "^21.5.1",
"qrcode.react": "^3.1.0",
"ramda": "^0.29.1",
Expand Down Expand Up @@ -97,7 +96,7 @@
],
"devDependencies": {
"@babel/eslint-parser": "^7.23.3",
"@incubateur-ademe/nosgestesclimat-scripts": "^0.2.2",
"@incubateur-ademe/nosgestesclimat-scripts": "^0.3.6",
"@simonsmith/cypress-image-snapshot": "^9.0.1",
"@svgr/cli": "^8.1.0",
"@types/cheerio": "^0.22.34",
Expand All @@ -112,6 +111,7 @@
"@types/webpack": "^5.28.5",
"@typescript-eslint/eslint-plugin": "^6.11.0",
"@typescript-eslint/parser": "^6.11.0",
"ansi-colors": "^4.1.3",
"autoprefixer": "^10.4.16",
"cli-progress": "^3.12.0",
"csv-loader": "^3.0.5",
Expand Down
12 changes: 12 additions & 0 deletions public/datashare/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
window.addEventListener('message', function (e) {
// Get the sent data

// There are lots of messages passing
// console.log("MONLOG", e);
const data = e.data

// we need to filter them
if (data.messageType && data.messageType === 'ngc-iframe-share') {
console.log('MON RESULTAT DE SIMULATION', data.data)
}
})
23 changes: 23 additions & 0 deletions public/demo-iframe-datashare.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Demo Iframe</title>
</head>
<body>
<header>
<h2>iframe datashare</h2>
<p>
Ci-dessous, nosgestesclimat.fr intégré comme un iframe avec data-share.
</p>
</header>
<main>
<script
id="nosgestesclimat"
src="/iframe.js"
data-share-data="true"></script>
</main>
<script src="datashare/index.js"></script>
</body>
</html>
13 changes: 5 additions & 8 deletions scripts/i18n/generate-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const ramda = require('ramda')
const child_process = require('child_process')
const utils = require('@incubateur-ademe/nosgestesclimat-scripts/utils')
const cli = require('@incubateur-ademe/nosgestesclimat-scripts/cli')
const c = require('ansi-colors')

const paths = require('./paths')

Expand Down Expand Up @@ -69,7 +70,7 @@ if (remove) {
)
const unusedKeys = ramda.difference(oldKeys, currentKeys)
oldFrResource = ramda.omit(unusedKeys, oldFrResource)
printResult(cli.green('-') + ' Removed', unusedKeys, cli.green)
printResult(c.green('-') + ' Removed', unusedKeys, c.green)
} else {
let result = {
addedTranslations: [],
Expand All @@ -94,13 +95,9 @@ if (remove) {
oldFrResource[key] = value
}
})
printResult(cli.green('+') + ' Added', result.addedTranslations, cli.green)
printResult(
cli.yellow('~') + ' Updated',
result.updatedTranslations,
cli.yellow
)
printResult(cli.red('-') + ' Missing', result.missingTranslations, cli.red)
printResult(c.green('+') + ' Added', result.addedTranslations, c.green)
printResult(c.yellow('~') + ' Updated', result.updatedTranslations, c.yellow)
printResult(c.red('-') + ' Missing', result.missingTranslations, c.red)
}

console.log(`Writting resources in ${paths.UI.fr.withLock}...`)
Expand Down
6 changes: 3 additions & 3 deletions scripts/i18n/translate-faq.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const translateTo = async (srcYAML, destPath, destLang) => {

if (0 < missingEntries.length) {
console.log(
`Found ${cli.yellow(missingEntries.length)} missing translations...`
`Found ${c.yellow(missingEntries.length)} missing translations...`
)
await Promise.all(
missingEntries.map(async (refEntry) => {
Expand Down Expand Up @@ -88,7 +88,7 @@ const translateTo = async (srcYAML, destPath, destLang) => {

utils.writeYAML(destPath, targetEntries)
console.log(
`All missing translations succefully written in ${cli.yellow(destPath)}`
`All missing translations succefully written in ${c.yellow(destPath)}`
)
} else {
console.log('Nothing to be done, all translations are up to date!')
Expand All @@ -100,7 +100,7 @@ const srcYAML = utils.readYAML(srcPath)
const run = async () => {
for (let destLang of destLangs) {
console.log(
`Translating the FAQ files from ${cli.yellow(srcLang)} to ${cli.yellow(
`Translating the FAQ files from ${c.yellow(srcLang)} to ${c.yellow(
destLang
)}...`
)
Expand Down
14 changes: 5 additions & 9 deletions scripts/i18n/translate-nouveautes.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const glob = require('glob')

const deepl = require('@incubateur-ademe/nosgestesclimat-scripts/deepl')
const cli = require('@incubateur-ademe/nosgestesclimat-scripts/cli')
const c = require('ansi-colors')

const { srcLang, destLangs, srcFile, force } = cli.getArgs(
'Calls the DeepL API to translate the Markdown files.',
Expand All @@ -23,7 +24,7 @@ const { srcLang, destLangs, srcFile, force } = cli.getArgs(
const fileGlob = srcFile ?? '*.{md,mdx}'

const translateTo = async (src, destPath, destLang) => {
console.log(`Translating to ${cli.yellow(destPath)}...`)
console.log(`Translating to ${c.yellow(destPath)}...`)
const translation = await deepl.fetchTranslationMarkdown(
src,
srcLang.toUpperCase(),
Expand All @@ -33,18 +34,13 @@ const translateTo = async (src, destPath, destLang) => {
}

console.log(
`Translating Markdown files from ${cli.yellow(
`Translating Markdown files from ${c.yellow(
`src/locales/nouveautes/${srcLang}/${fileGlob}`
)}...`
)
glob(`src/locales/nouveautes/${srcLang}/${fileGlob}`, (err, files) => {
cli.exitIfError(err, 'ERROR: an error occured while fetching the files:')
console.log(
`Found ${cli.withStyle(
cli.colors.fgGreen,
files.length
)} files to translate.`
)
console.log(`Found ${c.green(files.length)} files to translate.`)

console.log('files', files)
files.forEach((file) => {
Expand All @@ -55,7 +51,7 @@ glob(`src/locales/nouveautes/${srcLang}/${fileGlob}`, (err, files) => {
translateTo(src, destPath, destLang)
} else {
console.log(
`The file ${cli.yellow(destPath)} already exists, ${cli.yellow(
`The file ${c.yellow(destPath)} already exists, ${c.yellow(
'skipping'
)}... (use the -f to force the translation)`
)
Expand Down
14 changes: 5 additions & 9 deletions scripts/i18n/translate-pages.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const glob = require('glob')

const deepl = require('@incubateur-ademe/nosgestesclimat-scripts/deepl')
const cli = require('@incubateur-ademe/nosgestesclimat-scripts/cli')
const c = require('ansi-colors')

const { srcLang, destLangs, srcFile, force } = cli.getArgs(
'Calls the DeepL API to translate the Markdown files.',
Expand All @@ -23,7 +24,7 @@ const { srcLang, destLangs, srcFile, force } = cli.getArgs(
const fileGlob = srcFile ?? '*.{md,mdx}'

const translateTo = async (src, destPath, destLang) => {
console.log(`Translating to ${cli.yellow(destPath)}...`)
console.log(`Translating to ${c.yellow(destPath)}...`)
const translation = await deepl.fetchTranslationMarkdown(
src,
srcLang.toUpperCase(),
Expand All @@ -33,18 +34,13 @@ const translateTo = async (src, destPath, destLang) => {
}

console.log(
`Translating Markdown files from ${cli.yellow(
`Translating Markdown files from ${c.yellow(
`src/locales/pages/${srcLang}/${fileGlob}`
)}...`
)
glob(`src/locales/pages/${srcLang}/${fileGlob}`, (err, files) => {
cli.exitIfError(err, 'ERROR: an error occured while fetching the files:')
console.log(
`Found ${cli.withStyle(
cli.colors.fgGreen,
files.length
)} files to translate.`
)
console.log(`Found ${c.green(files.length)} files to translate.`)

console.log('files', files)
files.forEach((file) => {
Expand All @@ -55,7 +51,7 @@ glob(`src/locales/pages/${srcLang}/${fileGlob}`, (err, files) => {
translateTo(src, destPath, destLang)
} else {
console.log(
`The file ${cli.yellow(destPath)} already exists, ${cli.yellow(
`The file ${c.yellow(destPath)} already exists, ${c.yellow(
'skipping'
)}... (use the -f to force the translation)`
)
Expand Down
4 changes: 2 additions & 2 deletions scripts/i18n/translate-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const translateTo = async (srcJSON, tradJSON, destPath, destLang) => {
destLang.toUpperCase()
)
console.log(
`🌍 Translated release ${cli.magenta(release.name)} to ${cli.yellow(
`🌍 Translated release ${c.magenta(release.name)} to ${c.yellow(
destLang
)}`
)
Expand All @@ -60,7 +60,7 @@ destLangs.forEach((destLang) => {
const numberOfMissingTranslation = srcJSON.length - tradJSON.length

if (numberOfMissingTranslation === 0) {
console.log(`🌍 ${cli.yellow(destLang)} is already up to date`)
console.log(`🌍 ${c.yellow(destLang)} is already up to date`)
} else {
translateTo(srcJSON, tradJSON, destPath, destLang)
}
Expand Down
11 changes: 4 additions & 7 deletions scripts/i18n/translate-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const fs = require('fs')
const utils = require('@incubateur-ademe/nosgestesclimat-scripts/utils')
const deepl = require('@incubateur-ademe/nosgestesclimat-scripts/deepl')
const cli = require('@incubateur-ademe/nosgestesclimat-scripts/cli')
const c = require('ansi-colors')

const paths = require('./paths')

Expand Down Expand Up @@ -52,13 +53,9 @@ const translateTo = async (targetLang, targetPath) => {
)

console.log(
`Found ${cli.withStyle(
cli.colors.fgGreen,
`Found ${c.green(
missingTranslations.length
)} missing translations for the language ${cli.withStyle(
cli.colors.fgYellow,
targetLang
)}.`
)} missing translations for the language ${c.yellow(targetLang)}.`
)

let translatedEntries = utils.readYAML(targetPath).entries
Expand Down Expand Up @@ -120,7 +117,7 @@ const translateTo = async (targetLang, targetPath) => {

if (nbEntriesToRemove > 0) {
console.log(
`Removed ${cli.yellow(nbEntriesToRemove)} translations for ${cli.yellow(
`Removed ${c.yellow(nbEntriesToRemove)} translations for ${c.yellow(
targetLang
)}`
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export default function ActionDetail({

const currentSimulation = getCurrentSimulation()

if (!currentSimulation) return
if (!currentSimulation || !rules) {
return null
}

const actionChoices = currentSimulation.actionChoices

Expand Down
Loading

0 comments on commit a0828fb

Please sign in to comment.