Skip to content

Commit

Permalink
Fix demo creation bug (#508)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinejaussoin authored Mar 25, 2023
1 parent 4297719 commit 85fc317
Show file tree
Hide file tree
Showing 19 changed files with 69 additions and 23 deletions.
2 changes: 1 addition & 1 deletion frontend/src/auth/AccountMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const AccountMenu = () => {
<DisplayName>{user.name}</DisplayName>
<ChipContainer>
{user.accountType === 'anonymous' ? (
<Chip color="secondary" label="Anonymous" />
<Chip color="secondary" label={t('Header.anonymous')} />
) : null}
</ChipContainer>
<AccountCircle fontSize={'large'} />
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/translations/locales/ar-SA.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"leave": "غادر",
"summaryMode": "النّمط الملخّص",
"account": "حسابي",
"adminPanel": "لوحة الإدارة"
"adminPanel": "لوحة الإدارة",
"anonymous": "مجهول"
},
"LanguagePicker": {
"header": "إختيار اللُّغة"
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/translations/locales/de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"leave": "Verlassen",
"summaryMode": "Zusammenfassungsmodus",
"account": "Mein Konto",
"adminPanel": "Administrationsbereich"
"adminPanel": "Administrationsbereich",
"anonymous": "Anonym"
},
"LanguagePicker": {
"header": "Sprache auswählen"
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/translations/locales/en-GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"leave": "Leave",
"summaryMode": "Summary Mode",
"account": "My Account",
"adminPanel": "Administration Panel"
"adminPanel": "Administration Panel",
"anonymous": "Anonymous"
},
"LanguagePicker": {
"header": "Choose a language"
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/translations/locales/es-ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"leave": "Salir",
"summaryMode": "Modo resumido",
"account": "Mi cuenta",
"adminPanel": "Panel de administración"
"adminPanel": "Panel de administración",
"anonymous": "Anónimo"
},
"LanguagePicker": {
"header": "Escoje un idioma"
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/translations/locales/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"leave": "Sortir",
"summaryMode": "Mode Résumé",
"account": "Mon compte",
"adminPanel": "Gestion des utilisateurs"
"adminPanel": "Gestion des utilisateurs",
"anonymous": "Anonyme"
},
"LanguagePicker": {
"header": "Changez de langue"
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/translations/locales/hu-HU.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"leave": "Távozás",
"summaryMode": "Összesített mód",
"account": "Fiókom",
"adminPanel": "Adminisztrációs panel"
"adminPanel": "Adminisztrációs panel",
"anonymous": ""
},
"LanguagePicker": {
"header": "Válassz nyelvet"
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/translations/locales/it-IT.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"leave": "Abbandona",
"summaryMode": "Modalità sommario",
"account": "Il Mio Account",
"adminPanel": "Pannello Di Amministrazione"
"adminPanel": "Pannello Di Amministrazione",
"anonymous": "Anonimo"
},
"LanguagePicker": {
"header": "Scegli una lingua"
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/translations/locales/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"leave": "退室",
"summaryMode": "要約モード",
"account": "マイアカウント",
"adminPanel": "管理パネル"
"adminPanel": "管理パネル",
"anonymous": "匿名です"
},
"LanguagePicker": {
"header": "言語を選択"
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/translations/locales/nl-NL.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"leave": "Verlaten",
"summaryMode": "Samenvatting",
"account": "Mijn account",
"adminPanel": "Beheer paneel"
"adminPanel": "Beheer paneel",
"anonymous": "Anoniem"
},
"LanguagePicker": {
"header": "Kies een taal"
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/translations/locales/pl-PL.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"leave": "Wyjdź",
"summaryMode": "Tryb Podsumowania",
"account": "Moje konto",
"adminPanel": "Panel administracyjny"
"adminPanel": "Panel administracyjny",
"anonymous": "Anonimowe"
},
"LanguagePicker": {
"header": "Wybierz język"
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/translations/locales/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"leave": "Sair",
"summaryMode": "Modo Sumário",
"account": "Minha conta",
"adminPanel": "Painel de Administração"
"adminPanel": "Painel de Administração",
"anonymous": "Anônimo"
},
"LanguagePicker": {
"header": "Escolha uma língua"
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/translations/locales/pt-PT.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"leave": "Sair",
"summaryMode": "Modo de Resumo",
"account": "Minha conta",
"adminPanel": "Painel de Administração"
"adminPanel": "Painel de Administração",
"anonymous": "Anônimo"
},
"LanguagePicker": {
"header": "Escolha um idioma"
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/translations/locales/uk-UA.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"leave": "Залишити",
"summaryMode": "Анонімний режим",
"account": "Особистий кабінет",
"adminPanel": "Панель адміністрування"
"adminPanel": "Панель адміністрування",
"anonymous": "Анонімний"
},
"LanguagePicker": {
"header": "Виберіть мову"
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/translations/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"leave": "离开",
"summaryMode": "主旨模式",
"account": "我的帐户",
"adminPanel": "管理面板"
"adminPanel": "管理面板",
"anonymous": "匿名的"
},
"LanguagePicker": {
"header": "切换语言"
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/translations/locales/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"leave": "離開",
"summaryMode": "主旨模式",
"account": "我的賬戶",
"adminPanel": "管理面板"
"adminPanel": "管理面板",
"anonymous": ""
},
"LanguagePicker": {
"header": "切換語言"
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/translations/useLanguage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type UseLanguageResult = [
export default function useLanguage(): UseLanguageResult {
const { i18n } = useTranslation();
const { user, setUser } = useContext(UserContext);
const hasUser = !!user;

const locale = i18n.language;
const language = useMemo(() => {
Expand All @@ -25,14 +26,14 @@ export default function useLanguage(): UseLanguageResult {
async (language: string) => {
trackEvent(`language/change/${language}` as TrackingEvent);
i18n.changeLanguage(language);
if (user) {
if (hasUser) {
const updatedUser = await updateLanguage(language);
if (updatedUser) {
setUser(updatedUser);
}
}
},
[user, setUser, i18n]
[hasUser, setUser, i18n]
);

return [language, handleChangeLanguage];
Expand Down
17 changes: 12 additions & 5 deletions frontend/src/views/Demo.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import styled from '@emotion/styled';
import { colors } from '@mui/material';
import { anonymousLogin, createDemoGame, me, updateLanguage } from 'api';
import { createDemoGame, me, updateLanguage } from 'api';
import UserContext from 'auth/Context';
import { useContext, useEffect } from 'react';
import { useSearchParams } from 'react-router-dom';
Expand All @@ -12,12 +12,17 @@ export default function Demo() {
const { setUser } = useContext(UserContext);
let [searchParams] = useSearchParams();
const twoLetter = searchParams.get('lang');
const [, changeLanguage] = useLanguage();
const [currentLanguage, changeLanguage] = useLanguage();
const language = getLanguage(twoLetter || 'en');

useEffect(() => {
if (currentLanguage.locale !== language.locale) {
changeLanguage(language.locale);
}
}, [language.locale, currentLanguage.locale, changeLanguage]);

useEffect(() => {
async function fetch() {
await anonymousLogin('Demo User');
trackEvent('register/demo');
let updatedUser = await me();
if (updatedUser?.language === null) {
Expand All @@ -30,8 +35,10 @@ export default function Demo() {
window.location.href = `/game/${session.id}`;
}
}
fetch();
}, [language.locale, setUser, changeLanguage]);
if (language.locale === currentLanguage.locale) {
fetch();
}
}, [language.locale, currentLanguage.locale, setUser, changeLanguage]);
return (
<Container>
<h1>Preparing demo...</h1>
Expand Down
23 changes: 23 additions & 0 deletions integration/cypress/e2e/test.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,26 @@ describe('Post workflow', () => {
cy.get('body', { timeout }).get('h1').should('contain', 'Welcome!');
});
});

describe('Demo Workflow', () => {
beforeEach(() => {
cy.setCookie('wpcc', 'dismiss');
});

it('Should create a demo with the right language (French)', () => {
// Asking for a FR demo
cy.visit('/demo?lang=fr');

// It should contain the right post (in English)
cy.get('#content', { timeout }).should(
'contain',
"I'm enjoying our new retrospective board!"
);

// But the UI must be in French
cy.get('#content', { timeout }).should(
'contain',
'Bienvenue dans cette démo'
);
});
});

0 comments on commit 85fc317

Please sign in to comment.