Skip to content

Commit

Permalink
feat: add persisting answers (price + PMR)
Browse files Browse the repository at this point in the history
  • Loading branch information
EmileRolley committed Dec 6, 2024
1 parent b714ba8 commit e9ec978
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/lib/components/Questions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
:
</p>
{#each questions as question}
{#if $publicodeSituation['demandeur . en situation de handicap'] !== 'oui' && question === 'revenu fiscal de référence par part'}
{#if question === 'revenu fiscal de référence par part'}
<RevenuSelector {goals} />
{:else if question !== 'revenu fiscal de référence par part'}
<!-- NOTE: needed to avoid dissociated question and values -->
Expand Down
18 changes: 14 additions & 4 deletions src/lib/stores.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import type { Questions, Situation } from '@betagouv/aides-velo';
import { derived, get, writable, type Readable } from 'svelte/store';
import type { Questions, RuleName, Situation } from '@betagouv/aides-velo';
import { derived, get, writable } from 'svelte/store';

export const localisation = writable(null);
export const localisation = writable<any | null>(null);
export const answers = writable({});
// NOTE: maybe should be added to persisting answers
export const revenuFiscal = writable(undefined);
export const veloCat = writable<Questions['vélo . type']>();

export const PERSISTING_ANSWSERS: RuleName[] = [
'demandeur . en situation de handicap',
'vélo . prix',
];

/** resetAnswers() will remove all answers from the store except the ones listed in {@link PERSISTING_ANSWSERS} */
export const resetAnswers = () => {
if (Object.keys(get(answers)).length > 0) {
answers.set({});
const persistingAnswers = Object.fromEntries(
Object.entries(get(answers)).filter(([key]) => PERSISTING_ANSWSERS.includes(key as RuleName)),
);
answers.set(persistingAnswers);
}
};

Expand Down
26 changes: 26 additions & 0 deletions tests/navigation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,32 @@ test('Revenu selector', async ({ page }) => {
await expect(page.locator('.playwright-revenuoptions input[type=radio]')).toHaveCount(3);
});

test('Persisting answers', async ({ page }) => {
await page.goto(baseUrl + '/ville/lyon');
await page.waitForTimeout(100);
await expect(page.locator('text=aide non disponible')).toHaveCount(0);

await page.click('text=plus de 2 076 €');
await expect(page.locator('text=aide non disponible')).toHaveCount(8);

await page.getByLabel('Oui').click();
await expect(page.locator('text=aide non disponible')).toHaveCount(1);

await page.click("text=Achat d'un vélo électrique");
await page.waitForTimeout(100);
await expect(page.locator('text=total des aides >> ..')).toHaveText('Total des aides 400 €');

await page.fill('input:below(label:text("Quel est le prix du vélo ?"))', '100');

await page.goBack();
await page.waitForTimeout(100);

await page.click("text=Achat d'un vélo mécanique simple");
await page.waitForTimeout(100);
await expect(page.locator('text=aide non disponible')).toHaveCount(0);
expect(page.getByTestId('question-velo-prix-value-100')).toBeTruthy();
});

test('New or second hand bike', async ({ page }) => {
await page.goto(baseUrl + '/ville/toulouse?velo=électrique');
expect(page.locator("text=neuf ou d'occasion ?")).toBeTruthy();
Expand Down

0 comments on commit e9ec978

Please sign in to comment.