Skip to content

Commit

Permalink
feat(GODIET-60): ✨ create page to create energy calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitor Sousa committed Apr 11, 2024
1 parent cbd3ed1 commit eaa2c85
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { CreateEnergyCalculationView } from './create-energy-calculation.view';
export function CreateEnergyCalculationController(
props: CreateEnergyCalculationHookOutput
) {
const { pageStatus, state } = props;
const { pageStatus, handleSubmit } = props;

const { isError, isLoading, noData } = pageStatus;

Expand All @@ -34,5 +34,5 @@ export function CreateEnergyCalculationController(
return <CreateEnergyCalculationEmpty />;
}

return <CreateEnergyCalculationView data={state} />;
return <CreateEnergyCalculationView onSubmit={handleSubmit} />;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { useState } from 'react';
import React from 'react';

import { ReturnHookPage } from '@godiet-utils/types';

import { TCreateEnergyCalculationDTO } from './components/EnergyCalculationForm';

/**
* Define o formato de saída do hook `useCreateEnergyCalculationHook`.
*
Expand All @@ -10,7 +12,7 @@ import { ReturnHookPage } from '@godiet-utils/types';
* @interface CreateEnergyCalculationHookProps
*/
interface CreateEnergyCalculationHookProps {
state: number;
handleSubmit: (data: TCreateEnergyCalculationDTO) => Promise<void>;
}
/**
* Adiciona na tipagem do retorno do hook algumas tipagens obrigatórias.
Expand All @@ -26,14 +28,19 @@ export type CreateEnergyCalculationHookOutput =
* @returns Retorna um objeto contendo o estado interno e o status da página.
*/
export function useCreateEnergyCalculationHook(): CreateEnergyCalculationHookOutput {
const [state] = useState(0);
const handleSubmit = React.useCallback(
async (data: TCreateEnergyCalculationDTO) => {
console.log(data);
},
[]
);

return {
state,
handleSubmit,
pageStatus: {
isLoading: false,
isError: false,
noData: true,
noData: false,
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,5 @@ export function CreateEnergyCalculationLayout(
) {
const { children } = props;

return (
<div>
CreateEnergyCalculation layout
{children}
</div>
);
return <>{children}</>;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import {
render,
renderHook,
ReturnRenderHookType,
ReturnRenderType,
} from '@testing-react';
import { clearAllMocks } from '@testing-suit';

import { useCreateEnergyCalculationHook } from './create-energy-calculation.hook';
import { render, ReturnRenderType } from '@testing-react';
import { clearAllMocks, fn } from '@testing-suit';

import { CreateEnergyCalculationView } from './create-energy-calculation.view';

describe('CreateEnergyCalculationPage', () => {
Expand All @@ -29,32 +23,32 @@ describe('CreateEnergyCalculationPage', () => {
// Arrange

// Act
rendered = render(<CreateEnergyCalculationView data={0} />);
rendered = render(<CreateEnergyCalculationView onSubmit={fn()} />);

// Assert
expect(rendered.getByText('CreateEnergyCalculation view'));
expect(rendered.getByText('Estimativa de gasto energético'));
});
});

describe('Hook', () => {
let rendered: ReturnRenderHookType<typeof useCreateEnergyCalculationHook>;
// describe('Hook', () => {
// let rendered: ReturnRenderHookType<typeof useCreateEnergyCalculationHook>;

beforeEach(() => {
clearAllMocks();
});
// beforeEach(() => {
// clearAllMocks();
// });

afterEach(() => {
rendered.unmount();
});
// afterEach(() => {
// rendered.unmount();
// });

it('Should render the hook with default props', () => {
// Arrange
// it('Should render the hook with default props', () => {
// // Arrange

// Act
rendered = renderHook(() => useCreateEnergyCalculationHook());
// // Act
// rendered = renderHook(() => useCreateEnergyCalculationHook());

// Assert
expect(rendered.result.current.state).toEqual(0);
});
});
// // Assert
// expect(rendered.result.current.state).toEqual(0);
// });
// });
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import { Button } from '@godiet-ui/Button';

import {
EnergyCalculationForm,
TCreateEnergyCalculationDTO,
} from './components/EnergyCalculationForm';

/**
* Interface que define as propriedades aceitas pelo componente `CreateEnergyCalculationView`.
*
Expand All @@ -6,7 +13,7 @@
* @interface CreateEnergyCalculationViewProps
*/
export interface CreateEnergyCalculationViewProps {
data: number;
onSubmit: (data: TCreateEnergyCalculationDTO) => Promise<void>;
}

/**
Expand All @@ -17,12 +24,20 @@ export interface CreateEnergyCalculationViewProps {
export function CreateEnergyCalculationView(
props: CreateEnergyCalculationViewProps
) {
const { data } = props;
const { onSubmit } = props;

return (
<div>
<h1>CreateEnergyCalculation view</h1>
{data}
<div className="mb-10">
<h1 className="font-bold">Estimativa de gasto energético</h1>

<EnergyCalculationForm
formId="create-energy-calculation"
onSubmit={onSubmit}
/>

<Button type="submit" form="create-energy-calculation">
Criar
</Button>
</div>
);
}

0 comments on commit eaa2c85

Please sign in to comment.