Skip to content

Commit

Permalink
feat(useMikadoGraph): the prerequisite form can only be opened once
Browse files Browse the repository at this point in the history
  • Loading branch information
arnolanglade committed Nov 9, 2023
1 parent 8b0ea61 commit 7b4008b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/mikado-graph/component/mikado-graph.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use client';

import React, { useEffect } from 'react';
import React from 'react';
import { StatusView } from '@/api/mikado-graph/mikado-graph';
import AddPrerequisiteForm from '@/mikado-graph/component/add-prerequisite-form';
import { Translation } from '@/tools/i18n/intl-provider';
import {
Controls, Handle, MiniMap, Position, ReactFlow, useEdgesState, useNodesState,
Controls, Handle, MiniMap, Position, ReactFlow,
} from 'reactflow';
import {
GaolData, MikadoGraph, NewPrerequisiteData, PrerequisiteData,
Expand Down
25 changes: 21 additions & 4 deletions app/mikado-graph/mikado-graph.usecase.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,7 @@ describe('useMikadoGraph', () => {
const mikadoGraphId = uuidv4();
const mikadoGraphView = aMikadoGraphView({ mikadoGraphId, prerequisites: [] });
const { result } = renderHook(() => useMikadoGraph(mikadoGraphView), {
wrapper: createWrapper(
{},
{ 'prerequisite.notification.add-prerequisite.success': 'The prerequisite has been added' },
),
wrapper: createWrapper(),
});

await act(() => result.current.openPrerequisiteForm(mikadoGraphId));
Expand All @@ -217,6 +214,26 @@ describe('useMikadoGraph', () => {
target: 'new-prerequisite',
});
});

test('The prerequisite form can only be opened once', async () => {
const parentId = uuidv4();
const mikadoGraphView = aMikadoGraphView({
mikadoGraphId: parentId,
prerequisites: [
{ prerequisiteId: 'new-prerequisite', parentId: uuidv4() },
],
});
const { result } = renderHook(() => useMikadoGraph(mikadoGraphView), {
wrapper: createWrapper(),
});

await act(() => result.current.openPrerequisiteForm(parentId));

expect(result.current.mikadoGraph.nodes[1]).toMatchObject({
id: 'new-prerequisite',
parentId,
}); // 0: Goal + 1: prerequisite
});
});

describe('add prerequisite', () => {
Expand Down
4 changes: 3 additions & 1 deletion app/mikado-graph/mikado-graph.usecase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ export default function useMikadoGraph(defaultMikadoGraphView: MikadoGraphView)
const nodeHeight = 350;

const openPrerequisiteForm = (parentId: string) => {
const prerequisiteWithoutNodeForm = mikadoGraphView.prerequisites.filter((p) => p.prerequisiteId !== 'new-prerequisite');

setMikadoGraphView({
...mikadoGraphView,
prerequisites: [...mikadoGraphView.prerequisites, {
prerequisites: [...prerequisiteWithoutNodeForm, {
prerequisiteId: 'new-prerequisite',
parentId,
label: '',
Expand Down

0 comments on commit 7b4008b

Please sign in to comment.