From 4ad46ecfb35ae2eda73fc02ea2c3a3efdcd141fc Mon Sep 17 00:00:00 2001 From: RubenGonzalezAutentia Date: Tue, 28 May 2024 11:10:49 +0200 Subject: [PATCH 1/4] feat: new subcontracted activity filters --- .../get-subcontracted-activities-qry.ts | 21 +++--- ...t-subcontracted-activities-query-params.ts | 4 +- .../subcontracted-activity-repository.ts | 4 +- .../http-subcontracted-activity-repository.ts | 10 +-- ...bcontracted-activity-filter-form.schema.ts | 8 ++- .../subcontracted-activity-filter-form.tsx | 37 ++++++++--- .../subcontracted-activities-list.tsx | 64 ++++++------------- 7 files changed, 69 insertions(+), 79 deletions(-) diff --git a/src/features/binnacle/features/activity/application/get-subcontracted-activities-qry.ts b/src/features/binnacle/features/activity/application/get-subcontracted-activities-qry.ts index 456e0c20..07132602 100644 --- a/src/features/binnacle/features/activity/application/get-subcontracted-activities-qry.ts +++ b/src/features/binnacle/features/activity/application/get-subcontracted-activities-qry.ts @@ -1,40 +1,41 @@ import { Query, UseCaseKey } from '@archimedes/arch' -import { GetUserLoggedQry } from '../../../../shared/user/application/get-user-logged-qry' import { SUBCONTRACTED_ACTIVITY_REPOSITORY } from '../../../../../shared/di/container-tokens' -import { DateInterval } from '../../../../../shared/types/date-interval' import { chrono } from '../../../../../shared/utils/chrono' import { inject, singleton } from 'tsyringe' import { SearchProjectRolesQry } from '../../search/application/search-project-roles-qry' import { SubcontractedActivity } from '../domain/subcontracted-activity' import type { SubcontractedActivityRepository } from '../domain/subcontracted-activity-repository' import { SubcontractedActivitiesWithRoleInformation } from '../domain/services/subcontracted-activities-with-role-information' +import { GetSubcontractedActivitiesQueryParams } from '../domain/get-subcontracted-activities-query-params' @UseCaseKey('GetSubcontractedActivitiesQry') @singleton() -export class GetSubcontractedActivitiesQry extends Query { +export class GetSubcontractedActivitiesQry extends Query< + SubcontractedActivity[], + GetSubcontractedActivitiesQueryParams +> { constructor( @inject(SUBCONTRACTED_ACTIVITY_REPOSITORY) private readonly subcontractedActivityRepository: SubcontractedActivityRepository, private readonly searchProjectRolesQry: SearchProjectRolesQry, - private readonly subcontractedActivitiesWithRoleInformation: SubcontractedActivitiesWithRoleInformation, - private readonly getUserLoggedQry: GetUserLoggedQry + private readonly subcontractedActivitiesWithRoleInformation: SubcontractedActivitiesWithRoleInformation ) { super() } - async internalExecute(dateInterval: DateInterval): Promise { - const { id } = await this.getUserLoggedQry.execute() - const activitiesResponse = await this.subcontractedActivityRepository.getAll(dateInterval, id) + async internalExecute( + filters: GetSubcontractedActivitiesQueryParams + ): Promise { + const activitiesResponse = await this.subcontractedActivityRepository.getAll(filters) const activitiesSorted = activitiesResponse.slice() activitiesSorted.sort((a, b) => (chrono(new Date(a.month)).isAfter(new Date(b.month)) ? 1 : -1)) const projectRoleIds = activitiesSorted.map((a) => a.projectRoleId) const uniqueProjectRoleIds = Array.from(new Set(projectRoleIds)) - const { start } = dateInterval const projectRolesInformation = await this.searchProjectRolesQry.execute({ ids: uniqueProjectRoleIds, - year: start.getFullYear() + year: chrono(filters.startDate).getDate().getFullYear() }) return this.subcontractedActivitiesWithRoleInformation.addRoleInformationToActivities( diff --git a/src/features/binnacle/features/activity/domain/get-subcontracted-activities-query-params.ts b/src/features/binnacle/features/activity/domain/get-subcontracted-activities-query-params.ts index ab7249c0..7e96f7eb 100644 --- a/src/features/binnacle/features/activity/domain/get-subcontracted-activities-query-params.ts +++ b/src/features/binnacle/features/activity/domain/get-subcontracted-activities-query-params.ts @@ -1,7 +1,5 @@ -import { Id } from '../../../../../shared/types/id' - export interface GetSubcontractedActivitiesQueryParams { - userId?: Id startDate: string endDate: string + organizationId?: number } diff --git a/src/features/binnacle/features/activity/domain/subcontracted-activity-repository.ts b/src/features/binnacle/features/activity/domain/subcontracted-activity-repository.ts index f7d59ee0..0cbb7d33 100644 --- a/src/features/binnacle/features/activity/domain/subcontracted-activity-repository.ts +++ b/src/features/binnacle/features/activity/domain/subcontracted-activity-repository.ts @@ -1,4 +1,3 @@ -import { DateInterval } from '../../../../../shared/types/date-interval' import { Id } from '../../../../../shared/types/id' import { NewSubcontractedActivity } from './new-subcontracted-activity' import { UpdateSubcontractedActivity } from './update-subcontracted-activity' @@ -7,8 +6,7 @@ import { SubcontractedActivityWithProjectRoleId } from './subcontracted-activity export interface SubcontractedActivityRepository { getAll( - { start, end }: DateInterval, - userId: Id + queryParams: GetSubcontractedActivitiesQueryParams ): Promise getActivitiesBasedOnFilters( diff --git a/src/features/binnacle/features/activity/infrastructure/http-subcontracted-activity-repository.ts b/src/features/binnacle/features/activity/infrastructure/http-subcontracted-activity-repository.ts index 8fad7e7d..d88a5399 100644 --- a/src/features/binnacle/features/activity/infrastructure/http-subcontracted-activity-repository.ts +++ b/src/features/binnacle/features/activity/infrastructure/http-subcontracted-activity-repository.ts @@ -1,7 +1,5 @@ import { HttpClient } from '../../../../../shared/http/http-client' -import { DateInterval } from '../../../../../shared/types/date-interval' import { Id } from '../../../../../shared/types/id' -import { chrono, getLastDayOfMonth } from '../../../../../shared/utils/chrono' import { singleton } from 'tsyringe' import { SubcontractedActivityRepository } from '../domain/subcontracted-activity-repository' import { SubcontractedActivityWithProjectRoleId } from '../domain/subcontracted-activity-with-project-role-id' @@ -22,17 +20,13 @@ export class HttpSubcontractedActivityRepository implements SubcontractedActivit constructor(private readonly httpClient: HttpClient) {} async getAll( - { start, end }: DateInterval, - userId: number + queryParams: GetSubcontractedActivitiesQueryParams ): Promise { - end = getLastDayOfMonth(end) const data = await this.httpClient.get( HttpSubcontractedActivityRepository.activityPath, { params: { - startDate: chrono(start).format(chrono.DATE_FORMAT), - endDate: chrono(end).format(chrono.DATE_FORMAT), - userId + ...queryParams } } ) diff --git a/src/features/binnacle/features/activity/ui/components/subcontracted-activities-list/components/activity-filter/subcontracted-activity-filter-form.schema.ts b/src/features/binnacle/features/activity/ui/components/subcontracted-activities-list/components/activity-filter/subcontracted-activity-filter-form.schema.ts index e4958503..5edffa25 100644 --- a/src/features/binnacle/features/activity/ui/components/subcontracted-activities-list/components/activity-filter/subcontracted-activity-filter-form.schema.ts +++ b/src/features/binnacle/features/activity/ui/components/subcontracted-activities-list/components/activity-filter/subcontracted-activity-filter-form.schema.ts @@ -1,10 +1,12 @@ -import { object, string } from 'yup' +import { ObjectSchema, object, string } from 'yup' import { i18n } from '../../../../../../../../../shared/i18n/i18n' import { chrono } from '../../../../../../../../../shared/utils/chrono' +import { Organization } from '../../../../../../organization/domain/organization' export interface SubcontractedActivityFilterFormSchema { startDate: string endDate: string + organization: Organization | undefined } export const SubcontractedActivityFilterFormValidationSchema = object({ @@ -13,7 +15,7 @@ export const SubcontractedActivityFilterFormValidationSchema = object({ .required(i18n.t('form_errors.field_required')) .test('is-greater', i18n.t('form_errors.end_date_greater'), function () { const { startDate, endDate } = this.parent - return chrono(endDate).isSame(startDate, 'day') || chrono(endDate).isAfter(startDate) - }) + }), + organization: object().optional() as ObjectSchema }).defined() diff --git a/src/features/binnacle/features/activity/ui/components/subcontracted-activities-list/components/activity-filter/subcontracted-activity-filter-form.tsx b/src/features/binnacle/features/activity/ui/components/subcontracted-activities-list/components/activity-filter/subcontracted-activity-filter-form.tsx index 2f557592..26ec4473 100644 --- a/src/features/binnacle/features/activity/ui/components/subcontracted-activities-list/components/activity-filter/subcontracted-activity-filter-form.tsx +++ b/src/features/binnacle/features/activity/ui/components/subcontracted-activities-list/components/activity-filter/subcontracted-activity-filter-form.tsx @@ -9,10 +9,12 @@ import { } from './subcontracted-activity-filter-form.schema' import { chrono } from '../../../../../../../../../shared/utils/chrono' import { MonthField } from '../../../../../../../../../shared/components/form-fields/month-field' +import { OrganizationsCombo } from '../../../activity-form/components/combos/organizations-combo' +import { GetSubcontractedActivitiesQueryParams } from '../../../../../domain/get-subcontracted-activities-query-params' interface Props { - filters: { start: Date; end: Date } - onFiltersChange: (startDate: Date, endDate: Date) => Promise + filters: GetSubcontractedActivitiesQueryParams + onFiltersChange: (params: GetSubcontractedActivitiesQueryParams) => Promise } export const SubcontractedActivityFilterForm: FC = (props) => { @@ -22,13 +24,15 @@ export const SubcontractedActivityFilterForm: FC = (props) => { const { register, handleSubmit, + control, trigger, watch, formState: { errors } } = useForm({ defaultValues: { - startDate: chrono(filters.start).format('yyyy-MM'), - endDate: chrono(filters.end).format('yyyy-MM') + startDate: chrono(filters.startDate).format('yyyy-MM'), + endDate: chrono(filters.endDate).format('yyyy-MM'), + organization: undefined }, resolver: yupResolver(SubcontractedActivityFilterFormValidationSchema), mode: 'onChange' @@ -36,20 +40,30 @@ export const SubcontractedActivityFilterForm: FC = (props) => { const onSubmit = useCallback( (data: SubcontractedActivityFilterFormSchema) => { - onFiltersChange(chrono(data.startDate).getDate(), chrono(data.endDate).getDate()) + const startDate = chrono(data.startDate).startOf('month').format('yyyy-MM-dd') + const endDate = chrono(data.endDate).endOf('month').format('yyyy-MM-dd') + const organizationId = data.organization?.id + + onFiltersChange({ + startDate, + endDate, + organizationId + }) }, [onFiltersChange] ) useEffect(() => { - const subscription = watch(async () => { + const subscription = watch(async (newValues) => { const isValid = await trigger() if (isValid) { - handleSubmit(onSubmit)() + // TODO: review types here + //@ts-ignore + handleSubmit(() => onSubmit(newValues))() } }) return () => subscription?.unsubscribe() - }, [watch, handleSubmit, filters, trigger, onSubmit]) + }, [handleSubmit]) return ( @@ -67,6 +81,13 @@ export const SubcontractedActivityFilterForm: FC = (props) => { {...register('endDate')} /> + + + ) } diff --git a/src/features/binnacle/features/activity/ui/components/subcontracted-activities-list/subcontracted-activities-list.tsx b/src/features/binnacle/features/activity/ui/components/subcontracted-activities-list/subcontracted-activities-list.tsx index 35ec3631..b02e84cd 100644 --- a/src/features/binnacle/features/activity/ui/components/subcontracted-activities-list/subcontracted-activities-list.tsx +++ b/src/features/binnacle/features/activity/ui/components/subcontracted-activities-list/subcontracted-activities-list.tsx @@ -12,14 +12,12 @@ import { SubcontractedActivityFilterForm } from './components/activity-filter/su import { CreateSubcontractedActivityCmd } from '../../../application/create-subcontracted-activity-cmd' import { UpdateSubcontractedActivityCmd } from '../../../application/update-subcontracted-activity-cmd' import { DeleteSubcontractedActivityCmd } from '../../../application/delete-subcontracted-activity-cmd' -import { DateInterval } from '../../../../../../../shared/types/date-interval' -import { useQueryParams } from '../../../../../../../shared/router/use-query-params' import { TimeUnits } from '../../../../../../../shared/types/time-unit' import { SubcontractedActivityModal } from '../subcontracted-activity-modal/subcontracted-activity-modal' import { SubcontractedActivity } from '../../../domain/subcontracted-activity' import { RemoveSubcontractedActivityButton } from '../subcontracted-activity-form/components/remove-subcontracted-activity-button' import { SUBCONTRACTED_ACTIVITY_FORM_ID } from '../subcontracted-activity-form/subcontracted-activity-form' -import { format } from 'date-fns' +import { GetSubcontractedActivitiesQueryParams } from '../../../domain/get-subcontracted-activities-query-params' interface Props { onCloseSubcontractedActivity: () => void @@ -36,74 +34,52 @@ export const SubcontractedActivitiesList: FC = ({ const [isLoadingForm, setIsLoadingForm] = useState(false) const [showSubcontractedActivityModal, setShowSubcontractedActivityModal] = useState(false) const [lastEndTime, setLastEndTime] = useState() - + /* const formatDate = (startDate: Date, endDate: Date) => { return { - startDate: format(startDate, 'yyyy-MM'), - endDate: format(endDate, 'yyyy-MM') - } - } - - const initialValue: DateInterval = useMemo( - () => ({ - start: new Date( - selectedDate.getFullYear(), - selectedDate.getMonth() - 2, - selectedDate.getDate() - ), - end: new Date(selectedDate) - }), - [selectedDate] - ) - - const { queryParams, onQueryParamsChange } = useQueryParams( - formatDate(initialValue.start, initialValue.end) - ) - - const selectedDateInterval = useMemo(() => { - if (queryParams === undefined || Object.keys(queryParams).length === 0) { - onQueryParamsChange(formatDate(initialValue.start, initialValue.end)) - return initialValue + startDate: format(startDate, 'yyyy-MM-dd'), + endDate: format(endDate, 'yyyy-MM-dd') } + }*/ - return { - start: chrono(queryParams.startDate).getDate(), - end: chrono(queryParams.endDate).getDate() - } - }, [initialValue, onQueryParamsChange, queryParams]) + const [queryParams, setQueryParams] = useState({ + startDate: chrono(new Date()).startOf('year').format(chrono.DATE_FORMAT), + endDate: chrono(new Date()).format(chrono.DATE_FORMAT) + }) const { isLoading: isLoadingActivities, result: subcontractedActivities = [], executeUseCase: getSubcontractedActivitiesQry - } = useExecuteUseCaseOnMount(GetSubcontractedActivitiesQry, selectedDateInterval) + } = useExecuteUseCaseOnMount(GetSubcontractedActivitiesQry, queryParams) useSubscribeToUseCase( CreateSubcontractedActivityCmd, () => { - getSubcontractedActivitiesQry(selectedDateInterval) + getSubcontractedActivitiesQry(queryParams) }, - [selectedDateInterval] + [queryParams] ) useSubscribeToUseCase( UpdateSubcontractedActivityCmd, () => { - getSubcontractedActivitiesQry(selectedDateInterval) + getSubcontractedActivitiesQry(queryParams) }, - [selectedDateInterval] + [queryParams] ) useSubscribeToUseCase( DeleteSubcontractedActivityCmd, () => { - getSubcontractedActivitiesQry(selectedDateInterval) + getSubcontractedActivitiesQry(queryParams) }, - [selectedDateInterval] + [queryParams] ) - const applyFilters = async (startDate: Date, endDate: Date): Promise => { - onQueryParamsChange(formatDate(startDate, endDate)) + const applyFilters = async (newParams: GetSubcontractedActivitiesQueryParams): Promise => { + setQueryParams(newParams) + getSubcontractedActivitiesQry(newParams) } const onActivityClicked = (activity: SubcontractedActivity) => { @@ -139,7 +115,7 @@ export const SubcontractedActivitiesList: FC = ({ return ( <> From e709d93dad197e3d1e63065774e1a34df6a359a7 Mon Sep 17 00:00:00 2001 From: RubenGonzalezAutentia Date: Tue, 28 May 2024 12:05:56 +0200 Subject: [PATCH 2/4] fix: move organization field position --- .../subcontracted-activity-filter-form.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/features/binnacle/features/activity/ui/components/subcontracted-activities-list/components/activity-filter/subcontracted-activity-filter-form.tsx b/src/features/binnacle/features/activity/ui/components/subcontracted-activities-list/components/activity-filter/subcontracted-activity-filter-form.tsx index 26ec4473..9c73230e 100644 --- a/src/features/binnacle/features/activity/ui/components/subcontracted-activities-list/components/activity-filter/subcontracted-activity-filter-form.tsx +++ b/src/features/binnacle/features/activity/ui/components/subcontracted-activities-list/components/activity-filter/subcontracted-activity-filter-form.tsx @@ -67,6 +67,13 @@ export const SubcontractedActivityFilterForm: FC = (props) => { return ( + + + = (props) => { {...register('endDate')} /> - - - ) } From c408a352afde2a92e6363a4d47ba73d14a13d52e Mon Sep 17 00:00:00 2001 From: RubenGonzalezAutentia Date: Tue, 28 May 2024 12:09:25 +0200 Subject: [PATCH 3/4] fix: remove commented code --- .../subcontracted-activities-list.tsx | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/features/binnacle/features/activity/ui/components/subcontracted-activities-list/subcontracted-activities-list.tsx b/src/features/binnacle/features/activity/ui/components/subcontracted-activities-list/subcontracted-activities-list.tsx index b02e84cd..0e3f1a1b 100644 --- a/src/features/binnacle/features/activity/ui/components/subcontracted-activities-list/subcontracted-activities-list.tsx +++ b/src/features/binnacle/features/activity/ui/components/subcontracted-activities-list/subcontracted-activities-list.tsx @@ -34,13 +34,6 @@ export const SubcontractedActivitiesList: FC = ({ const [isLoadingForm, setIsLoadingForm] = useState(false) const [showSubcontractedActivityModal, setShowSubcontractedActivityModal] = useState(false) const [lastEndTime, setLastEndTime] = useState() - /* - const formatDate = (startDate: Date, endDate: Date) => { - return { - startDate: format(startDate, 'yyyy-MM-dd'), - endDate: format(endDate, 'yyyy-MM-dd') - } - }*/ const [queryParams, setQueryParams] = useState({ startDate: chrono(new Date()).startOf('year').format(chrono.DATE_FORMAT), From 9958d33a21ffe1111cd135c99e7a0bd9e865958e Mon Sep 17 00:00:00 2001 From: RubenGonzalezAutentia Date: Tue, 28 May 2024 12:45:59 +0200 Subject: [PATCH 4/4] fix: test --- .../get-subcontracted-activities-qry.test.ts | 21 +++++++++--------- ...-subcontracted-activity-repository.test.ts | 19 ++++++---------- ...ubcontracted-activity-filter-form.test.tsx | 22 ++++++++++--------- 3 files changed, 29 insertions(+), 33 deletions(-) diff --git a/src/features/binnacle/features/activity/application/get-subcontracted-activities-qry.test.ts b/src/features/binnacle/features/activity/application/get-subcontracted-activities-qry.test.ts index 10ef5b62..77cce291 100644 --- a/src/features/binnacle/features/activity/application/get-subcontracted-activities-qry.test.ts +++ b/src/features/binnacle/features/activity/application/get-subcontracted-activities-qry.test.ts @@ -8,12 +8,13 @@ import { SubcontractedActivityRepository } from '../domain/subcontracted-activit import { SubcontractedActivitiesWithRoleInformation } from '../domain/services/subcontracted-activities-with-role-information' import { GetSubcontractedActivitiesQry } from './get-subcontracted-activities-qry' import { UserMother } from '../../../../../test-utils/mothers/user-mother' +import { GetSubcontractedActivitiesQueryParams } from '../domain/get-subcontracted-activities-query-params' describe('GetSubcontractedActivitiesQry', () => { it('should return subcontracted activities sorted by the given interval', async () => { - const { getSubcontractedActivitiesQry, interval, subcontractedActivities } = setup() + const { getSubcontractedActivitiesQry, params, subcontractedActivities } = setup() - const result = await getSubcontractedActivitiesQry.internalExecute(interval) + const result = await getSubcontractedActivitiesQry.internalExecute(params) expect(result).toEqual(subcontractedActivities) }) @@ -24,9 +25,10 @@ function setup() { const searchProjectRolesQry = mock() const getUserLoggedQry = mock() - const interval = { - start: new Date('2024-05'), - end: new Date('2024-07') + const params: GetSubcontractedActivitiesQueryParams = { + startDate: '2024-05-01', + endDate: '2024-07-30', + organizationId: 1 } const user = UserMother.userWithoutRoles() @@ -36,9 +38,7 @@ function setup() { SubcontractedActivityMother.minutesActivityWithProjectRoleIdA(), SubcontractedActivityMother.minutesBillableActivityWithProjectRoleId() ] - subcontractedActivityRepository.getAll - .calledWith(interval, 1) - .mockResolvedValue(activitiesResponse) + subcontractedActivityRepository.getAll.calledWith(params).mockResolvedValue(activitiesResponse) const projectRolesInformation = SearchMother.roles() searchProjectRolesQry.execute.mockResolvedValue(projectRolesInformation) @@ -52,12 +52,11 @@ function setup() { getSubcontractedActivitiesQry: new GetSubcontractedActivitiesQry( subcontractedActivityRepository, searchProjectRolesQry, - new SubcontractedActivitiesWithRoleInformation(), - getUserLoggedQry + new SubcontractedActivitiesWithRoleInformation() ), subcontractedActivityRepository, searchProjectRolesQry, - interval, + params, subcontractedActivities } } diff --git a/src/features/binnacle/features/activity/infrastructure/http-subcontracted-activity-repository.test.ts b/src/features/binnacle/features/activity/infrastructure/http-subcontracted-activity-repository.test.ts index 8027cf7f..40d8e4b4 100644 --- a/src/features/binnacle/features/activity/infrastructure/http-subcontracted-activity-repository.test.ts +++ b/src/features/binnacle/features/activity/infrastructure/http-subcontracted-activity-repository.test.ts @@ -1,21 +1,20 @@ import { mock } from 'jest-mock-extended' import { HttpClient } from '../../../../../shared/http/http-client' -import { DateInterval } from '../../../../../shared/types/date-interval' -import { chrono } from '../../../../../shared/utils/chrono' import { SubcontractedActivityMother } from '../../../../../test-utils/mothers/subcontracted-activity-mother' import { SubcontractedActivityWithProjectRoleIdMapper } from './subcontracted-activity-with-project-role-id-mapper' import { HttpSubcontractedActivityRepository } from './http-subcontracted-activity-repository' import { NewSubcontractedActivityDto } from './new-subcontracted-activity-dto' import { SubcontractedActivityWithProjectRoleId } from '../domain/subcontracted-activity-with-project-role-id' +import { GetSubcontractedActivitiesQueryParams } from '../domain/get-subcontracted-activities-query-params' describe('HttpSubcontractedActivityRepository', () => { it('should call http client for all activities', async () => { const { httpClient, httpSubcontractedActivityRepository } = setup() - const interval: DateInterval = { - start: new Date('2023-03-23T00:00:00.000Z'), - end: new Date('2023-03-30T00:00:00.000Z') + const params: GetSubcontractedActivitiesQueryParams = { + startDate: '2024-05-01', + endDate: '2024-07-30', + organizationId: 1 } - const userId = 1 const response = SubcontractedActivityMother.subcontractedActivitiesSerialized().map((x) => SubcontractedActivityWithProjectRoleIdMapper.toDomain(x) ) @@ -23,7 +22,7 @@ describe('HttpSubcontractedActivityRepository', () => { SubcontractedActivityMother.subcontractedActivitiesSerialized() ) - const result = await httpSubcontractedActivityRepository.getAll(interval, userId) + const result = await httpSubcontractedActivityRepository.getAll(params) const resultInMinutes = result.map((element) => { const r: SubcontractedActivityWithProjectRoleId = { ...element, @@ -32,11 +31,7 @@ describe('HttpSubcontractedActivityRepository', () => { return r }) expect(httpClient.get).toHaveBeenCalledWith('/api/subcontracted-activity', { - params: { - startDate: chrono(interval.start).format(chrono.DATE_FORMAT), - endDate: chrono(interval.end).format(chrono.DATE_FORMAT), - userId - } + params }) expect(resultInMinutes).toEqual(response) }) diff --git a/src/features/binnacle/features/activity/ui/components/subcontracted-activities-list/components/activity-filter/subcontracted-activity-filter-form.test.tsx b/src/features/binnacle/features/activity/ui/components/subcontracted-activities-list/components/activity-filter/subcontracted-activity-filter-form.test.tsx index 3e9df685..567d8e18 100644 --- a/src/features/binnacle/features/activity/ui/components/subcontracted-activities-list/components/activity-filter/subcontracted-activity-filter-form.test.tsx +++ b/src/features/binnacle/features/activity/ui/components/subcontracted-activities-list/components/activity-filter/subcontracted-activity-filter-form.test.tsx @@ -1,5 +1,4 @@ import { SubcontractedActivityFilterForm } from './subcontracted-activity-filter-form' -import { chrono } from '../../../../../../../../../shared/utils/chrono' import { render, screen, @@ -8,14 +7,15 @@ import { fireEvent, userEvent } from '../../../../../../../../../test-utils/render' +import { GetSubcontractedActivitiesQueryParams } from '../../../../../domain/get-subcontracted-activities-query-params' describe('SubcontractedActivityFilterForm', () => { it('should set default form values', () => { setup() const startDate = screen.getByLabelText('subcontracted_activity_form.start_date') const endDate = screen.getByLabelText('subcontracted_activity_form.end_date') - expect(startDate).toHaveValue('2024-02') - expect(endDate).toHaveValue('2024-04') + expect(startDate).toHaveValue('2024-03') + expect(endDate).toHaveValue('2024-07') }) it('should call onFiltersChange when there is a change', async () => { @@ -30,10 +30,11 @@ describe('SubcontractedActivityFilterForm', () => { expect(onFiltersChangeSpy).toHaveBeenCalledTimes(1) }) - expect(onFiltersChangeSpy).toHaveBeenCalledWith( - chrono('2024-04-01').getDate(), - chrono('2024-04-01').getDate() - ) + expect(onFiltersChangeSpy).toHaveBeenCalledWith({ + startDate: '2024-04-01', + endDate: '2024-07-31', + organizationId: undefined + }) }) it('should show error when startDate is greater than endDate', async () => { @@ -86,9 +87,10 @@ describe('SubcontractedActivityFilterForm', () => { }) function setup() { - const filters = { - start: new Date('2024-02-01'), - end: new Date('2024-04-01') + const filters: GetSubcontractedActivitiesQueryParams = { + startDate: '2024-03-01', + endDate: '2024-07-31', + organizationId: 1 } const onFiltersChangeSpy = jest.fn()