From bc1fb522110d2ca8895fd9e453b7d57a1fe5dea1 Mon Sep 17 00:00:00 2001 From: Martin Trajanovski Date: Tue, 21 Jun 2022 16:44:03 +0200 Subject: [PATCH 1/3] feat: Add call activate/deactivate button --- src/components/call/CallsTable.tsx | 52 ++++++++++++++++++++++++-- src/generated/sdk.ts | 19 ++++++---- src/graphql/call/fragment.call.graphql | 3 +- src/graphql/call/updateCall.graphql | 2 + 4 files changed, 63 insertions(+), 13 deletions(-) diff --git a/src/components/call/CallsTable.tsx b/src/components/call/CallsTable.tsx index fae2ffa60..c59e2798a 100644 --- a/src/components/call/CallsTable.tsx +++ b/src/components/call/CallsTable.tsx @@ -1,3 +1,5 @@ +import Archive from '@mui/icons-material/Archive'; +import Unarchive from '@mui/icons-material/Unarchive'; import { Typography } from '@mui/material'; import React, { useState } from 'react'; import { useQueryParams } from 'use-query-params'; @@ -9,12 +11,18 @@ import SuperMaterialTable, { DefaultQueryParams, UrlQueryParamsType, } from 'components/common/SuperMaterialTable'; -import { Call, InstrumentWithAvailabilityTime, UserRole } from 'generated/sdk'; +import { + Call, + InstrumentWithAvailabilityTime, + UserRole, + UpdateCallInput, +} from 'generated/sdk'; import { useFormattedDateTime } from 'hooks/admin/useFormattedDateTime'; import { useCallsData } from 'hooks/call/useCallsData'; import { tableIcons } from 'utils/materialIcons'; import useDataApiWithFeedback from 'utils/useDataApiWithFeedback'; import { FunctionType } from 'utils/utilTypes'; +import withConfirm, { WithConfirmProps } from 'utils/withConfirm'; import AssignedInstrumentsTable from './AssignedInstrumentsTable'; import AssignInstrumentsToCall from './AssignInstrumentsToCall'; @@ -30,7 +38,7 @@ const getFilterStatus = (callStatus: string | CallStatus) => ? undefined // if set to ALL we don't filter by status : callStatus === CallStatus.ACTIVE; -const CallsTable: React.FC = () => { +const CallsTable: React.FC = ({ confirm }) => { const { api } = useDataApiWithFeedback(); const { timezone, toFormattedDateTime } = useFormattedDateTime({ shouldUseTimeZone: true, @@ -120,6 +128,35 @@ const CallsTable: React.FC = () => { } }; + const changeCallActiveStatus = (call: Call) => { + const shouldActivateCall = !call.isActive; + confirm( + async () => { + const data = await api({ + toastSuccessMessage: `Call ${ + shouldActivateCall ? 'activated' : 'deactivated' + } successfully`, + }).updateCall({ + ...call, + isActive: shouldActivateCall, + } as UpdateCallInput); + + if (!data.updateCall.rejection) { + const newCallsArray = calls.filter( + (objectItem) => objectItem.id !== call.id + ); + setCalls(newCallsArray); + } + }, + { + title: `${shouldActivateCall ? 'Activate' : 'Deactivate'} call`, + description: `Are you sure you want to ${ + shouldActivateCall ? 'activate' : 'deactivate' + } this call?`, + } + )(); + }; + const deleteCall = async (id: number | string) => { return await api({ toastSuccessMessage: 'Call deleted successfully' }) .deleteCall({ @@ -247,7 +284,8 @@ const CallsTable: React.FC = () => { setData={setCalls} delete={deleteCall} hasAccess={{ - create: isUserOfficer, + create: + isUserOfficer && urlQueryParams.callStatus !== CallStatus.INACTIVE, update: isUserOfficer, remove: isUserOfficer, }} @@ -277,6 +315,12 @@ const CallsTable: React.FC = () => { setAssigningInstrumentsCallId((rowData as Call).id), position: 'row', }, + (rowData) => ({ + icon: rowData.isActive ? Archive : Unarchive, + tooltip: `${rowData.isActive ? 'Deactivate' : 'Activate'} call`, + onClick: (): void => changeCallActiveStatus(rowData as Call), + position: 'row', + }), ]} urlQueryParams={urlQueryParams} setUrlQueryParams={setUrlQueryParams} @@ -285,4 +329,4 @@ const CallsTable: React.FC = () => { ); }; -export default CallsTable; +export default withConfirm(CallsTable); diff --git a/src/generated/sdk.ts b/src/generated/sdk.ts index 77d17e36b..c3014744c 100644 --- a/src/generated/sdk.ts +++ b/src/generated/sdk.ts @@ -3087,6 +3087,7 @@ export type UpdateCallInput = { endSEPReview?: InputMaybe; esiTemplateId?: InputMaybe; id: Scalars['Int']; + isActive?: InputMaybe; proposalSequence?: InputMaybe; proposalWorkflowId: Scalars['Int']; referenceNumberFormat?: InputMaybe; @@ -3603,7 +3604,7 @@ export type CreateCallMutationVariables = Exact<{ }>; -export type CreateCallMutation = { createCall: { rejection: { reason: string, context: string | null, exception: string | null } | null, call: { id: number, shortCode: string, startCall: any, endCall: any, startReview: any, endReview: any, startSEPReview: any | null, endSEPReview: any | null, startNotify: any, endNotify: any, startCycle: any, endCycle: any, cycleComment: string, surveyComment: string, referenceNumberFormat: string | null, proposalWorkflowId: number | null, templateId: number, esiTemplateId: number | null, allocationTimeUnit: AllocationTimeUnits, proposalCount: number, title: string | null, description: string | null, submissionMessage: string | null, instruments: Array<{ id: number, name: string, shortCode: string, description: string, availabilityTime: number | null, submitted: boolean | null, scientists: Array<{ id: number, firstname: string, lastname: string, preferredname: string | null, organisation: string, organizationId: number, position: string, created: any | null, placeholder: boolean | null }> }>, proposalWorkflow: { id: number, name: string, description: string } | null, template: { templateId: number, name: string, isArchived: boolean } } | null } }; +export type CreateCallMutation = { createCall: { rejection: { reason: string, context: string | null, exception: string | null } | null, call: { id: number, shortCode: string, startCall: any, endCall: any, startReview: any, endReview: any, startSEPReview: any | null, endSEPReview: any | null, startNotify: any, endNotify: any, startCycle: any, endCycle: any, cycleComment: string, surveyComment: string, referenceNumberFormat: string | null, proposalWorkflowId: number | null, templateId: number, esiTemplateId: number | null, allocationTimeUnit: AllocationTimeUnits, proposalCount: number, title: string | null, description: string | null, submissionMessage: string | null, isActive: boolean, instruments: Array<{ id: number, name: string, shortCode: string, description: string, availabilityTime: number | null, submitted: boolean | null, scientists: Array<{ id: number, firstname: string, lastname: string, preferredname: string | null, organisation: string, organizationId: number, position: string, created: any | null, placeholder: boolean | null }> }>, proposalWorkflow: { id: number, name: string, description: string } | null, template: { templateId: number, name: string, isArchived: boolean } } | null } }; export type DeleteCallMutationVariables = Exact<{ id: Scalars['Int']; @@ -3612,28 +3613,28 @@ export type DeleteCallMutationVariables = Exact<{ export type DeleteCallMutation = { deleteCall: { rejection: { reason: string, context: string | null, exception: string | null } | null, call: { id: number } | null } }; -export type CallFragment = { id: number, shortCode: string, startCall: any, endCall: any, startReview: any, endReview: any, startSEPReview: any | null, endSEPReview: any | null, startNotify: any, endNotify: any, startCycle: any, endCycle: any, cycleComment: string, surveyComment: string, referenceNumberFormat: string | null, proposalWorkflowId: number | null, templateId: number, esiTemplateId: number | null, allocationTimeUnit: AllocationTimeUnits, proposalCount: number, title: string | null, description: string | null, submissionMessage: string | null, instruments: Array<{ id: number, name: string, shortCode: string, description: string, availabilityTime: number | null, submitted: boolean | null, scientists: Array<{ id: number, firstname: string, lastname: string, preferredname: string | null, organisation: string, organizationId: number, position: string, created: any | null, placeholder: boolean | null }> }>, proposalWorkflow: { id: number, name: string, description: string } | null, template: { templateId: number, name: string, isArchived: boolean } }; +export type CallFragment = { id: number, shortCode: string, startCall: any, endCall: any, startReview: any, endReview: any, startSEPReview: any | null, endSEPReview: any | null, startNotify: any, endNotify: any, startCycle: any, endCycle: any, cycleComment: string, surveyComment: string, referenceNumberFormat: string | null, proposalWorkflowId: number | null, templateId: number, esiTemplateId: number | null, allocationTimeUnit: AllocationTimeUnits, proposalCount: number, title: string | null, description: string | null, submissionMessage: string | null, isActive: boolean, instruments: Array<{ id: number, name: string, shortCode: string, description: string, availabilityTime: number | null, submitted: boolean | null, scientists: Array<{ id: number, firstname: string, lastname: string, preferredname: string | null, organisation: string, organizationId: number, position: string, created: any | null, placeholder: boolean | null }> }>, proposalWorkflow: { id: number, name: string, description: string } | null, template: { templateId: number, name: string, isArchived: boolean } }; export type GetCallQueryVariables = Exact<{ id: Scalars['Int']; }>; -export type GetCallQuery = { call: { id: number, shortCode: string, startCall: any, endCall: any, startReview: any, endReview: any, startSEPReview: any | null, endSEPReview: any | null, startNotify: any, endNotify: any, startCycle: any, endCycle: any, cycleComment: string, surveyComment: string, referenceNumberFormat: string | null, proposalWorkflowId: number | null, templateId: number, esiTemplateId: number | null, allocationTimeUnit: AllocationTimeUnits, proposalCount: number, title: string | null, description: string | null, submissionMessage: string | null, instruments: Array<{ id: number, name: string, shortCode: string, description: string, availabilityTime: number | null, submitted: boolean | null, scientists: Array<{ id: number, firstname: string, lastname: string, preferredname: string | null, organisation: string, organizationId: number, position: string, created: any | null, placeholder: boolean | null }> }>, proposalWorkflow: { id: number, name: string, description: string } | null, template: { templateId: number, name: string, isArchived: boolean } } | null }; +export type GetCallQuery = { call: { id: number, shortCode: string, startCall: any, endCall: any, startReview: any, endReview: any, startSEPReview: any | null, endSEPReview: any | null, startNotify: any, endNotify: any, startCycle: any, endCycle: any, cycleComment: string, surveyComment: string, referenceNumberFormat: string | null, proposalWorkflowId: number | null, templateId: number, esiTemplateId: number | null, allocationTimeUnit: AllocationTimeUnits, proposalCount: number, title: string | null, description: string | null, submissionMessage: string | null, isActive: boolean, instruments: Array<{ id: number, name: string, shortCode: string, description: string, availabilityTime: number | null, submitted: boolean | null, scientists: Array<{ id: number, firstname: string, lastname: string, preferredname: string | null, organisation: string, organizationId: number, position: string, created: any | null, placeholder: boolean | null }> }>, proposalWorkflow: { id: number, name: string, description: string } | null, template: { templateId: number, name: string, isArchived: boolean } } | null }; export type GetCallsQueryVariables = Exact<{ filter?: InputMaybe; }>; -export type GetCallsQuery = { calls: Array<{ id: number, shortCode: string, startCall: any, endCall: any, startReview: any, endReview: any, startSEPReview: any | null, endSEPReview: any | null, startNotify: any, endNotify: any, startCycle: any, endCycle: any, cycleComment: string, surveyComment: string, referenceNumberFormat: string | null, proposalWorkflowId: number | null, templateId: number, esiTemplateId: number | null, allocationTimeUnit: AllocationTimeUnits, proposalCount: number, title: string | null, description: string | null, submissionMessage: string | null, instruments: Array<{ id: number, name: string, shortCode: string, description: string, availabilityTime: number | null, submitted: boolean | null, scientists: Array<{ id: number, firstname: string, lastname: string, preferredname: string | null, organisation: string, organizationId: number, position: string, created: any | null, placeholder: boolean | null }> }>, proposalWorkflow: { id: number, name: string, description: string } | null, template: { templateId: number, name: string, isArchived: boolean } }> | null }; +export type GetCallsQuery = { calls: Array<{ id: number, shortCode: string, startCall: any, endCall: any, startReview: any, endReview: any, startSEPReview: any | null, endSEPReview: any | null, startNotify: any, endNotify: any, startCycle: any, endCycle: any, cycleComment: string, surveyComment: string, referenceNumberFormat: string | null, proposalWorkflowId: number | null, templateId: number, esiTemplateId: number | null, allocationTimeUnit: AllocationTimeUnits, proposalCount: number, title: string | null, description: string | null, submissionMessage: string | null, isActive: boolean, instruments: Array<{ id: number, name: string, shortCode: string, description: string, availabilityTime: number | null, submitted: boolean | null, scientists: Array<{ id: number, firstname: string, lastname: string, preferredname: string | null, organisation: string, organizationId: number, position: string, created: any | null, placeholder: boolean | null }> }>, proposalWorkflow: { id: number, name: string, description: string } | null, template: { templateId: number, name: string, isArchived: boolean } }> | null }; export type GetCallsByInstrumentScientistQueryVariables = Exact<{ scientistId: Scalars['Int']; }>; -export type GetCallsByInstrumentScientistQuery = { callsByInstrumentScientist: Array<{ id: number, shortCode: string, startCall: any, endCall: any, startReview: any, endReview: any, startSEPReview: any | null, endSEPReview: any | null, startNotify: any, endNotify: any, startCycle: any, endCycle: any, cycleComment: string, surveyComment: string, referenceNumberFormat: string | null, proposalWorkflowId: number | null, templateId: number, esiTemplateId: number | null, allocationTimeUnit: AllocationTimeUnits, proposalCount: number, title: string | null, description: string | null, submissionMessage: string | null, instruments: Array<{ id: number, name: string, shortCode: string, description: string, availabilityTime: number | null, submitted: boolean | null, scientists: Array<{ id: number, firstname: string, lastname: string, preferredname: string | null, organisation: string, organizationId: number, position: string, created: any | null, placeholder: boolean | null }> }>, proposalWorkflow: { id: number, name: string, description: string } | null, template: { templateId: number, name: string, isArchived: boolean } }> | null }; +export type GetCallsByInstrumentScientistQuery = { callsByInstrumentScientist: Array<{ id: number, shortCode: string, startCall: any, endCall: any, startReview: any, endReview: any, startSEPReview: any | null, endSEPReview: any | null, startNotify: any, endNotify: any, startCycle: any, endCycle: any, cycleComment: string, surveyComment: string, referenceNumberFormat: string | null, proposalWorkflowId: number | null, templateId: number, esiTemplateId: number | null, allocationTimeUnit: AllocationTimeUnits, proposalCount: number, title: string | null, description: string | null, submissionMessage: string | null, isActive: boolean, instruments: Array<{ id: number, name: string, shortCode: string, description: string, availabilityTime: number | null, submitted: boolean | null, scientists: Array<{ id: number, firstname: string, lastname: string, preferredname: string | null, organisation: string, organizationId: number, position: string, created: any | null, placeholder: boolean | null }> }>, proposalWorkflow: { id: number, name: string, description: string } | null, template: { templateId: number, name: string, isArchived: boolean } }> | null }; export type RemoveAssignedInstrumentFromCallMutationVariables = Exact<{ instrumentId: Scalars['Int']; @@ -3666,10 +3667,11 @@ export type UpdateCallMutationVariables = Exact<{ esiTemplateId?: InputMaybe; title?: InputMaybe; description?: InputMaybe; + isActive?: InputMaybe; }>; -export type UpdateCallMutation = { updateCall: { rejection: { reason: string, context: string | null, exception: string | null } | null, call: { id: number, shortCode: string, startCall: any, endCall: any, startReview: any, endReview: any, startSEPReview: any | null, endSEPReview: any | null, startNotify: any, endNotify: any, startCycle: any, endCycle: any, cycleComment: string, surveyComment: string, referenceNumberFormat: string | null, proposalWorkflowId: number | null, templateId: number, esiTemplateId: number | null, allocationTimeUnit: AllocationTimeUnits, proposalCount: number, title: string | null, description: string | null, submissionMessage: string | null, instruments: Array<{ id: number, name: string, shortCode: string, description: string, availabilityTime: number | null, submitted: boolean | null, scientists: Array<{ id: number, firstname: string, lastname: string, preferredname: string | null, organisation: string, organizationId: number, position: string, created: any | null, placeholder: boolean | null }> }>, proposalWorkflow: { id: number, name: string, description: string } | null, template: { templateId: number, name: string, isArchived: boolean } } | null } }; +export type UpdateCallMutation = { updateCall: { rejection: { reason: string, context: string | null, exception: string | null } | null, call: { id: number, shortCode: string, startCall: any, endCall: any, startReview: any, endReview: any, startSEPReview: any | null, endSEPReview: any | null, startNotify: any, endNotify: any, startCycle: any, endCycle: any, cycleComment: string, surveyComment: string, referenceNumberFormat: string | null, proposalWorkflowId: number | null, templateId: number, esiTemplateId: number | null, allocationTimeUnit: AllocationTimeUnits, proposalCount: number, title: string | null, description: string | null, submissionMessage: string | null, isActive: boolean, instruments: Array<{ id: number, name: string, shortCode: string, description: string, availabilityTime: number | null, submitted: boolean | null, scientists: Array<{ id: number, firstname: string, lastname: string, preferredname: string | null, organisation: string, organizationId: number, position: string, created: any | null, placeholder: boolean | null }> }>, proposalWorkflow: { id: number, name: string, description: string } | null, template: { templateId: number, name: string, isArchived: boolean } } | null } }; export type CreateEsiMutationVariables = Exact<{ scheduledEventId: Scalars['Int']; @@ -5175,6 +5177,7 @@ export const CallFragmentDoc = gql` title description submissionMessage + isActive } ${BasicUserDetailsFragmentDoc}`; export const EsiFragmentDoc = gql` @@ -6386,9 +6389,9 @@ export const RemoveAssignedInstrumentFromCallDocument = gql` } ${RejectionFragmentDoc}`; export const UpdateCallDocument = gql` - mutation updateCall($id: Int!, $shortCode: String!, $startCall: DateTime!, $endCall: DateTime!, $startReview: DateTime!, $endReview: DateTime!, $startSEPReview: DateTime, $endSEPReview: DateTime, $startNotify: DateTime!, $endNotify: DateTime!, $startCycle: DateTime!, $endCycle: DateTime!, $cycleComment: String!, $submissionMessage: String, $surveyComment: String!, $allocationTimeUnit: AllocationTimeUnits!, $referenceNumberFormat: String, $proposalWorkflowId: Int!, $templateId: Int!, $esiTemplateId: Int, $title: String, $description: String) { + mutation updateCall($id: Int!, $shortCode: String!, $startCall: DateTime!, $endCall: DateTime!, $startReview: DateTime!, $endReview: DateTime!, $startSEPReview: DateTime, $endSEPReview: DateTime, $startNotify: DateTime!, $endNotify: DateTime!, $startCycle: DateTime!, $endCycle: DateTime!, $cycleComment: String!, $submissionMessage: String, $surveyComment: String!, $allocationTimeUnit: AllocationTimeUnits!, $referenceNumberFormat: String, $proposalWorkflowId: Int!, $templateId: Int!, $esiTemplateId: Int, $title: String, $description: String, $isActive: Boolean) { updateCall( - updateCallInput: {id: $id, shortCode: $shortCode, startCall: $startCall, endCall: $endCall, startReview: $startReview, endReview: $endReview, startSEPReview: $startSEPReview, endSEPReview: $endSEPReview, startNotify: $startNotify, endNotify: $endNotify, startCycle: $startCycle, endCycle: $endCycle, cycleComment: $cycleComment, submissionMessage: $submissionMessage, surveyComment: $surveyComment, allocationTimeUnit: $allocationTimeUnit, referenceNumberFormat: $referenceNumberFormat, proposalWorkflowId: $proposalWorkflowId, templateId: $templateId, esiTemplateId: $esiTemplateId, title: $title, description: $description} + updateCallInput: {id: $id, shortCode: $shortCode, startCall: $startCall, endCall: $endCall, startReview: $startReview, endReview: $endReview, startSEPReview: $startSEPReview, endSEPReview: $endSEPReview, startNotify: $startNotify, endNotify: $endNotify, startCycle: $startCycle, endCycle: $endCycle, cycleComment: $cycleComment, submissionMessage: $submissionMessage, surveyComment: $surveyComment, allocationTimeUnit: $allocationTimeUnit, referenceNumberFormat: $referenceNumberFormat, proposalWorkflowId: $proposalWorkflowId, templateId: $templateId, esiTemplateId: $esiTemplateId, title: $title, description: $description, isActive: $isActive} ) { rejection { ...rejection diff --git a/src/graphql/call/fragment.call.graphql b/src/graphql/call/fragment.call.graphql index 77159aa0b..096a209a5 100644 --- a/src/graphql/call/fragment.call.graphql +++ b/src/graphql/call/fragment.call.graphql @@ -17,7 +17,7 @@ fragment call on Call { proposalWorkflowId templateId esiTemplateId - allocationTimeUnit + allocationTimeUnit instruments { id name @@ -43,4 +43,5 @@ fragment call on Call { title description submissionMessage + isActive } diff --git a/src/graphql/call/updateCall.graphql b/src/graphql/call/updateCall.graphql index 33cda0ba3..77b5e8ca2 100644 --- a/src/graphql/call/updateCall.graphql +++ b/src/graphql/call/updateCall.graphql @@ -21,6 +21,7 @@ mutation updateCall( $esiTemplateId: Int $title: String $description: String + $isActive: Boolean ) { updateCall( updateCallInput: { @@ -46,6 +47,7 @@ mutation updateCall( esiTemplateId: $esiTemplateId title: $title description: $description + isActive: $isActive } ) { rejection { From cd372cb39fb9f6d2c40a5bff141f39c32a009224 Mon Sep 17 00:00:00 2001 From: Martin Trajanovski Date: Wed, 22 Jun 2022 18:54:25 +0200 Subject: [PATCH 2/3] add e2e tests and fix the active call logic --- cypress/integration/calls.ts | 50 + cypress/integration/proposals.ts | 2 +- cypress/integration/templates.ts | 2494 ++++++++--------- src/components/DashBoard.tsx | 2 +- src/components/proposal/ProposalSummary.tsx | 17 +- src/components/proposal/ProposalTable.tsx | 9 +- .../proposal/ProposalQuestionaryWizardStep.ts | 12 +- src/generated/sdk.ts | 12 +- src/graphql/proposal/cloneProposals.graphql | 2 + src/graphql/proposal/getProposal.graphql | 2 + src/graphql/user/getUserProposals.graphql | 2 + .../proposal/ProposalWithQuestionary.ts | 6 +- src/utils/helperFunctions.ts | 18 +- 13 files changed, 1363 insertions(+), 1265 deletions(-) diff --git a/cypress/integration/calls.ts b/cypress/integration/calls.ts index 56d0a5a12..24571e5d5 100644 --- a/cypress/integration/calls.ts +++ b/cypress/integration/calls.ts @@ -5,6 +5,7 @@ import { AllocationTimeUnits, CreateInstrumentMutationVariables, TemplateGroupId, + UpdateCallInput, } from '../../src/generated/sdk'; import initialDBData from '../support/initialDBData'; @@ -443,6 +444,48 @@ context('Calls tests', () => { ); }); + it('A user-officer should be able to deactivate/activate a call', () => { + cy.contains('Calls').click(); + + cy.contains(newCall.shortCode) + .parent() + .find('[aria-label="Deactivate call"]') + .click(); + + cy.get('[data-cy="confirm-ok"]').click(); + cy.notification({ variant: 'success', text: 'successfully' }); + + cy.get('[data-cy="calls-table"]').should( + 'not.contain', + newCall.shortCode + ); + + cy.get('[data-cy="call-status-filter"]').click(); + cy.get('[role="listbox"]').contains('Inactive').click(); + + cy.finishedLoading(); + + cy.contains(newCall.shortCode) + .parent() + .find('[aria-label="Activate call"]') + .click(); + + cy.get('[data-cy="confirm-ok"]').click(); + cy.notification({ variant: 'success', text: 'successfully' }); + + cy.get('[data-cy="calls-table"]').should( + 'not.contain', + newCall.shortCode + ); + + cy.get('[data-cy="call-status-filter"]').click(); + cy.get('[role="listbox"]').contains('Active').click(); + + cy.finishedLoading(); + + cy.get('[data-cy="calls-table"]').should('contain', newCall.shortCode); + }); + it('A user-officer should not be able to set negative availability time on instrument per call', () => { cy.assignInstrumentToCall({ callId: createdCallId, @@ -555,6 +598,13 @@ context('Calls tests', () => { ...newInactiveCall, esiTemplateId: esiTemplateId, proposalWorkflowId: workflowId, + }).then((result) => { + if (result.createCall.call?.id) { + cy.updateCall({ + ...result.createCall.call, + isActive: false, + } as UpdateCallInput); + } }); cy.contains('Calls').click(); diff --git a/cypress/integration/proposals.ts b/cypress/integration/proposals.ts index 0edd3b666..be509e142 100644 --- a/cypress/integration/proposals.ts +++ b/cypress/integration/proposals.ts @@ -472,7 +472,7 @@ context('Proposal tests', () => { cy.contains(newProposalTitle).should('not.exist'); }); - it('User should not be able to create and submit proposal with inactive call', () => { + it('User should not be able to create and submit proposal on a call that is ended', () => { createTopicAndQuestionToExistingTemplate(); cy.login('user'); cy.visit('/'); diff --git a/cypress/integration/templates.ts b/cypress/integration/templates.ts index 9c904d0f4..7ade65756 100644 --- a/cypress/integration/templates.ts +++ b/cypress/integration/templates.ts @@ -346,928 +346,928 @@ context('Template tests', () => { }); describe('Proposal templates basic tests', () => { - // it('User officer can delete active template', () => { - // const newName = faker.lorem.words(3); - // const newDescription = faker.lorem.words(5); + it('User officer can delete active template', () => { + const newName = faker.lorem.words(3); + const newDescription = faker.lorem.words(5); - // cy.login('officer'); - // cy.visit('/'); + cy.login('officer'); + cy.visit('/'); - // cy.navigateToTemplatesSubmenu('Shipment declaration templates'); + cy.navigateToTemplatesSubmenu('Shipment declaration templates'); - // cy.get('[data-cy=create-new-button]').click(); + cy.get('[data-cy=create-new-button]').click(); - // cy.get('[data-cy=name] input').type(newName); - // cy.get('[data-cy=description]').type(newDescription); + cy.get('[data-cy=name] input').type(newName); + cy.get('[data-cy=description]').type(newDescription); - // cy.get('[data-cy=submit]').click(); + cy.get('[data-cy=submit]').click(); - // cy.visit('/'); - // cy.navigateToTemplatesSubmenu('Shipment declaration templates'); + cy.visit('/'); + cy.navigateToTemplatesSubmenu('Shipment declaration templates'); - // cy.get('[data-cy=mark-as-active]').click(); + cy.get('[data-cy=mark-as-active]').click(); - // cy.get('[data-cy=delete-template]').click(); + cy.get('[data-cy=delete-template]').click(); - // cy.get('[data-cy=confirm-ok]').click(); + cy.get('[data-cy=confirm-ok]').click(); - // cy.finishedLoading(); + cy.finishedLoading(); - // cy.contains(newName).should('not.exist'); - // }); + cy.contains(newName).should('not.exist'); + }); - // it('User officer can modify proposal template', () => { - // cy.login('officer'); - // cy.visit('/'); + it('User officer can modify proposal template', () => { + cy.login('officer'); + cy.visit('/'); - // cy.navigateToTemplatesSubmenu('Proposal'); + cy.navigateToTemplatesSubmenu('Proposal'); - // cy.contains(initialDBData.template.name) - // .parent() - // .find("[aria-label='Edit']") - // .first() - // .click(); + cy.contains(initialDBData.template.name) + .parent() + .find("[aria-label='Edit']") + .first() + .click(); - // /* Boolean */ + /* Boolean */ - // cy.createBooleanQuestion(booleanQuestion); + cy.createBooleanQuestion(booleanQuestion); - // cy.contains(booleanQuestion) - // .closest('[data-cy=question-container]') - // .find("[data-cy='proposal-question-id']") - // .invoke('html') - // .then((fieldId) => { - // boolId = fieldId; - // }); + cy.contains(booleanQuestion) + .closest('[data-cy=question-container]') + .find("[data-cy='proposal-question-id']") + .invoke('html') + .then((fieldId) => { + boolId = fieldId; + }); - // /* --- */ + /* --- */ - // /* Interval */ - // cy.createIntervalQuestion(intervalQuestion, { - // units: ['celsius', 'kelvin'], - // }); + /* Interval */ + cy.createIntervalQuestion(intervalQuestion, { + units: ['celsius', 'kelvin'], + }); - // cy.contains(intervalQuestion) - // .closest('[data-cy=question-container]') - // .find("[data-cy='proposal-question-id']") - // .invoke('html') - // .then((fieldId) => { - // intervalId = fieldId; - // }); + cy.contains(intervalQuestion) + .closest('[data-cy=question-container]') + .find("[data-cy='proposal-question-id']") + .invoke('html') + .then((fieldId) => { + intervalId = fieldId; + }); - // /* --- */ + /* --- */ - // /* Number */ + /* Number */ - // cy.createNumberInputQuestion(numberQuestion, { - // units: ['celsius', 'kelvin'], - // }); + cy.createNumberInputQuestion(numberQuestion, { + units: ['celsius', 'kelvin'], + }); - // cy.contains(numberQuestion) - // .closest('[data-cy=question-container]') - // .find("[data-cy='proposal-question-id']") - // .invoke('html') - // .then((fieldId) => { - // numberId = fieldId; - // }); + cy.contains(numberQuestion) + .closest('[data-cy=question-container]') + .find("[data-cy='proposal-question-id']") + .invoke('html') + .then((fieldId) => { + numberId = fieldId; + }); - // /* --- */ + /* --- */ + + /* Text input */ + cy.createTextQuestion(textQuestion.title, { + isRequired: true, + isMultipleLines: true, + maxCharacters: textQuestion.maxChars, + }); + + cy.contains(textQuestion.title) + .closest('[data-cy=question-container]') + .find("[data-cy='proposal-question-id']") + .invoke('html') + .then((fieldId) => { + textId = fieldId; + }); - // /* Text input */ - // cy.createTextQuestion(textQuestion.title, { - // isRequired: true, - // isMultipleLines: true, - // maxCharacters: textQuestion.maxChars, - // }); + /* Update question */ - // cy.contains(textQuestion.title) - // .closest('[data-cy=question-container]') - // .find("[data-cy='proposal-question-id']") - // .invoke('html') - // .then((fieldId) => { - // textId = fieldId; - // }); + cy.contains(textQuestion.title).click(); - // /* Update question */ + cy.get('[data-cy="natural-key"]').click(); - // cy.contains(textQuestion.title).click(); + cy.get("[data-cy='natural_key']").clear().type(textQuestion.newId); - // cy.get('[data-cy="natural-key"]').click(); + cy.contains('Save').click(); - // cy.get("[data-cy='natural_key']").clear().type(textQuestion.newId); + cy.contains(textQuestion.newId); + /* --- */ - // cy.contains('Save').click(); + cy.contains(textQuestion.title).click(); - // cy.contains(textQuestion.newId); - // /* --- */ + // Updating dependencies + cy.get('[data-cy="add-dependency-button"]').click(); + cy.get('#dependency-id').click(); + cy.get('[data-cy=question-relation-dialogue]') + .get('#menu- > .MuiPaper-root > .MuiList-root > [tabindex="0"]') + .click(); // get boolean question - // cy.contains(textQuestion.title).click(); + cy.get('#dependencyValue').click(); + cy.get('[data-cy=question-relation-dialogue]') + .get("#menu- > .MuiPaper-root > .MuiList-root > [tabindex='0']") + .click(); // get true from dropdown - // // Updating dependencies - // cy.get('[data-cy="add-dependency-button"]').click(); - // cy.get('#dependency-id').click(); - // cy.get('[data-cy=question-relation-dialogue]') - // .get('#menu- > .MuiPaper-root > .MuiList-root > [tabindex="0"]') - // .click(); // get boolean question - - // cy.get('#dependencyValue').click(); - // cy.get('[data-cy=question-relation-dialogue]') - // .get("#menu- > .MuiPaper-root > .MuiList-root > [tabindex='0']") - // .click(); // get true from dropdown - - // cy.contains('Update').click(); - - // // Check reordering - // cy.contains(textQuestion.title) - // .parent() - // .dragElement([{ direction: 'up', length: 1 }]); // Move item to top, in case it isn't + cy.contains('Update').click(); - // cy.contains(initialDBData.template.topic.title) - // .closest('[data-rbd-draggable-context-id]') // new topic column - // .find('[data-rbd-drag-handle-draggable-id]') // all questions - // .first() // first question - // .contains(textQuestion.title); + // Check reordering + cy.contains(textQuestion.title) + .parent() + .dragElement([{ direction: 'up', length: 1 }]); // Move item to top, in case it isn't - // cy.contains(textQuestion.title) - // .parent() - // .dragElement([{ direction: 'down', length: 1 }]); - - // cy.contains(initialDBData.template.topic.title) - // .closest('[data-rbd-draggable-context-id]') // new topic column - // .find('[data-rbd-drag-handle-draggable-id]') // all questions - // .first() // first question - // .should('not.contain', textQuestion); + cy.contains(initialDBData.template.topic.title) + .closest('[data-rbd-draggable-context-id]') // new topic column + .find('[data-rbd-drag-handle-draggable-id]') // all questions + .first() // first question + .contains(textQuestion.title); - // /* Selection from options */ - // cy.createMultipleChoiceQuestion(multipleChoiceQuestion.title, { - // option1: multipleChoiceQuestion.answers[0], - // option2: multipleChoiceQuestion.answers[1], - // option3: multipleChoiceQuestion.answers[2], - // isMultipleSelect: true, - // }); + cy.contains(textQuestion.title) + .parent() + .dragElement([{ direction: 'down', length: 1 }]); + + cy.contains(initialDBData.template.topic.title) + .closest('[data-rbd-draggable-context-id]') // new topic column + .find('[data-rbd-drag-handle-draggable-id]') // all questions + .first() // first question + .should('not.contain', textQuestion); + + /* Selection from options */ + cy.createMultipleChoiceQuestion(multipleChoiceQuestion.title, { + option1: multipleChoiceQuestion.answers[0], + option2: multipleChoiceQuestion.answers[1], + option3: multipleChoiceQuestion.answers[2], + isMultipleSelect: true, + }); + + cy.contains(multipleChoiceQuestion.title) + .closest('[data-cy=question-container]') + .find("[data-cy='proposal-question-id']") + .invoke('html') + .then((fieldId) => { + multipleChoiceId = fieldId; + }); - // cy.contains(multipleChoiceQuestion.title) - // .closest('[data-cy=question-container]') - // .find("[data-cy='proposal-question-id']") - // .invoke('html') - // .then((fieldId) => { - // multipleChoiceId = fieldId; - // }); + cy.finishedLoading(); - // cy.finishedLoading(); + cy.contains(multipleChoiceQuestion.title).click(); - // cy.contains(multipleChoiceQuestion.title).click(); - - // cy.get('[data-cy=natural-key]').click(); - - // cy.get('[index=0]').should( - // 'not.contain', - // multipleChoiceQuestion.answers[1] - // ); + cy.get('[data-cy=natural-key]').click(); - // cy.contains(multipleChoiceQuestion.answers[1]) - // .parent() - // .find('[aria-label=Up]') - // .click(); + cy.get('[index=0]').should( + 'not.contain', + multipleChoiceQuestion.answers[1] + ); - // cy.get('[index=0]').contains(multipleChoiceQuestion.answers[1]); + cy.contains(multipleChoiceQuestion.answers[1]) + .parent() + .find('[aria-label=Up]') + .click(); - // cy.contains(multipleChoiceQuestion.answers[1]) - // .parent() - // .find('[aria-label=Down]') - // .click(); + cy.get('[index=0]').contains(multipleChoiceQuestion.answers[1]); - // cy.contains('Save').click(); + cy.contains(multipleChoiceQuestion.answers[1]) + .parent() + .find('[aria-label=Down]') + .click(); - // /* --- */ + cy.contains('Save').click(); - // /* Date */ - // cy.createDateQuestion(dateQuestion.title, { - // includeTime: false, - // isRequired: true, - // }); + /* --- */ - // cy.contains(dateQuestion.title) - // .closest('[data-cy=question-container]') - // .find("[data-cy='proposal-question-id']") - // .invoke('html') - // .then((fieldId) => { - // dateId = fieldId; - // }); + /* Date */ + cy.createDateQuestion(dateQuestion.title, { + includeTime: false, + isRequired: true, + }); - // cy.createDateQuestion(timeQuestion, { - // includeTime: true, - // isRequired: false, - // }); + cy.contains(dateQuestion.title) + .closest('[data-cy=question-container]') + .find("[data-cy='proposal-question-id']") + .invoke('html') + .then((fieldId) => { + dateId = fieldId; + }); - // cy.contains(timeQuestion) - // .closest('[data-cy=question-container]') - // .find("[data-cy='proposal-question-id']") - // .invoke('html') - // .then((fieldId) => { - // timeId = fieldId; - // }); + cy.createDateQuestion(timeQuestion, { + includeTime: true, + isRequired: false, + }); + + cy.contains(timeQuestion) + .closest('[data-cy=question-container]') + .find("[data-cy='proposal-question-id']") + .invoke('html') + .then((fieldId) => { + timeId = fieldId; + }); - // /* --- */ + /* --- */ - // /* File */ + /* File */ - // cy.createFileUploadQuestion(fileQuestion, ['.pdf', 'image/*']); + cy.createFileUploadQuestion(fileQuestion, ['.pdf', 'image/*']); - // /* --- */ + /* --- */ - // /* Rich Text Input */ + /* Rich Text Input */ - // cy.createRichTextInput(richTextInputQuestion.title, { - // maxChars: richTextInputQuestion.maxChars, - // }); + cy.createRichTextInput(richTextInputQuestion.title, { + maxChars: richTextInputQuestion.maxChars, + }); - // cy.contains(richTextInputQuestion.title); + cy.contains(richTextInputQuestion.title); - // cy.contains(richTextInputQuestion.title) - // .closest('[data-cy=question-container]') - // .find("[data-cy='proposal-question-id']") - // .invoke('html') - // .then((fieldId) => { - // richTextInputId = fieldId; - // }); + cy.contains(richTextInputQuestion.title) + .closest('[data-cy=question-container]') + .find("[data-cy='proposal-question-id']") + .invoke('html') + .then((fieldId) => { + richTextInputId = fieldId; + }); - // /* --- */ + /* --- */ - // /* --- Update templateQuestionRelation */ - // cy.contains(dateQuestion.title).click(); - // cy.get("[data-cy='tooltip'] input").clear().type(dateQuestion.tooltip); + /* --- Update templateQuestionRelation */ + cy.contains(dateQuestion.title).click(); + cy.get("[data-cy='tooltip'] input").clear().type(dateQuestion.tooltip); - // cy.contains('Update').click(); + cy.contains('Update').click(); - // cy.reload(); + cy.reload(); - // cy.contains(dateQuestion.title).click(); - // cy.get("[data-cy='tooltip'] input").should( - // 'have.value', - // dateQuestion.tooltip - // ); - // cy.get('body').type('{esc}'); - // /* --- */ + cy.contains(dateQuestion.title).click(); + cy.get("[data-cy='tooltip'] input").should( + 'have.value', + dateQuestion.tooltip + ); + cy.get('body').type('{esc}'); + /* --- */ - // cy.contains(booleanQuestion); - // cy.contains(textQuestion.title); - // cy.contains(dateQuestion.title); - // cy.contains(timeQuestion); - // }); + cy.contains(booleanQuestion); + cy.contains(textQuestion.title); + cy.contains(dateQuestion.title); + cy.contains(timeQuestion); + }); - // it('User officer can change template title and description', () => { - // const newName = faker.lorem.words(3); - // const newDescription = faker.lorem.words(5); + it('User officer can change template title and description', () => { + const newName = faker.lorem.words(3); + const newDescription = faker.lorem.words(5); - // cy.login('officer'); - // cy.visit('/'); + cy.login('officer'); + cy.visit('/'); - // cy.navigateToTemplatesSubmenu('Proposal'); + cy.navigateToTemplatesSubmenu('Proposal'); - // cy.contains(initialDBData.template.name) - // .parent() - // .find("[aria-label='Edit']") - // .first() - // .click(); + cy.contains(initialDBData.template.name) + .parent() + .find("[aria-label='Edit']") + .first() + .click(); - // cy.get('[data-cy=edit-metadata]').click(); - // cy.get('[data-cy=template-name] input').clear().type(newName); - // cy.get('[data-cy=template-description] input') - // .clear() - // .type(newDescription); + cy.get('[data-cy=edit-metadata]').click(); + cy.get('[data-cy=template-name] input').clear().type(newName); + cy.get('[data-cy=template-description] input') + .clear() + .type(newDescription); - // cy.get('[data-cy="save-metadata-btn"]').click(); + cy.get('[data-cy="save-metadata-btn"]').click(); - // cy.finishedLoading(); - - // cy.contains(newName); - // cy.contains(newDescription); - // }); + cy.finishedLoading(); - // it('User officer can clone template', () => { - // cy.login('officer'); - // cy.visit('/'); - - // cy.navigateToTemplatesSubmenu('Proposal'); + cy.contains(newName); + cy.contains(newDescription); + }); - // cy.contains(initialDBData.template.name) - // .parent() - // .find("[aria-label='Clone']") - // .first() - // .click(); + it('User officer can clone template', () => { + cy.login('officer'); + cy.visit('/'); - // cy.contains('Yes').click(); + cy.navigateToTemplatesSubmenu('Proposal'); - // cy.contains(`Copy of ${initialDBData.template.name}`); - // }); + cy.contains(initialDBData.template.name) + .parent() + .find("[aria-label='Clone']") + .first() + .click(); - // it('User officer can delete template', () => { - // cy.cloneTemplate({ templateId: initialDBData.template.id }); - // cy.login('officer'); - // cy.visit('/'); + cy.contains('Yes').click(); - // cy.navigateToTemplatesSubmenu('Proposal'); + cy.contains(`Copy of ${initialDBData.template.name}`); + }); - // cy.contains(`Copy of ${initialDBData.template.name}`) - // .parent() - // .find("[aria-label='Delete']") - // .first() - // .click(); + it('User officer can delete template', () => { + cy.cloneTemplate({ templateId: initialDBData.template.id }); + cy.login('officer'); + cy.visit('/'); - // cy.contains('Yes').click(); + cy.navigateToTemplatesSubmenu('Proposal'); - // cy.contains(`Copy of ${initialDBData.template.name}`).should('not.exist'); - // }); + cy.contains(`Copy of ${initialDBData.template.name}`) + .parent() + .find("[aria-label='Delete']") + .first() + .click(); - // it('User officer archive and unarchive template', () => { - // cy.login('officer'); - // cy.visit('/'); + cy.contains('Yes').click(); - // cy.navigateToTemplatesSubmenu('Proposal'); + cy.contains(`Copy of ${initialDBData.template.name}`).should('not.exist'); + }); - // cy.contains(initialDBData.template.name) - // .parent() - // .find("[aria-label='Archive']") - // .first() - // .click(); + it('User officer archive and unarchive template', () => { + cy.login('officer'); + cy.visit('/'); - // cy.contains('Yes').click(); + cy.navigateToTemplatesSubmenu('Proposal'); - // cy.notification({ variant: 'success', text: 'successfully' }); + cy.contains(initialDBData.template.name) + .parent() + .find("[aria-label='Archive']") + .first() + .click(); - // cy.contains(initialDBData.template.name).should('not.exist'); + cy.contains('Yes').click(); - // cy.contains('Archived').click(); + cy.notification({ variant: 'success', text: 'successfully' }); - // cy.contains(initialDBData.template.name); + cy.contains(initialDBData.template.name).should('not.exist'); - // cy.contains(initialDBData.template.name) - // .parent() - // .find("[aria-label='Unarchive']") - // .first() - // .click(); + cy.contains('Archived').click(); - // cy.contains('Yes').click(); - // }); + cy.contains(initialDBData.template.name); - // it('should render the Date field with default value and min max values when set', () => { - // let dateFieldId: string; - // const minDate = DateTime.fromJSDate(faker.date.past()).toFormat( - // initialDBData.getFormats().dateFormat - // ); - // const earlierThanMinDate = DateTime.fromFormat( - // minDate, - // initialDBData.getFormats().dateFormat - // ) - // .minus({ day: 1 }) - // .toFormat(initialDBData.getFormats().dateFormat); - // const maxDate = DateTime.fromJSDate(faker.date.future()).toFormat( - // initialDBData.getFormats().dateFormat - // ); - // const laterThanMaxDate = DateTime.fromFormat( - // maxDate, - // initialDBData.getFormats().dateFormat - // ) - // .plus({ day: 1 }) - // .toFormat(initialDBData.getFormats().dateFormat); - // const defaultDate = DateTime.now().toFormat( - // initialDBData.getFormats().dateFormat - // ); + cy.contains(initialDBData.template.name) + .parent() + .find("[aria-label='Unarchive']") + .first() + .click(); - // const tomorrowDate = DateTime.now() - // .plus({ day: 1 }) - // .toFormat(initialDBData.getFormats().dateFormat); + cy.contains('Yes').click(); + }); - // cy.login('officer'); - // cy.visit('/'); + it('should render the Date field with default value and min max values when set', () => { + let dateFieldId: string; + const minDate = DateTime.fromJSDate(faker.date.past()).toFormat( + initialDBData.getFormats().dateFormat + ); + const earlierThanMinDate = DateTime.fromFormat( + minDate, + initialDBData.getFormats().dateFormat + ) + .minus({ day: 1 }) + .toFormat(initialDBData.getFormats().dateFormat); + const maxDate = DateTime.fromJSDate(faker.date.future()).toFormat( + initialDBData.getFormats().dateFormat + ); + const laterThanMaxDate = DateTime.fromFormat( + maxDate, + initialDBData.getFormats().dateFormat + ) + .plus({ day: 1 }) + .toFormat(initialDBData.getFormats().dateFormat); + const defaultDate = DateTime.now().toFormat( + initialDBData.getFormats().dateFormat + ); + + const tomorrowDate = DateTime.now() + .plus({ day: 1 }) + .toFormat(initialDBData.getFormats().dateFormat); - // cy.navigateToTemplatesSubmenu('Proposal'); + cy.login('officer'); + cy.visit('/'); - // cy.contains(initialDBData.template.name) - // .parent() - // .find("[aria-label='Edit']") - // .first() - // .click(); + cy.navigateToTemplatesSubmenu('Proposal'); - // cy.get('[data-cy=show-more-button]').first().click(); + cy.contains(initialDBData.template.name) + .parent() + .find("[aria-label='Edit']") + .first() + .click(); - // cy.get('[data-cy=add-question-menu-item]').first().click(); + cy.get('[data-cy=show-more-button]').first().click(); - // cy.get('[data-cy=questionPicker] [data-cy=show-more-button]') - // .first() - // .click(); + cy.get('[data-cy=add-question-menu-item]').first().click(); - // cy.contains('Add Date').click(); + cy.get('[data-cy=questionPicker] [data-cy=show-more-button]') + .first() + .click(); - // cy.get('[data-cy=question]').clear().type(dateQuestion.title); + cy.contains('Add Date').click(); - // cy.get('[data-cy="minDate"] input').type(minDate); - // cy.get('[data-cy="maxDate"] input').type(maxDate); - // cy.get('[data-cy="defaultDate"] input').type(defaultDate); + cy.get('[data-cy=question]').clear().type(dateQuestion.title); - // cy.contains('Save').click(); + cy.get('[data-cy="minDate"] input').type(minDate); + cy.get('[data-cy="maxDate"] input').type(maxDate); + cy.get('[data-cy="defaultDate"] input').type(defaultDate); - // cy.contains(dateQuestion.title) - // .closest('[data-cy=question-container]') - // .find("[data-cy='proposal-question-id']") - // .invoke('html') - // .then((fieldId) => { - // dateFieldId = fieldId; - // }); + cy.contains('Save').click(); - // cy.contains(dateQuestion.title) - // .parent() - // .dragElement([{ direction: 'left', length: 1 }]); + cy.contains(dateQuestion.title) + .closest('[data-cy=question-container]') + .find("[data-cy='proposal-question-id']") + .invoke('html') + .then((fieldId) => { + dateFieldId = fieldId; + }); - // cy.finishedLoading(); + cy.contains(dateQuestion.title) + .parent() + .dragElement([{ direction: 'left', length: 1 }]); - // cy.contains(dateQuestion.title).click(); + cy.finishedLoading(); - // cy.get('[data-cy="minDate"] input').should('have.value', minDate); - // cy.get('[data-cy="maxDate"] input').should('have.value', maxDate); - // cy.get('[data-cy="defaultDate"] input').should('have.value', defaultDate); + cy.contains(dateQuestion.title).click(); - // cy.get('[data-cy="minDate"] input').clear().type(minDate); - // cy.get('[data-cy="maxDate"] input').clear().type(maxDate); - // cy.get('[data-cy="defaultDate"] input').clear().type(defaultDate); + cy.get('[data-cy="minDate"] input').should('have.value', minDate); + cy.get('[data-cy="maxDate"] input').should('have.value', maxDate); + cy.get('[data-cy="defaultDate"] input').should('have.value', defaultDate); - // cy.contains('Update').click(); + cy.get('[data-cy="minDate"] input').clear().type(minDate); + cy.get('[data-cy="maxDate"] input').clear().type(maxDate); + cy.get('[data-cy="defaultDate"] input').clear().type(defaultDate); - // cy.logout(); + cy.contains('Update').click(); - // cy.login('user'); - // cy.visit('/'); + cy.logout(); - // cy.contains('New Proposal').click(); + cy.login('user'); + cy.visit('/'); - // cy.contains(dateQuestion.title); - // cy.get('body').then(() => { - // cy.get(`[data-cy="${dateFieldId}.value"] input`).as('dateField'); + cy.contains('New Proposal').click(); - // cy.get('@dateField').should('have.value', defaultDate); + cy.contains(dateQuestion.title); + cy.get('body').then(() => { + cy.get(`[data-cy="${dateFieldId}.value"] input`).as('dateField'); - // cy.get('@dateField').clear().type(earlierThanMinDate); - // cy.contains('Save and continue').click(); - // cy.contains('Date must be no earlier than'); + cy.get('@dateField').should('have.value', defaultDate); - // cy.get('@dateField').clear().type(laterThanMaxDate); - // cy.contains('Save and continue').click(); - // cy.contains('Date must be no latter than'); + cy.get('@dateField').clear().type(earlierThanMinDate); + cy.contains('Save and continue').click(); + cy.contains('Date must be no earlier than'); - // cy.get('@dateField').clear().type(tomorrowDate); - // cy.contains('Save and continue').click(); - // cy.contains('Date must be no').should('not.exist'); - // }); - // }); + cy.get('@dateField').clear().type(laterThanMaxDate); + cy.contains('Save and continue').click(); + cy.contains('Date must be no latter than'); - // it('should render the Number field accepting only positive, negative numbers if set', () => { - // let numberField1Id: string; - // let numberField2Id: string; + cy.get('@dateField').clear().type(tomorrowDate); + cy.contains('Save and continue').click(); + cy.contains('Date must be no').should('not.exist'); + }); + }); - // cy.login('officer'); - // cy.visit('/'); + it('should render the Number field accepting only positive, negative numbers if set', () => { + let numberField1Id: string; + let numberField2Id: string; - // cy.navigateToTemplatesSubmenu('Proposal'); + cy.login('officer'); + cy.visit('/'); - // cy.contains(initialDBData.template.name) - // .parent() - // .find("[aria-label='Edit']") - // .first() - // .click(); + cy.navigateToTemplatesSubmenu('Proposal'); - // cy.get('[data-cy=show-more-button]').first().click(); + cy.contains(initialDBData.template.name) + .parent() + .find("[aria-label='Edit']") + .first() + .click(); - // cy.get('[data-cy=add-question-menu-item]').first().click(); + cy.get('[data-cy=show-more-button]').first().click(); - // cy.get('[data-cy=questionPicker] [data-cy=show-more-button]') - // .first() - // .click(); + cy.get('[data-cy=add-question-menu-item]').first().click(); - // cy.contains('Add Number').click(); + cy.get('[data-cy=questionPicker] [data-cy=show-more-button]') + .first() + .click(); - // cy.get('[data-cy=question]').clear().type(numberQuestion2.title); + cy.contains('Add Number').click(); - // cy.get('[data-cy=units]').find('[aria-label=Open]').click(); + cy.get('[data-cy=question]').clear().type(numberQuestion2.title); - // cy.contains('celsius').click(); + cy.get('[data-cy=units]').find('[aria-label=Open]').click(); - // cy.get('[data-cy=units]').find('[aria-label=Open]').click(); + cy.contains('celsius').click(); - // cy.contains('kelvin').click(); + cy.get('[data-cy=units]').find('[aria-label=Open]').click(); - // cy.get('[data-cy="numberValueConstraint"]').click(); + cy.contains('kelvin').click(); - // cy.contains('Only positive numbers').click(); + cy.get('[data-cy="numberValueConstraint"]').click(); - // cy.contains('Save').click(); + cy.contains('Only positive numbers').click(); - // cy.contains(numberQuestion2.title) - // .closest('[data-cy=question-container]') - // .find("[data-cy='proposal-question-id']") - // .invoke('html') - // .then((fieldId) => { - // numberField1Id = fieldId; - // }); + cy.contains('Save').click(); - // cy.contains(numberQuestion2.title) - // .parent() - // .dragElement([{ direction: 'left', length: 1 }]); + cy.contains(numberQuestion2.title) + .closest('[data-cy=question-container]') + .find("[data-cy='proposal-question-id']") + .invoke('html') + .then((fieldId) => { + numberField1Id = fieldId; + }); - // cy.get('[data-cy=questionPicker] [data-cy=show-more-button]') - // .first() - // .click(); + cy.contains(numberQuestion2.title) + .parent() + .dragElement([{ direction: 'left', length: 1 }]); - // cy.contains('Add Number').click(); + cy.get('[data-cy=questionPicker] [data-cy=show-more-button]') + .first() + .click(); - // cy.get('[data-cy=question]').clear().type(numberQuestion3.title); + cy.contains('Add Number').click(); - // cy.get('[data-cy=units]').find('[aria-label=Open]').click(); + cy.get('[data-cy=question]').clear().type(numberQuestion3.title); - // cy.contains('celsius').click(); + cy.get('[data-cy=units]').find('[aria-label=Open]').click(); - // cy.get('[data-cy=units]').find('[aria-label=Open]').click(); + cy.contains('celsius').click(); - // cy.contains('kelvin').click(); + cy.get('[data-cy=units]').find('[aria-label=Open]').click(); - // cy.get('[data-cy="numberValueConstraint"]').click(); + cy.contains('kelvin').click(); - // cy.contains('Only positive numbers').click(); + cy.get('[data-cy="numberValueConstraint"]').click(); - // cy.contains('Save').click(); + cy.contains('Only positive numbers').click(); - // cy.contains(numberQuestion3.title) - // .closest('[data-cy=question-container]') - // .find("[data-cy='proposal-question-id']") - // .invoke('html') - // .then((fieldId) => { - // numberField2Id = fieldId; - // }); + cy.contains('Save').click(); - // cy.contains(numberQuestion3.title) - // .parent() - // .dragElement([{ direction: 'left', length: 1 }]); + cy.contains(numberQuestion3.title) + .closest('[data-cy=question-container]') + .find("[data-cy='proposal-question-id']") + .invoke('html') + .then((fieldId) => { + numberField2Id = fieldId; + }); - // cy.finishedLoading(); + cy.contains(numberQuestion3.title) + .parent() + .dragElement([{ direction: 'left', length: 1 }]); - // cy.contains(numberQuestion3.title).click(); + cy.finishedLoading(); - // cy.get('[data-cy=units]').contains('celsius'); - // cy.get('[data-cy=units]').contains('kelvin'); + cy.contains(numberQuestion3.title).click(); - // cy.get('[data-cy="numberValueConstraint"] input').should( - // 'have.value', - // 'Only positive numbers' - // ); + cy.get('[data-cy=units]').contains('celsius'); + cy.get('[data-cy=units]').contains('kelvin'); - // cy.get('[data-cy="numberValueConstraint"]').click(); + cy.get('[data-cy="numberValueConstraint"] input').should( + 'have.value', + 'Only positive numbers' + ); - // cy.contains('Only negative numbers').click(); + cy.get('[data-cy="numberValueConstraint"]').click(); - // cy.contains('Update').click(); + cy.contains('Only negative numbers').click(); - // cy.logout(); + cy.contains('Update').click(); - // cy.login('user'); - // cy.visit('/'); + cy.logout(); - // cy.contains('New Proposal').click(); + cy.login('user'); + cy.visit('/'); - // cy.contains(numberQuestion2.title); - // cy.contains(numberQuestion3.title); - // cy.get('body').then(() => { - // cy.get(`[data-cy="${numberField1Id}.value"] input`).as('numberField1'); - // cy.get(`[data-cy="${numberField2Id}.value"] input`).as('numberField2'); + cy.contains('New Proposal').click(); - // cy.get('@numberField1').type('1{leftarrow}-'); - // cy.get('@numberField2').type('1'); + cy.contains(numberQuestion2.title); + cy.contains(numberQuestion3.title); + cy.get('body').then(() => { + cy.get(`[data-cy="${numberField1Id}.value"] input`).as('numberField1'); + cy.get(`[data-cy="${numberField2Id}.value"] input`).as('numberField2'); - // cy.contains('Save and continue').click(); - // cy.contains('Value must be a negative number'); - // cy.contains('Value must be a positive number'); + cy.get('@numberField1').type('1{leftarrow}-'); + cy.get('@numberField2').type('1'); - // cy.get('@numberField1').clear().type('1'); - // cy.get('@numberField2').clear().type('1{leftarrow}-'); + cy.contains('Save and continue').click(); + cy.contains('Value must be a negative number'); + cy.contains('Value must be a positive number'); - // cy.contains('Value must be a negative number').should('not.exist'); - // cy.contains('Value must be a positive number').should('not.exist'); - // }); - // }); + cy.get('@numberField1').clear().type('1'); + cy.get('@numberField2').clear().type('1{leftarrow}-'); - // it('User officer can add multiple choice question as a dependency', () => { - // cy.createProposal({ callId: initialDBData.call.id }).then((result) => { - // const createdProposal = result.createProposal.proposal; - // if (createdProposal) { - // cy.updateProposal({ - // proposalPk: createdProposal.primaryKey, - // title: proposal.title, - // abstract: proposal.abstract, - // proposerId: initialDBData.users.user1.id, - // }); - // } - // }); + cy.contains('Value must be a negative number').should('not.exist'); + cy.contains('Value must be a positive number').should('not.exist'); + }); + }); - // cy.login('officer'); - // cy.visit('/'); + it('User officer can add multiple choice question as a dependency', () => { + cy.createProposal({ callId: initialDBData.call.id }).then((result) => { + const createdProposal = result.createProposal.proposal; + if (createdProposal) { + cy.updateProposal({ + proposalPk: createdProposal.primaryKey, + title: proposal.title, + abstract: proposal.abstract, + proposerId: initialDBData.users.user1.id, + }); + } + }); - // cy.navigateToTemplatesSubmenu('Proposal'); + cy.login('officer'); + cy.visit('/'); - // cy.contains(initialDBData.template.name) - // .parent() - // .find("[aria-label='Edit']") - // .first() - // .click(); + cy.navigateToTemplatesSubmenu('Proposal'); - // cy.createMultipleChoiceQuestion( - // templateDependencies.questions.selectQuestion.title, - // { - // option1: templateDependencies.questions.selectQuestion.answer1, - // option2: templateDependencies.questions.selectQuestion.answer2, - // } - // ); + cy.contains(initialDBData.template.name) + .parent() + .find("[aria-label='Edit']") + .first() + .click(); - // cy.createBooleanQuestion( - // templateDependencies.questions.booleanQuestion.title - // ); + cy.createMultipleChoiceQuestion( + templateDependencies.questions.selectQuestion.title, + { + option1: templateDependencies.questions.selectQuestion.answer1, + option2: templateDependencies.questions.selectQuestion.answer2, + } + ); - // cy.contains(templateDependencies.questions.booleanQuestion.title).click(); - - // cy.get('[data-cy="add-dependency-button"]').click(); - - // cy.get('[id="dependency-id"]').click(); - - // cy.get('[role="presentation"]') - // .contains(templateDependencies.questions.selectQuestion.title) - // .click(); - - // cy.get('[id="dependencyValue"]').click(); + cy.createBooleanQuestion( + templateDependencies.questions.booleanQuestion.title + ); - // cy.contains( - // templateDependencies.questions.selectQuestion.answer1 - // ).click(); - - // cy.get('[data-cy="submit"]').click(); + cy.contains(templateDependencies.questions.booleanQuestion.title).click(); - // cy.logout(); - - // cy.login('user'); - // cy.visit('/'); - - // cy.contains(proposal.title) - // .parent() - // .find('[aria-label="Edit proposal"]') - // .click(); + cy.get('[data-cy="add-dependency-button"]').click(); - // cy.contains('save and continue', { matchCase: false }).click(); - // cy.finishedLoading(); + cy.get('[id="dependency-id"]').click(); - // // Dependee is NOT visible - // cy.get('main form').should( - // 'not.contain.text', - // templateDependencies.questions.booleanQuestion.title - // ); + cy.get('[role="presentation"]') + .contains(templateDependencies.questions.selectQuestion.title) + .click(); - // cy.contains(templateDependencies.questions.selectQuestion.title) - // .parent() - // .click(); - // cy.contains( - // templateDependencies.questions.selectQuestion.answer1 - // ).click(); - - // // Dependee is visible - // cy.get('main form').should( - // 'contain.text', - // templateDependencies.questions.booleanQuestion.title - // ); + cy.get('[id="dependencyValue"]').click(); - // cy.contains(templateDependencies.questions.selectQuestion.title) - // .parent() - // .click(); - // cy.contains( - // templateDependencies.questions.selectQuestion.answer2 - // ).click(); - - // // Dependee is NOT visible again - // cy.get('main form').should( - // 'not.contain.text', - // templateDependencies.questions.booleanQuestion.title - // ); - // }); + cy.contains( + templateDependencies.questions.selectQuestion.answer1 + ).click(); - // it('Should not let you create circular dependency chain', () => { - // const field1 = 'boolean_1_' + Date.now(); - // const field2 = 'boolean_2_' + Date.now(); - // const field3 = 'boolean_3_' + Date.now(); - // cy.login('officer'); - // cy.visit('/'); - - // cy.navigateToTemplatesSubmenu('Proposal'); + cy.get('[data-cy="submit"]').click(); - // cy.contains(initialDBData.template.name) - // .parent() - // .find("[aria-label='Edit']") - // .first() - // .click(); - - // cy.createBooleanQuestion(field1); - // cy.createBooleanQuestion(field2); - // cy.createBooleanQuestion(field3); - - // function addDependency( - // fieldName: string, - // contains: string[], - // select?: string - // ) { - // cy.contains(fieldName).click(); - // cy.get('[data-cy="add-dependency-button"]').click(); - // cy.get('[id="dependency-id"]').click(); - - // contains.forEach((field) => { - // cy.get('[role="listbox"]').contains(field); - // }); - - // if (contains.length === 0) { - // cy.get('[role="listbox"]').children().should('have.length', 2); - // } - - // if (select) { - // cy.get('[role="listbox"]').contains(select).click(); - - // cy.get('[id="dependencyValue"]').click(); - // cy.get('[role="listbox"]').contains('true').click(); - - // cy.contains('Update').click(); - - // cy.finishedLoading(); - // } - // } - - // addDependency(field1, [field2, field3], field2); - // addDependency(field2, [field3], field3); - // addDependency(field3, []); - // }); - - // it('User officer should be able to search questions', function () { - // createTopicWithQuestionsAndRelations(); - // cy.login('officer'); - // cy.visit('/'); - - // cy.navigateToTemplatesSubmenu('Proposal'); - - // // Create an empty template so we can search all question from the question picker - - // cy.get('[data-cy=create-new-button]').click(); - - // cy.get('[data-cy="name"]').type(templateSearch.title); - - // cy.get('[data-cy="description"]').type(templateSearch.description); - - // cy.get('[data-cy="submit"]').click(); - - // cy.get('[data-cy=show-more-button]').click(); - - // // Search questions - // cy.contains('Add question').click(); - - // cy.get('[data-cy=search-button]').click(); - - // // after entering textQuestion, dateQuestion should not be visible - // cy.contains(dateQuestion.title); - // cy.get('[data-cy=search-text] input').clear().type(textQuestion.title); - // cy.contains(textQuestion.title).should('exist'); - // cy.contains(dateQuestion.title).should('not.exist'); - - // cy.get('[data-cy=search-text] input').clear(); - - // // after entering dateQuestion, textQuestion should not be visible - // cy.contains(textQuestion.title); - // cy.get('[data-cy=search-text] input').clear().type(dateQuestion.title); - // cy.contains(dateQuestion.title).should('exist'); - // cy.contains(textQuestion.title).should('not.exist'); - - // cy.get('[data-cy=search-text] input').clear(); - // cy.get('[data-cy=question-list]') - // .contains(booleanQuestion) - // .should('exist'); // this command is here to wait for the list to be clean of the previous search - - // // searching by categories + cy.logout(); - // // Boolean - // cy.get('[data-cy=data-type]').click(); - // cy.get('[role=listbox]').contains('Boolean').click(); - // cy.get('[data-cy=question-list]') - // .contains(booleanQuestion) - // .should('exist'); - // cy.get('[data-cy=question-list]') - // .contains(textQuestion.title) - // .should('not.exist'); + cy.login('user'); + cy.visit('/'); - // // Date - // cy.get('[data-cy=data-type]').click(); - // cy.get('[role=listbox]').contains('Date').click(); - // cy.get('[data-cy=question-list]') - // .contains(dateQuestion.title) - // .should('exist'); - // cy.get('[data-cy=question-list]') - // .contains(textQuestion.title) - // .should('not.exist'); + cy.contains(proposal.title) + .parent() + .find('[aria-label="Edit proposal"]') + .click(); + + cy.contains('save and continue', { matchCase: false }).click(); + cy.finishedLoading(); + + // Dependee is NOT visible + cy.get('main form').should( + 'not.contain.text', + templateDependencies.questions.booleanQuestion.title + ); + + cy.contains(templateDependencies.questions.selectQuestion.title) + .parent() + .click(); + cy.contains( + templateDependencies.questions.selectQuestion.answer1 + ).click(); + + // Dependee is visible + cy.get('main form').should( + 'contain.text', + templateDependencies.questions.booleanQuestion.title + ); + + cy.contains(templateDependencies.questions.selectQuestion.title) + .parent() + .click(); + cy.contains( + templateDependencies.questions.selectQuestion.answer2 + ).click(); + + // Dependee is NOT visible again + cy.get('main form').should( + 'not.contain.text', + templateDependencies.questions.booleanQuestion.title + ); + }); + + it('Should not let you create circular dependency chain', () => { + const field1 = 'boolean_1_' + Date.now(); + const field2 = 'boolean_2_' + Date.now(); + const field3 = 'boolean_3_' + Date.now(); + cy.login('officer'); + cy.visit('/'); + + cy.navigateToTemplatesSubmenu('Proposal'); + + cy.contains(initialDBData.template.name) + .parent() + .find("[aria-label='Edit']") + .first() + .click(); - // // All question types - // cy.get('[data-cy=data-type]').click(); - // cy.get('[role=listbox]').contains('All').click(); - // cy.get('[data-cy=question-list]') - // .contains(dateQuestion.title) - // .should('exist'); - // cy.get('[data-cy=question-list]') - // .contains(textQuestion.title) - // .should('exist'); + cy.createBooleanQuestion(field1); + cy.createBooleanQuestion(field2); + cy.createBooleanQuestion(field3); + + function addDependency( + fieldName: string, + contains: string[], + select?: string + ) { + cy.contains(fieldName).click(); + cy.get('[data-cy="add-dependency-button"]').click(); + cy.get('[id="dependency-id"]').click(); + + contains.forEach((field) => { + cy.get('[role="listbox"]').contains(field); + }); - // // filter with no results - // cy.get('[data-cy=search-text] input') - // .clear() - // .type('string match no results'); - // cy.get('[data-cy=question-list] div').should('have.length', 0); + if (contains.length === 0) { + cy.get('[role="listbox"]').children().should('have.length', 2); + } - // // closing resets the filter - // cy.get('[data-cy=search-button]').click(); - // cy.get('[data-cy=question-list] div').should('have.length.above', 0); - // }); + if (select) { + cy.get('[role="listbox"]').contains(select).click(); - // it('User officer import template', () => { - // const fileName = 'template_import.json'; - // const resolvedQuestionTitle = 'General information'; + cy.get('[id="dependencyValue"]').click(); + cy.get('[role="listbox"]').contains('true').click(); - // cy.login('officer'); - // cy.visit('/'); + cy.contains('Update').click(); - // cy.navigateToTemplatesSubmenu('Proposal'); + cy.finishedLoading(); + } + } - // cy.get('[data-cy=import-template-button]').click(); + addDependency(field1, [field2, field3], field2); + addDependency(field2, [field3], field3); + addDependency(field3, []); + }); - // cy.get('input[type="file"]').attachFixture({ - // filePath: fileName, - // fileName: fileName, - // mimeType: 'image/png', - // }); + it('User officer should be able to search questions', function () { + createTopicWithQuestionsAndRelations(); + cy.login('officer'); + cy.visit('/'); + + cy.navigateToTemplatesSubmenu('Proposal'); + + // Create an empty template so we can search all question from the question picker + + cy.get('[data-cy=create-new-button]').click(); + + cy.get('[data-cy="name"]').type(templateSearch.title); + + cy.get('[data-cy="description"]').type(templateSearch.description); + + cy.get('[data-cy="submit"]').click(); + + cy.get('[data-cy=show-more-button]').click(); + + // Search questions + cy.contains('Add question').click(); + + cy.get('[data-cy=search-button]').click(); + + // after entering textQuestion, dateQuestion should not be visible + cy.contains(dateQuestion.title); + cy.get('[data-cy=search-text] input').clear().type(textQuestion.title); + cy.contains(textQuestion.title).should('exist'); + cy.contains(dateQuestion.title).should('not.exist'); + + cy.get('[data-cy=search-text] input').clear(); + + // after entering dateQuestion, textQuestion should not be visible + cy.contains(textQuestion.title); + cy.get('[data-cy=search-text] input').clear().type(dateQuestion.title); + cy.contains(dateQuestion.title).should('exist'); + cy.contains(textQuestion.title).should('not.exist'); + + cy.get('[data-cy=search-text] input').clear(); + cy.get('[data-cy=question-list]') + .contains(booleanQuestion) + .should('exist'); // this command is here to wait for the list to be clean of the previous search + + // searching by categories + + // Boolean + cy.get('[data-cy=data-type]').click(); + cy.get('[role=listbox]').contains('Boolean').click(); + cy.get('[data-cy=question-list]') + .contains(booleanQuestion) + .should('exist'); + cy.get('[data-cy=question-list]') + .contains(textQuestion.title) + .should('not.exist'); + + // Date + cy.get('[data-cy=data-type]').click(); + cy.get('[role=listbox]').contains('Date').click(); + cy.get('[data-cy=question-list]') + .contains(dateQuestion.title) + .should('exist'); + cy.get('[data-cy=question-list]') + .contains(textQuestion.title) + .should('not.exist'); + + // All question types + cy.get('[data-cy=data-type]').click(); + cy.get('[role=listbox]').contains('All').click(); + cy.get('[data-cy=question-list]') + .contains(dateQuestion.title) + .should('exist'); + cy.get('[data-cy=question-list]') + .contains(textQuestion.title) + .should('exist'); + + // filter with no results + cy.get('[data-cy=search-text] input') + .clear() + .type('string match no results'); + cy.get('[data-cy=question-list] div').should('have.length', 0); + + // closing resets the filter + cy.get('[data-cy=search-button]').click(); + cy.get('[data-cy=question-list] div').should('have.length.above', 0); + }); - // cy.get("[data-cy='proposal_basis-accordion']") - // .find('[data-cy=conflict-icon]') - // .should('exist'); + it('User officer import template', () => { + const fileName = 'template_import.json'; + const resolvedQuestionTitle = 'General information'; - // cy.get("[data-cy='proposal_basis-accordion']").click(); + cy.login('officer'); + cy.visit('/'); + + cy.navigateToTemplatesSubmenu('Proposal'); - // cy.get("[data-cy='proposal_basis-accordion']") - // .find("[data-cy='new-item-checkbox']") - // .click(); + cy.get('[data-cy=import-template-button]').click(); - // cy.get("[data-cy='proposal_basis-accordion']") - // .find('[data-cy=conflict-icon]') - // .should('not.exist'); - - // cy.get("[data-cy='proposal_basis-accordion']") - // .find('[data-cy=resolved-icon]') - // .should('exist'); - - // cy.get('[data-cy=import-template-button]').click(); - - // cy.contains(resolvedQuestionTitle).should('exist'); - - // cy.notification({ - // variant: 'success', - // text: 'Template imported successfully', - // }); - // }); - - // it('should export template in compatible format', () => { - // cy.login('officer'); - // cy.visit('/'); - - // cy.navigateToTemplatesSubmenu('Proposal'); - - // cy.contains(initialDBData.template.name) - // .closest('TR') - // .find('[aria-label="Export"]') - // .click(); - - // cy.fixture('template_export.json').then((expectedExport) => { - // const downloadsFolder = Cypress.config('downloadsFolder'); - - // cy.readFile( - // path.join(downloadsFolder, `${initialDBData.template.name}.json`) - // ).then((actualExport) => { - // // remove date from the export, because it is not deterministic - // delete expectedExport.metadata.exportDate; - // delete actualExport.metadata.exportDate; - - // const exportSubtemplates = expectedExport.data.subTemplates[0]; - // const importSubtemplates = actualExport.data.subTemplates[0]; - - // expect(expectedExport).to.deep.equal(actualExport); - - // expect(exportSubtemplates).to.deep.equal(importSubtemplates); - // }); - // }); - // }); + cy.get('input[type="file"]').attachFixture({ + filePath: fileName, + fileName: fileName, + mimeType: 'image/png', + }); + + cy.get("[data-cy='proposal_basis-accordion']") + .find('[data-cy=conflict-icon]') + .should('exist'); + + cy.get("[data-cy='proposal_basis-accordion']").click(); + + cy.get("[data-cy='proposal_basis-accordion']") + .find("[data-cy='new-item-checkbox']") + .click(); + + cy.get("[data-cy='proposal_basis-accordion']") + .find('[data-cy=conflict-icon]') + .should('not.exist'); + + cy.get("[data-cy='proposal_basis-accordion']") + .find('[data-cy=resolved-icon]') + .should('exist'); + + cy.get('[data-cy=import-template-button]').click(); + + cy.contains(resolvedQuestionTitle).should('exist'); + + cy.notification({ + variant: 'success', + text: 'Template imported successfully', + }); + }); + + it('should export template in compatible format', () => { + cy.login('officer'); + cy.visit('/'); + + cy.navigateToTemplatesSubmenu('Proposal'); + + cy.contains(initialDBData.template.name) + .closest('TR') + .find('[aria-label="Export"]') + .click(); + + cy.fixture('template_export.json').then((expectedExport) => { + const downloadsFolder = Cypress.config('downloadsFolder'); + + cy.readFile( + path.join(downloadsFolder, `${initialDBData.template.name}.json`) + ).then((actualExport) => { + // remove date from the export, because it is not deterministic + delete expectedExport.metadata.exportDate; + delete actualExport.metadata.exportDate; + + const exportSubtemplates = expectedExport.data.subTemplates[0]; + const importSubtemplates = actualExport.data.subTemplates[0]; + + expect(expectedExport).to.deep.equal(actualExport); + + expect(exportSubtemplates).to.deep.equal(importSubtemplates); + }); + }); + }); it('should validate question template relation input', () => { createTopicWithQuestionsAndRelations(); @@ -1296,161 +1296,161 @@ context('Template tests', () => { createTopicWithQuestionsAndRelations(true); }); - // it('User can create proposal with template', () => { - // const dateTimeFieldValue = DateTime.fromJSDate( - // faker.date.past() - // ).toFormat(initialDBData.getFormats().dateTimeFormat); - // cy.createProposal({ callId: initialDBData.call.id }).then((result) => { - // const createdProposal = result.createProposal.proposal; - // if (createdProposal) { - // cy.updateProposal({ - // proposalPk: createdProposal.primaryKey, - // title: proposal.title, - // abstract: proposal.abstract, - // proposerId: initialDBData.users.user1.id, - // }); - // } - // }); - // cy.login('user'); - // cy.visit('/'); - - // cy.contains(proposal.title) - // .parent() - // .find('[aria-label="Edit proposal"]') - // .click(); - - // cy.contains('save and continue', { matchCase: false }).click(); - // cy.finishedLoading(); - - // cy.get(`[data-cy="${intervalId}.min"]`).click().type('1'); - // cy.get(`[data-cy="${intervalId}.max"]`).click().type('2'); - // cy.get(`[data-cy="${numberId}.value"]`).click().type('1'); - // cy.get(`#${boolId}`).click(); - // cy.get(`#${textId}`).clear().type('this_word_{enter}should_be_multiline'); - // cy.contains('this_word_should_be_multiline').should('not.exist'); - // cy.get(`#${textId}`).clear().type(textQuestion.answer); - // cy.contains(`${textQuestion.answer.length}/${textQuestion.maxChars}`); - // cy.get(`[data-cy='${dateId}.value'] button`).click(); - // cy.contains('15').click(); - // cy.get(`[data-cy='${timeId}.value'] input`) - // .clear() - // .type(dateTimeFieldValue); - - // cy.get(`#${multipleChoiceId}`).click(); - // cy.contains(multipleChoiceQuestion.answers[0]).click(); - // cy.contains(multipleChoiceQuestion.answers[2]).click(); - // cy.get('body').type('{esc}'); - - // cy.window().then((win) => { - // return new Cypress.Promise((resolve) => { - // win.tinyMCE.editors[richTextInputId].setContent( - // richTextInputQuestion.answer - // ); - // win.tinyMCE.editors[richTextInputId].fire('blur'); - - // resolve(); - // }); - // }); - - // cy.get(`#${richTextInputId}_ifr`) - // .its('0.contentDocument.body') - // .should('not.be.empty') - // .contains(richTextInputQuestion.answer); - - // cy.get('[data-cy="rich-text-char-count"]').then((element) => { - // expect(element.text()).to.be.equal( - // `Characters: ${richTextInputQuestion.answer.length} / ${richTextInputQuestion.maxChars}` - // ); - // }); - - // cy.contains('Save and continue').click(); - - // cy.contains('Submit').click(); - - // cy.contains('OK').click(); - - // cy.contains(proposal.title); - // cy.contains(proposal.abstract); - // cy.contains(textQuestion.answer); - // cy.contains(multipleChoiceQuestion.answers[0]); - // cy.contains(multipleChoiceQuestion.answers[1]).should('not.exist'); - // cy.contains(multipleChoiceQuestion.answers[2]); - // cy.contains(dateTimeFieldValue); - - // cy.contains(richTextInputQuestion.title); - // cy.get(`[data-cy="${richTextInputId}_open"]`).click(); - // cy.get('[role="dialog"]').contains(richTextInputQuestion.title); - // cy.get('[role="dialog"]').contains(richTextInputQuestion.answer); - // cy.get('[role="dialog"]').contains('Close').click(); - - // cy.contains('Dashboard').click(); - // cy.contains(proposal.title); - // cy.contains('submitted'); - // }); - - // it('File Upload field could be set as required', () => { - // const fileName = 'file_upload_test.png'; - - // cy.login('officer'); - // cy.visit('/'); - - // cy.navigateToTemplatesSubmenu('Proposal'); - - // cy.contains(initialDBData.template.name) - // .parent() - // .find("[aria-label='Edit']") - // .first() - // .click(); - - // cy.contains(fileQuestion).click(); - - // cy.get('[role="presentation"]').contains('image/*').click(); - - // cy.get('body').type('{esc}'); - - // cy.contains('Is required').click(); + it('User can create proposal with template', () => { + const dateTimeFieldValue = DateTime.fromJSDate( + faker.date.past() + ).toFormat(initialDBData.getFormats().dateTimeFormat); + cy.createProposal({ callId: initialDBData.call.id }).then((result) => { + const createdProposal = result.createProposal.proposal; + if (createdProposal) { + cy.updateProposal({ + proposalPk: createdProposal.primaryKey, + title: proposal.title, + abstract: proposal.abstract, + proposerId: initialDBData.users.user1.id, + }); + } + }); + cy.login('user'); + cy.visit('/'); - // cy.contains('Update').click(); + cy.contains(proposal.title) + .parent() + .find('[aria-label="Edit proposal"]') + .click(); - // cy.logout(); + cy.contains('save and continue', { matchCase: false }).click(); + cy.finishedLoading(); + + cy.get(`[data-cy="${intervalId}.min"]`).click().type('1'); + cy.get(`[data-cy="${intervalId}.max"]`).click().type('2'); + cy.get(`[data-cy="${numberId}.value"]`).click().type('1'); + cy.get(`#${boolId}`).click(); + cy.get(`#${textId}`).clear().type('this_word_{enter}should_be_multiline'); + cy.contains('this_word_should_be_multiline').should('not.exist'); + cy.get(`#${textId}`).clear().type(textQuestion.answer); + cy.contains(`${textQuestion.answer.length}/${textQuestion.maxChars}`); + cy.get(`[data-cy='${dateId}.value'] button`).click(); + cy.contains('15').click(); + cy.get(`[data-cy='${timeId}.value'] input`) + .clear() + .type(dateTimeFieldValue); + + cy.get(`#${multipleChoiceId}`).click(); + cy.contains(multipleChoiceQuestion.answers[0]).click(); + cy.contains(multipleChoiceQuestion.answers[2]).click(); + cy.get('body').type('{esc}'); - // cy.login('user'); - // cy.visit('/'); + cy.window().then((win) => { + return new Cypress.Promise((resolve) => { + win.tinyMCE.editors[richTextInputId].setContent( + richTextInputQuestion.answer + ); + win.tinyMCE.editors[richTextInputId].fire('blur'); - // cy.contains('New Proposal').click(); + resolve(); + }); + }); + + cy.get(`#${richTextInputId}_ifr`) + .its('0.contentDocument.body') + .should('not.be.empty') + .contains(richTextInputQuestion.answer); + + cy.get('[data-cy="rich-text-char-count"]').then((element) => { + expect(element.text()).to.be.equal( + `Characters: ${richTextInputQuestion.answer.length} / ${richTextInputQuestion.maxChars}` + ); + }); + + cy.contains('Save and continue').click(); + + cy.contains('Submit').click(); + + cy.contains('OK').click(); + + cy.contains(proposal.title); + cy.contains(proposal.abstract); + cy.contains(textQuestion.answer); + cy.contains(multipleChoiceQuestion.answers[0]); + cy.contains(multipleChoiceQuestion.answers[1]).should('not.exist'); + cy.contains(multipleChoiceQuestion.answers[2]); + cy.contains(dateTimeFieldValue); + + cy.contains(richTextInputQuestion.title); + cy.get(`[data-cy="${richTextInputId}_open"]`).click(); + cy.get('[role="dialog"]').contains(richTextInputQuestion.title); + cy.get('[role="dialog"]').contains(richTextInputQuestion.answer); + cy.get('[role="dialog"]').contains('Close').click(); + + cy.contains('Dashboard').click(); + cy.contains(proposal.title); + cy.contains('submitted'); + }); - // cy.get('[data-cy=title] input').type(faker.lorem.words(2)); - // cy.get('[data-cy=abstract] textarea').first().type(faker.lorem.words(2)); - // cy.contains('Save and continue').click(); + it('File Upload field could be set as required', () => { + const fileName = 'file_upload_test.png'; - // cy.contains(fileQuestion); - // cy.contains('Save and continue').click(); - // cy.contains(fileQuestion) - // .parent() - // .contains('field must have at least 1 items'); + cy.login('officer'); + cy.visit('/'); - // cy.intercept({ - // method: 'POST', - // url: '/files/upload', - // }).as('upload'); + cy.navigateToTemplatesSubmenu('Proposal'); - // cy.get('input[type="file"]').attachFixture({ - // filePath: fileName, - // fileName: fileName, - // mimeType: 'image/png', - // }); + cy.contains(initialDBData.template.name) + .parent() + .find("[aria-label='Edit']") + .first() + .click(); + + cy.contains(fileQuestion).click(); + + cy.get('[role="presentation"]').contains('image/*').click(); + + cy.get('body').type('{esc}'); + + cy.contains('Is required').click(); + + cy.contains('Update').click(); + + cy.logout(); + + cy.login('user'); + cy.visit('/'); + + cy.contains('New Proposal').click(); + + cy.get('[data-cy=title] input').type(faker.lorem.words(2)); + cy.get('[data-cy=abstract] textarea').first().type(faker.lorem.words(2)); + cy.contains('Save and continue').click(); + + cy.contains(fileQuestion); + cy.contains('Save and continue').click(); + cy.contains(fileQuestion) + .parent() + .contains('field must have at least 1 items'); - // // wait for the '/files/upload' request, and leave a 30 seconds delay before throwing an error - // cy.wait('@upload', { requestTimeout: 30000 }); + cy.intercept({ + method: 'POST', + url: '/files/upload', + }).as('upload'); - // cy.contains(fileName); + cy.get('input[type="file"]').attachFixture({ + filePath: fileName, + fileName: fileName, + mimeType: 'image/png', + }); - // cy.contains(fileQuestion) - // .parent() - // .should('not.contain.text', 'field must have at least 1 items'); + // wait for the '/files/upload' request, and leave a 30 seconds delay before throwing an error + cy.wait('@upload', { requestTimeout: 30000 }); - // cy.logout(); - // }); + cy.contains(fileName); + + cy.contains(fileQuestion) + .parent() + .should('not.contain.text', 'field must have at least 1 items'); + + cy.logout(); + }); it('File Upload max files should be required', () => { cy.login('officer'); @@ -1488,504 +1488,504 @@ context('Template tests', () => { cy.logout(); }); - // it('Officer can delete proposal questions', () => { - // cy.login('officer'); - // cy.visit('/'); + it('Officer can delete proposal questions', () => { + cy.login('officer'); + cy.visit('/'); + + cy.navigateToTemplatesSubmenu('Proposal'); + + cy.contains(initialDBData.template.name) + .parent() + .find("[aria-label='Edit']") + .first() + .click(); + + cy.contains(textQuestion.title).click(); + cy.get("[data-cy='remove-from-template']").click(); + + cy.contains(booleanQuestion).click(); + cy.get("[data-cy='remove-from-template']").click(); + + cy.contains(dateQuestion.title).click(); + cy.get("[data-cy='remove-from-template']").click(); + + cy.contains(fileQuestion).click(); + cy.get("[data-cy='remove-from-template']").click(); + }); + + it('User officer can add multiple dependencies on a question', () => { + cy.createProposal({ callId: initialDBData.call.id }).then((result) => { + const createdProposal = result.createProposal.proposal; + if (createdProposal) { + cy.updateProposal({ + proposalPk: createdProposal.primaryKey, + title: proposal.title, + abstract: proposal.abstract, + proposerId: initialDBData.users.user1.id, + }); + } + }); + cy.login('officer'); + cy.visit('/'); - // cy.navigateToTemplatesSubmenu('Proposal'); + cy.navigateToTemplatesSubmenu('Proposal'); - // cy.contains(initialDBData.template.name) - // .parent() - // .find("[aria-label='Edit']") - // .first() - // .click(); + cy.contains(initialDBData.template.name) + .parent() + .find("[aria-label='Edit']") + .first() + .click(); - // cy.contains(textQuestion.title).click(); - // cy.get("[data-cy='remove-from-template']").click(); + cy.createTextQuestion(templateDependencies.questions.textQuestion.title); - // cy.contains(booleanQuestion).click(); - // cy.get("[data-cy='remove-from-template']").click(); + cy.contains(templateDependencies.questions.textQuestion.title).click(); - // cy.contains(dateQuestion.title).click(); - // cy.get("[data-cy='remove-from-template']").click(); + cy.get('[data-cy="add-dependency-button"]').click(); - // cy.contains(fileQuestion).click(); - // cy.get("[data-cy='remove-from-template']").click(); - // }); + cy.get('[id="dependency-id"]').click(); - // it('User officer can add multiple dependencies on a question', () => { - // cy.createProposal({ callId: initialDBData.call.id }).then((result) => { - // const createdProposal = result.createProposal.proposal; - // if (createdProposal) { - // cy.updateProposal({ - // proposalPk: createdProposal.primaryKey, - // title: proposal.title, - // abstract: proposal.abstract, - // proposerId: initialDBData.users.user1.id, - // }); - // } - // }); - // cy.login('officer'); - // cy.visit('/'); + cy.get('[role="presentation"]') + .contains(multipleChoiceQuestion.title) + .click(); - // cy.navigateToTemplatesSubmenu('Proposal'); + cy.get('[id="dependencyValue"]').click(); - // cy.contains(initialDBData.template.name) - // .parent() - // .find("[aria-label='Edit']") - // .first() - // .click(); + cy.contains(multipleChoiceQuestion.answers[1]).click(); - // cy.createTextQuestion(templateDependencies.questions.textQuestion.title); + cy.get('[data-cy="add-dependency-button"]').click(); - // cy.contains(templateDependencies.questions.textQuestion.title).click(); + cy.get('[id="dependency-id"]').last().click(); - // cy.get('[data-cy="add-dependency-button"]').click(); + cy.get('[role="presentation"]').contains(booleanQuestion).click(); - // cy.get('[id="dependency-id"]').click(); + cy.get('[id="dependencyValue"]').last().click(); - // cy.get('[role="presentation"]') - // .contains(multipleChoiceQuestion.title) - // .click(); + cy.contains('true').click(); - // cy.get('[id="dependencyValue"]').click(); + cy.get('[data-cy="submit"]').click(); - // cy.contains(multipleChoiceQuestion.answers[1]).click(); + cy.logout(); - // cy.get('[data-cy="add-dependency-button"]').click(); + cy.login('user'); + cy.visit('/'); - // cy.get('[id="dependency-id"]').last().click(); + cy.contains(proposal.title) + .parent() + .find('[aria-label="Edit proposal"]') + .click(); - // cy.get('[role="presentation"]').contains(booleanQuestion).click(); + cy.contains('save and continue', { matchCase: false }).click(); + cy.finishedLoading(); - // cy.get('[id="dependencyValue"]').last().click(); + cy.get('main form').should( + 'not.contain.text', + templateDependencies.questions.textQuestion.title + ); - // cy.contains('true').click(); + cy.contains(multipleChoiceQuestion.title).parent().click(); + cy.contains(multipleChoiceQuestion.answers[1]).click(); + cy.get('body').type('{esc}'); + cy.get('main form').should( + 'not.contain.text', + templateDependencies.questions.textQuestion.title + ); - // cy.get('[data-cy="submit"]').click(); + cy.contains(booleanQuestion).click(); - // cy.logout(); + cy.get('main form').should( + 'contain.text', + templateDependencies.questions.textQuestion.title + ); - // cy.login('user'); - // cy.visit('/'); + cy.contains(multipleChoiceQuestion.title).parent().click(); + cy.get('[role="presentation"]') + .contains(multipleChoiceQuestion.answers[1]) + .click(); + cy.contains(multipleChoiceQuestion.answers[2]).click(); + cy.get('body').type('{esc}'); - // cy.contains(proposal.title) - // .parent() - // .find('[aria-label="Edit proposal"]') - // .click(); + cy.get('main form').should( + 'not.contain.text', + templateDependencies.questions.textQuestion.title + ); + }); - // cy.contains('save and continue', { matchCase: false }).click(); - // cy.finishedLoading(); + it('User officer can change dependency logic operator', () => { + cy.createProposal({ callId: initialDBData.call.id }).then((result) => { + const createdProposal = result.createProposal.proposal; + if (createdProposal) { + cy.updateProposal({ + proposalPk: createdProposal.primaryKey, + title: proposal.title, + abstract: proposal.abstract, + proposerId: initialDBData.users.user1.id, + }); + } + }); + cy.login('officer'); + cy.visit('/'); - // cy.get('main form').should( - // 'not.contain.text', - // templateDependencies.questions.textQuestion.title - // ); + cy.navigateToTemplatesSubmenu('Proposal'); - // cy.contains(multipleChoiceQuestion.title).parent().click(); - // cy.contains(multipleChoiceQuestion.answers[1]).click(); - // cy.get('body').type('{esc}'); - // cy.get('main form').should( - // 'not.contain.text', - // templateDependencies.questions.textQuestion.title - // ); + cy.get('[aria-label="Edit"]').last().click(); - // cy.contains(booleanQuestion).click(); + cy.contains(textQuestion.title).click(); - // cy.get('main form').should( - // 'contain.text', - // templateDependencies.questions.textQuestion.title - // ); + cy.get('[data-cy="add-dependency-button"]').click(); - // cy.contains(multipleChoiceQuestion.title).parent().click(); - // cy.get('[role="presentation"]') - // .contains(multipleChoiceQuestion.answers[1]) - // .click(); - // cy.contains(multipleChoiceQuestion.answers[2]).click(); - // cy.get('body').type('{esc}'); + cy.get('[id="dependency-id"]').last().click(); - // cy.get('main form').should( - // 'not.contain.text', - // templateDependencies.questions.textQuestion.title - // ); - // }); + cy.get('[role="presentation"]') + .contains(multipleChoiceQuestion.title) + .click(); - // it('User officer can change dependency logic operator', () => { - // cy.createProposal({ callId: initialDBData.call.id }).then((result) => { - // const createdProposal = result.createProposal.proposal; - // if (createdProposal) { - // cy.updateProposal({ - // proposalPk: createdProposal.primaryKey, - // title: proposal.title, - // abstract: proposal.abstract, - // proposerId: initialDBData.users.user1.id, - // }); - // } - // }); - // cy.login('officer'); - // cy.visit('/'); + cy.get('[id="dependencyValue"]').last().click(); - // cy.navigateToTemplatesSubmenu('Proposal'); + cy.contains(multipleChoiceQuestion.answers[1]).click(); - // cy.get('[aria-label="Edit"]').last().click(); + cy.get('[data-cy="dependencies-operator"]').click(); - // cy.contains(textQuestion.title).click(); + cy.get('[data-value="OR"]').click(); - // cy.get('[data-cy="add-dependency-button"]').click(); + cy.get('[data-cy="submit"]').click(); - // cy.get('[id="dependency-id"]').last().click(); + cy.logout(); - // cy.get('[role="presentation"]') - // .contains(multipleChoiceQuestion.title) - // .click(); + cy.login('user'); + cy.visit('/'); - // cy.get('[id="dependencyValue"]').last().click(); + cy.contains(proposal.title) + .parent() + .find('[aria-label="Edit proposal"]') + .click(); - // cy.contains(multipleChoiceQuestion.answers[1]).click(); + cy.contains('save and continue', { matchCase: false }).click(); + cy.finishedLoading(); - // cy.get('[data-cy="dependencies-operator"]').click(); + cy.get('main form').should('not.contain.text', textQuestion.title); - // cy.get('[data-value="OR"]').click(); + cy.contains(multipleChoiceQuestion.title).parent().click(); + cy.contains(multipleChoiceQuestion.answers[1]).click(); + cy.get('body').type('{esc}'); + cy.contains(textQuestion.title); - // cy.get('[data-cy="submit"]').click(); + cy.contains(multipleChoiceQuestion.title).parent().click(); + cy.get('[role="presentation"]') + .contains(multipleChoiceQuestion.answers[1]) + .click(); + cy.contains(multipleChoiceQuestion.answers[2]).click(); + cy.get('body').type('{esc}'); - // cy.logout(); + cy.get('main form').should('not.contain.text', textQuestion.title); - // cy.login('user'); - // cy.visit('/'); + cy.contains(booleanQuestion).click(); + cy.contains(textQuestion.title); + }); - // cy.contains(proposal.title) - // .parent() - // .find('[aria-label="Edit proposal"]') - // .click(); + it('Can delete dependee, which will remove the dependency on depender', () => { + cy.login('officer'); + cy.visit('/'); - // cy.contains('save and continue', { matchCase: false }).click(); - // cy.finishedLoading(); + cy.navigateToTemplatesSubmenu('Proposal'); - // cy.get('main form').should('not.contain.text', textQuestion.title); + cy.contains(initialDBData.template.name) + .parent() + .find("[aria-label='Edit']") + .first() + .click(); - // cy.contains(multipleChoiceQuestion.title).parent().click(); - // cy.contains(multipleChoiceQuestion.answers[1]).click(); - // cy.get('body').type('{esc}'); - // cy.contains(textQuestion.title); + cy.contains(textQuestion.title) + .closest('[data-cy=question-container]') + .find('[data-cy=dependency-list]') + .should('exist'); + cy.contains(booleanQuestion).click(); + cy.get('[data-cy=remove-from-template]').click(); + cy.contains(textQuestion.title) + .closest('[data-cy=question-container]') + .find('[data-cy=dependency-list]') + .should('not.exist'); + }); - // cy.contains(multipleChoiceQuestion.title).parent().click(); - // cy.get('[role="presentation"]') - // .contains(multipleChoiceQuestion.answers[1]) - // .click(); - // cy.contains(multipleChoiceQuestion.answers[2]).click(); - // cy.get('body').type('{esc}'); + it('User can add captions after uploading image/* file', () => { + const fileName = 'file_upload_test2.png'; // need to use another file due to bug in cypress, which do not allow the same fixture to be reused + cy.createProposal({ callId: initialDBData.call.id }).then((result) => { + const createdProposal = result.createProposal.proposal; + if (createdProposal) { + cy.updateProposal({ + proposalPk: createdProposal.primaryKey, + title: proposal.title, + abstract: proposal.abstract, + proposerId: initialDBData.users.user1.id, + }); + } + }); - // cy.get('main form').should('not.contain.text', textQuestion.title); + cy.login('user'); + cy.visit('/'); - // cy.contains(booleanQuestion).click(); - // cy.contains(textQuestion.title); - // }); + cy.contains(proposal.title) + .parent() + .find('[aria-label="Edit proposal"]') + .click(); + cy.finishedLoading(); + + cy.contains('Save and continue').click(); + + cy.contains(fileQuestion); - // it('Can delete dependee, which will remove the dependency on depender', () => { - // cy.login('officer'); - // cy.visit('/'); + cy.intercept({ + method: 'POST', + url: '/files/upload', + }).as('upload'); - // cy.navigateToTemplatesSubmenu('Proposal'); + cy.get('input[type="file"]').attachFixture({ + filePath: fileName, + fileName: fileName, + mimeType: 'image/png', + }); - // cy.contains(initialDBData.template.name) - // .parent() - // .find("[aria-label='Edit']") - // .first() - // .click(); + // wait for the '/files/upload' request, and leave a 30 seconds delay before throwing an error + cy.wait('@upload', { requestTimeout: 30000 }); - // cy.contains(textQuestion.title) - // .closest('[data-cy=question-container]') - // .find('[data-cy=dependency-list]') - // .should('exist'); - // cy.contains(booleanQuestion).click(); - // cy.get('[data-cy=remove-from-template]').click(); - // cy.contains(textQuestion.title) - // .closest('[data-cy=question-container]') - // .find('[data-cy=dependency-list]') - // .should('not.exist'); - // }); + cy.contains(fileName); - // it('User can add captions after uploading image/* file', () => { - // const fileName = 'file_upload_test2.png'; // need to use another file due to bug in cypress, which do not allow the same fixture to be reused - // cy.createProposal({ callId: initialDBData.call.id }).then((result) => { - // const createdProposal = result.createProposal.proposal; - // if (createdProposal) { - // cy.updateProposal({ - // proposalPk: createdProposal.primaryKey, - // title: proposal.title, - // abstract: proposal.abstract, - // proposerId: initialDBData.users.user1.id, - // }); - // } - // }); + cy.get('[aria-label="Add image caption"]').click(); - // cy.login('user'); - // cy.visit('/'); + cy.get('[data-cy="image-figure"] input').type('Fig_test'); + cy.get('[data-cy="image-caption"] input').type('Test caption'); - // cy.contains(proposal.title) - // .parent() - // .find('[aria-label="Edit proposal"]') - // .click(); - // cy.finishedLoading(); + cy.get('[data-cy="save-button"]').click(); - // cy.contains('Save and continue').click(); + cy.notification({ variant: 'success', text: 'Saved' }); - // cy.contains(fileQuestion); + cy.finishedLoading(); - // cy.intercept({ - // method: 'POST', - // url: '/files/upload', - // }).as('upload'); + cy.get('.MuiStep-root').contains('Review').click(); - // cy.get('input[type="file"]').attachFixture({ - // filePath: fileName, - // fileName: fileName, - // mimeType: 'image/png', - // }); + cy.contains(proposal.abstract); - // // wait for the '/files/upload' request, and leave a 30 seconds delay before throwing an error - // cy.wait('@upload', { requestTimeout: 30000 }); + cy.contains(fileName); + + cy.get('[data-cy="questionary-stepper"]') + .contains(initialDBData.template.topic.title) + .click(); - // cy.contains(fileName); + cy.finishedLoading(); + cy.contains('Save and continue'); - // cy.get('[aria-label="Add image caption"]').click(); - - // cy.get('[data-cy="image-figure"] input').type('Fig_test'); - // cy.get('[data-cy="image-caption"] input').type('Test caption'); - - // cy.get('[data-cy="save-button"]').click(); - - // cy.notification({ variant: 'success', text: 'Saved' }); - - // cy.finishedLoading(); - - // cy.get('.MuiStep-root').contains('Review').click(); - - // cy.contains(proposal.abstract); - - // cy.contains(fileName); - - // cy.get('[data-cy="questionary-stepper"]') - // .contains(initialDBData.template.topic.title) - // .click(); - - // cy.finishedLoading(); - // cy.contains('Save and continue'); - - // cy.contains(fileQuestion) - // .parent() - // .should('contain.text', fileName) - // .find('[data-cy="image-caption"] input') - // .should('have.value', 'Test caption'); - // cy.contains(fileQuestion) - // .parent() - // .find('[data-cy="image-figure"] input') - // .should('have.value', 'Fig_test'); - // }); + cy.contains(fileQuestion) + .parent() + .should('contain.text', fileName) + .find('[data-cy="image-caption"] input') + .should('have.value', 'Test caption'); + cy.contains(fileQuestion) + .parent() + .find('[data-cy="image-figure"] input') + .should('have.value', 'Fig_test'); + }); }); - // describe('File upload tests', () => { - // beforeEach(() => { - // cy.login('officer'); - // cy.visit('/'); + describe('File upload tests', () => { + beforeEach(() => { + cy.login('officer'); + cy.visit('/'); - // cy.navigateToTemplatesSubmenu('Proposal'); + cy.navigateToTemplatesSubmenu('Proposal'); - // cy.contains(initialDBData.template.name) - // .parent() - // .find("[aria-label='Edit']") - // .first() - // .click(); + cy.contains(initialDBData.template.name) + .parent() + .find("[aria-label='Edit']") + .first() + .click(); - // cy.createFileUploadQuestion(fileQuestion, ['.pdf', '.docx', 'image/*']); + cy.createFileUploadQuestion(fileQuestion, ['.pdf', '.docx', 'image/*']); - // cy.login('user'); - // cy.visit('/'); + cy.login('user'); + cy.visit('/'); - // cy.contains('New Proposal').click(); + cy.contains('New Proposal').click(); - // cy.get('[data-cy=title] input').type('title'); + cy.get('[data-cy=title] input').type('title'); - // cy.get('[data-cy=abstract] textarea').first().type('abstract'); + cy.get('[data-cy=abstract] textarea').first().type('abstract'); - // cy.contains(fileQuestion); - // }); + cy.contains(fileQuestion); + }); - // it('File limitation info is displayed', () => { - // cy.contains('Accepted formats: .pdf, .docx, any image'); - // cy.contains('Maximum 3 PDF page(s) per file'); - // cy.contains('Maximum 3 file(s)'); - // }); + it('File limitation info is displayed', () => { + cy.contains('Accepted formats: .pdf, .docx, any image'); + cy.contains('Maximum 3 PDF page(s) per file'); + cy.contains('Maximum 3 file(s)'); + }); - // it('File without extension cannot be uploaded', () => { - // const fileName = 'file_without_ext'; + it('File without extension cannot be uploaded', () => { + const fileName = 'file_without_ext'; - // cy.get('input[type="file"]').attachFixture({ - // filePath: fileName, - // fileName: fileName, - // mimeType: 'application/pdf', - // }); + cy.get('input[type="file"]').attachFixture({ + filePath: fileName, + fileName: fileName, + mimeType: 'application/pdf', + }); - // cy.contains('Incorrect file type'); - // }); + cy.contains('Incorrect file type'); + }); - // it('File with incorrect content header cannot be uploaded', () => { - // const fileName = 'file_upload_test.png'; + it('File with incorrect content header cannot be uploaded', () => { + const fileName = 'file_upload_test.png'; - // cy.get('input[type="file"]').attachFixture({ - // filePath: fileName, - // fileName: fileName, - // mimeType: 'application/octet-stream', - // }); + cy.get('input[type="file"]').attachFixture({ + filePath: fileName, + fileName: fileName, + mimeType: 'application/octet-stream', + }); - // cy.contains('Incorrect file type'); - // }); + cy.contains('Incorrect file type'); + }); - // it('Unidentifiable disguised file is uploaded but not accepted', () => { - // const fileName = 'unidentifiable_file.pdf'; + it('Unidentifiable disguised file is uploaded but not accepted', () => { + const fileName = 'unidentifiable_file.pdf'; - // cy.intercept({ - // method: 'POST', - // url: '/files/upload', - // }).as('upload'); + cy.intercept({ + method: 'POST', + url: '/files/upload', + }).as('upload'); - // cy.get('input[type="file"]').attachFixture({ - // filePath: fileName, - // fileName: fileName, - // mimeType: 'application/pdf', - // }); + cy.get('input[type="file"]').attachFixture({ + filePath: fileName, + fileName: fileName, + mimeType: 'application/pdf', + }); - // // wait for the '/files/upload' request, and leave a 30 seconds delay before throwing an error - // cy.wait('@upload', { requestTimeout: 30000 }); + // wait for the '/files/upload' request, and leave a 30 seconds delay before throwing an error + cy.wait('@upload', { requestTimeout: 30000 }); - // cy.contains(fileName); + cy.contains(fileName); - // cy.contains('Save and continue').click(); + cy.contains('Save and continue').click(); - // cy.notification({ variant: 'error', text: 'not satisfying constraint' }); - // }); + cy.notification({ variant: 'error', text: 'not satisfying constraint' }); + }); - // it('Identifiable disguised file is uploaded but not accepted', () => { - // const fileName = 'mp3_file.pdf'; + it('Identifiable disguised file is uploaded but not accepted', () => { + const fileName = 'mp3_file.pdf'; - // cy.intercept({ - // method: 'POST', - // url: '/files/upload', - // }).as('upload'); + cy.intercept({ + method: 'POST', + url: '/files/upload', + }).as('upload'); - // cy.get('input[type="file"]').attachFixture({ - // filePath: fileName, - // fileName: fileName, - // mimeType: 'application/pdf', - // }); + cy.get('input[type="file"]').attachFixture({ + filePath: fileName, + fileName: fileName, + mimeType: 'application/pdf', + }); - // // wait for the '/files/upload' request, and leave a 30 seconds delay before throwing an error - // cy.wait('@upload', { requestTimeout: 30000 }); + // wait for the '/files/upload' request, and leave a 30 seconds delay before throwing an error + cy.wait('@upload', { requestTimeout: 30000 }); - // cy.contains(fileName); + cy.contains(fileName); - // cy.contains('Save and continue').click(); + cy.contains('Save and continue').click(); - // cy.notification({ variant: 'error', text: 'not satisfying constraint' }); - // }); + cy.notification({ variant: 'error', text: 'not satisfying constraint' }); + }); - // it('Question is not accepted when one of many files is invalid', () => { - // const validFile = 'file_upload_test.png'; - // const invalidFile = 'mp3_file.pdf'; + it('Question is not accepted when one of many files is invalid', () => { + const validFile = 'file_upload_test.png'; + const invalidFile = 'mp3_file.pdf'; - // cy.intercept({ - // method: 'POST', - // url: '/files/upload', - // }).as('upload'); + cy.intercept({ + method: 'POST', + url: '/files/upload', + }).as('upload'); - // cy.get('input[type="file"]').attachFixture({ - // filePath: validFile, - // fileName: validFile, - // mimeType: 'image/png', - // }); + cy.get('input[type="file"]').attachFixture({ + filePath: validFile, + fileName: validFile, + mimeType: 'image/png', + }); - // // wait for the '/files/upload' request, and leave a 30 seconds delay before throwing an error - // cy.wait('@upload', { requestTimeout: 30000 }); + // wait for the '/files/upload' request, and leave a 30 seconds delay before throwing an error + cy.wait('@upload', { requestTimeout: 30000 }); - // cy.contains(validFile); + cy.contains(validFile); - // cy.contains('Save and continue').click(); + cy.contains('Save and continue').click(); - // cy.notification({ variant: 'success', text: 'Saved' }); + cy.notification({ variant: 'success', text: 'Saved' }); - // cy.contains('Back').click(); + cy.contains('Back').click(); - // cy.contains(fileQuestion); - // cy.contains(validFile); + cy.contains(fileQuestion); + cy.contains(validFile); - // cy.intercept({ - // method: 'POST', - // url: '/files/upload', - // }).as('upload'); + cy.intercept({ + method: 'POST', + url: '/files/upload', + }).as('upload'); - // cy.get('input[type="file"]').attachFixture({ - // filePath: invalidFile, - // fileName: invalidFile, - // mimeType: 'application/pdf', - // }); + cy.get('input[type="file"]').attachFixture({ + filePath: invalidFile, + fileName: invalidFile, + mimeType: 'application/pdf', + }); - // // wait for the '/files/upload' request, and leave a 30 seconds delay before throwing an error - // cy.wait('@upload', { requestTimeout: 30000 }); + // wait for the '/files/upload' request, and leave a 30 seconds delay before throwing an error + cy.wait('@upload', { requestTimeout: 30000 }); - // cy.contains(invalidFile); + cy.contains(invalidFile); - // cy.contains('Save and continue').click(); + cy.contains('Save and continue').click(); - // cy.notification({ variant: 'error', text: 'not satisfying constraint' }); - // }); + cy.notification({ variant: 'error', text: 'not satisfying constraint' }); + }); - // it('Question is not accepted when PDF file page count is outside limit', () => { - // const fileName = 'pdf_5_pages.pdf'; + it('Question is not accepted when PDF file page count is outside limit', () => { + const fileName = 'pdf_5_pages.pdf'; - // cy.intercept({ - // method: 'POST', - // url: '/files/upload', - // }).as('upload'); + cy.intercept({ + method: 'POST', + url: '/files/upload', + }).as('upload'); - // cy.get('input[type="file"]').attachFixture({ - // filePath: fileName, - // fileName: fileName, - // mimeType: 'application/pdf', - // }); + cy.get('input[type="file"]').attachFixture({ + filePath: fileName, + fileName: fileName, + mimeType: 'application/pdf', + }); - // // wait for the '/files/upload' request, and leave a 30 seconds delay before throwing an error - // cy.wait('@upload', { requestTimeout: 30000 }); + // wait for the '/files/upload' request, and leave a 30 seconds delay before throwing an error + cy.wait('@upload', { requestTimeout: 30000 }); - // cy.contains(fileName); + cy.contains(fileName); - // cy.contains('Save and continue').click(); + cy.contains('Save and continue').click(); - // cy.notification({ variant: 'error', text: 'not satisfying constraint' }); - // }); + cy.notification({ variant: 'error', text: 'not satisfying constraint' }); + }); - // it('Question accepted when PDF file page count is within limit', () => { - // const fileName = 'pdf_3_pages.pdf'; + it('Question accepted when PDF file page count is within limit', () => { + const fileName = 'pdf_3_pages.pdf'; - // cy.intercept({ - // method: 'POST', - // url: '/files/upload', - // }).as('upload'); + cy.intercept({ + method: 'POST', + url: '/files/upload', + }).as('upload'); - // cy.get('input[type="file"]').attachFixture({ - // filePath: fileName, - // fileName: fileName, - // mimeType: 'application/pdf', - // }); + cy.get('input[type="file"]').attachFixture({ + filePath: fileName, + fileName: fileName, + mimeType: 'application/pdf', + }); - // // wait for the '/files/upload' request, and leave a 30 seconds delay before throwing an error - // cy.wait('@upload', { requestTimeout: 30000 }); + // wait for the '/files/upload' request, and leave a 30 seconds delay before throwing an error + cy.wait('@upload', { requestTimeout: 30000 }); - // cy.contains(fileName); + cy.contains(fileName); - // cy.contains('Save and continue').click(); + cy.contains('Save and continue').click(); - // cy.notification({ variant: 'success', text: 'Saved' }); - // }); - // }); + cy.notification({ variant: 'success', text: 'Saved' }); + }); + }); }); diff --git a/src/components/DashBoard.tsx b/src/components/DashBoard.tsx index 5900a931b..118da4587 100644 --- a/src/components/DashBoard.tsx +++ b/src/components/DashBoard.tsx @@ -190,7 +190,7 @@ const Dashboard: React.FC = () => { )?.isEnabled; const { currentRole } = useContext(UserContext); - const { calls } = useCallsData({ isActive: true }); + const { calls } = useCallsData({ isActive: true, isEnded: false }); useEffect(() => { if (isTabletOrMobile) { diff --git a/src/components/proposal/ProposalSummary.tsx b/src/components/proposal/ProposalSummary.tsx index 75a57051b..17fd9a8f0 100644 --- a/src/components/proposal/ProposalSummary.tsx +++ b/src/components/proposal/ProposalSummary.tsx @@ -11,8 +11,9 @@ import { } from 'components/questionary/QuestionaryContext'; import ProposalQuestionaryReview from 'components/review/ProposalQuestionaryReview'; import { UserRole } from 'generated/sdk'; -import { useDataApi } from 'hooks/common/useDataApi'; import { useDownloadPDFProposal } from 'hooks/proposal/useDownloadPDFProposal'; +import { isCallEnded } from 'utils/helperFunctions'; +import useDataApiWithFeedback from 'utils/useDataApiWithFeedback'; import withConfirm, { WithConfirmType } from 'utils/withConfirm'; import { ProposalContextType } from './ProposalContainer'; @@ -30,9 +31,13 @@ function ProposalReview({ confirm }: ProposalSummaryProps) { throw new Error(createMissingContextErrorMessage()); } - const api = useDataApi(); + const { api } = useDataApiWithFeedback(); const isUserOfficer = useCheckAccess([UserRole.USER_OFFICER]); - const isCallActive = state.proposal?.call?.isActive ?? true; + + const callHasEnded = isCallEnded( + state.proposal.call?.startCall, + state.proposal.call?.endCall + ); const [loadingSubmitMessage, setLoadingSubmitMessage] = useState(true); @@ -50,7 +55,7 @@ function ProposalReview({ confirm }: ProposalSummaryProps) { proposal.questionary.steps.every((step) => step.isCompleted); const submitDisabled = - (!isUserOfficer && !isCallActive) || // disallow submit for non user officers if the call ended + (!isUserOfficer && callHasEnded) || // disallow submit for non user officers if the call ended !allStepsComplete || proposal.submitted; @@ -126,7 +131,9 @@ function ProposalReview({ confirm }: ProposalSummaryProps) { confirm( async () => { setIsSubmitting(true); - const result = await api().submitProposal({ + const result = await api({ + toastSuccessMessage: 'Proposal submitted successfully', + }).submitProposal({ proposalPk: state.proposal.primaryKey, }); if (!result.submitProposal.proposal) { diff --git a/src/components/proposal/ProposalTable.tsx b/src/components/proposal/ProposalTable.tsx index 5beb963e2..ea7125672 100644 --- a/src/components/proposal/ProposalTable.tsx +++ b/src/components/proposal/ProposalTable.tsx @@ -15,6 +15,7 @@ import { UserContext } from 'context/UserContextProvider'; import { Call } from 'generated/sdk'; import { useDownloadPDFProposal } from 'hooks/proposal/useDownloadPDFProposal'; import { ProposalData } from 'hooks/proposal/useProposalData'; +import { isCallEnded } from 'utils/helperFunctions'; import { tableIcons } from 'utils/materialIcons'; import { tableLocalization } from 'utils/materialLocalization'; import { timeAgo } from 'utils/Time'; @@ -177,9 +178,13 @@ const ProposalTable = ({ }} actions={[ (rowData) => { - const isCallActive = rowData.call?.isActive ?? true; + const callHasEnded = isCallEnded( + rowData.call?.startCall, + rowData.call?.endCall + ); + const readOnly = - !isCallActive || + callHasEnded || (rowData.submitted && rowData.status?.shortCode !== 'EDITABLE_SUBMITTED'); diff --git a/src/components/questionary/questionaries/proposal/ProposalQuestionaryWizardStep.ts b/src/components/questionary/questionaries/proposal/ProposalQuestionaryWizardStep.ts index 6864be5a2..c394e1a63 100644 --- a/src/components/questionary/questionaries/proposal/ProposalQuestionaryWizardStep.ts +++ b/src/components/questionary/questionaries/proposal/ProposalQuestionaryWizardStep.ts @@ -1,6 +1,7 @@ import { ProposalSubmissionState } from 'models/questionary/proposal/ProposalSubmissionState'; import { ProposalWithQuestionary } from 'models/questionary/proposal/ProposalWithQuestionary'; import { QuestionarySubmissionState } from 'models/questionary/QuestionarySubmissionState'; +import { isCallEnded } from 'utils/helperFunctions'; import { QuestionaryWizardStep } from '../../DefaultWizardStepFactory'; @@ -8,17 +9,20 @@ export class ProposalQuestionaryWizardStep extends QuestionaryWizardStep { isItemWithQuestionaryEditable(state: QuestionarySubmissionState) { const { proposal } = state as ProposalSubmissionState; - const isCallActive = proposal.call?.isActive ?? true; + const callHasEnded = isCallEnded( + proposal.call?.startCall, + proposal.call?.endCall + ); const proposalStatus = this.getProposalStatus(proposal); if (proposalStatus === 'EDITABLE_SUBMITTED') { return true; } - if (isCallActive) { - return proposalStatus === 'DRAFT'; - } else { + if (callHasEnded) { return false; + } else { + return proposalStatus === 'DRAFT'; } } diff --git a/src/generated/sdk.ts b/src/generated/sdk.ts index fdea17791..2ba916681 100644 --- a/src/generated/sdk.ts +++ b/src/generated/sdk.ts @@ -3904,7 +3904,7 @@ export type CloneProposalsMutationVariables = Exact<{ }>; -export type CloneProposalsMutation = { cloneProposals: { proposals: Array<{ primaryKey: number, title: string, abstract: string, statusId: number, publicStatus: ProposalPublicStatus, proposalId: string, finalStatus: ProposalEndStatus | null, commentForUser: string | null, commentForManagement: string | null, created: any, updated: any, callId: number, questionaryId: number, notified: boolean, submitted: boolean, managementTimeAllocation: number | null, managementDecisionSubmitted: boolean, proposer: { id: number, firstname: string, lastname: string, preferredname: string | null, organisation: string, organizationId: number, position: string, created: any | null, placeholder: boolean | null } | null, users: Array<{ id: number, firstname: string, lastname: string, preferredname: string | null, organisation: string, organizationId: number, position: string, created: any | null, placeholder: boolean | null }>, questionary: { isCompleted: boolean, questionaryId: number, templateId: number, created: any, steps: Array<{ isCompleted: boolean, topic: { title: string, id: number, templateId: number, sortOrder: number, isEnabled: boolean }, fields: Array<{ answerId: number | null, sortOrder: number, topicId: number, dependenciesOperator: DependenciesLogicOperator | null, value: any | null, question: { id: string, question: string, naturalKey: string, dataType: DataType, categoryId: TemplateCategoryId, config: { small_label: string, required: boolean, tooltip: string } | { small_label: string, required: boolean, tooltip: string, minDate: string | null, maxDate: string | null, defaultDate: string | null, includeTime: boolean } | { html: string, plain: string, omitFromPdf: boolean } | { small_label: string, required: boolean, tooltip: string } | { file_type: Array, max_files: number, pdf_page_limit: number, small_label: string, required: boolean, tooltip: string } | { titlePlaceholder: string, questionLabel: string } | { small_label: string, required: boolean, tooltip: string, units: Array<{ id: string, unit: string, quantity: string, symbol: string, siConversionFormula: string }> } | { numberValueConstraint: NumberValueConstraint | null, small_label: string, required: boolean, tooltip: string, units: Array<{ id: string, unit: string, quantity: string, symbol: string, siConversionFormula: string }> } | { tooltip: string } | { tooltip: string } | { small_label: string, required: boolean, tooltip: string, max: number | null } | { titlePlaceholder: string } | { addEntryButtonLabel: string, minEntries: number | null, maxEntries: number | null, templateId: number | null, esiTemplateId: number | null, templateCategory: string, required: boolean, small_label: string } | { tooltip: string } | { variant: string, options: Array, isMultipleSelect: boolean, small_label: string, required: boolean, tooltip: string } | { small_label: string, required: boolean, tooltip: string } | { addEntryButtonLabel: string, minEntries: number | null, maxEntries: number | null, templateId: number | null, templateCategory: string, required: boolean, small_label: string } | { min: number | null, max: number | null, multiline: boolean, placeholder: string, small_label: string, required: boolean, tooltip: string, htmlQuestion: string | null, isHtmlQuestion: boolean, isCounterHidden: boolean } | { small_label: string, required: boolean, tooltip: string } }, config: { small_label: string, required: boolean, tooltip: string } | { small_label: string, required: boolean, tooltip: string, minDate: string | null, maxDate: string | null, defaultDate: string | null, includeTime: boolean } | { html: string, plain: string, omitFromPdf: boolean } | { small_label: string, required: boolean, tooltip: string } | { file_type: Array, max_files: number, pdf_page_limit: number, small_label: string, required: boolean, tooltip: string } | { titlePlaceholder: string, questionLabel: string } | { small_label: string, required: boolean, tooltip: string, units: Array<{ id: string, unit: string, quantity: string, symbol: string, siConversionFormula: string }> } | { numberValueConstraint: NumberValueConstraint | null, small_label: string, required: boolean, tooltip: string, units: Array<{ id: string, unit: string, quantity: string, symbol: string, siConversionFormula: string }> } | { tooltip: string } | { tooltip: string } | { small_label: string, required: boolean, tooltip: string, max: number | null } | { titlePlaceholder: string } | { addEntryButtonLabel: string, minEntries: number | null, maxEntries: number | null, templateId: number | null, esiTemplateId: number | null, templateCategory: string, required: boolean, small_label: string } | { tooltip: string } | { variant: string, options: Array, isMultipleSelect: boolean, small_label: string, required: boolean, tooltip: string } | { small_label: string, required: boolean, tooltip: string } | { addEntryButtonLabel: string, minEntries: number | null, maxEntries: number | null, templateId: number | null, templateCategory: string, required: boolean, small_label: string } | { min: number | null, max: number | null, multiline: boolean, placeholder: string, small_label: string, required: boolean, tooltip: string, htmlQuestion: string | null, isHtmlQuestion: boolean, isCounterHidden: boolean } | { small_label: string, required: boolean, tooltip: string }, dependencies: Array<{ questionId: string, dependencyId: string, dependencyNaturalKey: string, condition: { condition: EvaluatorOperator, params: any } }> }> }> }, technicalReview: { id: number, comment: string | null, publicComment: string | null, timeAllocation: number | null, status: TechnicalReviewStatus | null, proposalPk: number, submitted: boolean, files: string | null, technicalReviewAssigneeId: number | null, technicalReviewAssignee: { id: number, firstname: string, lastname: string } | null } | null, reviews: Array<{ id: number, grade: number | null, comment: string | null, status: ReviewStatus, userID: number, sepID: number, reviewer: { firstname: string, lastname: string, id: number } | null }> | null, instrument: { id: number, name: string, shortCode: string } | null, call: { id: number, shortCode: string, isActive: boolean, referenceNumberFormat: string | null } | null, status: { id: number, shortCode: string, name: string, description: string, isDefault: boolean } | null, sepMeetingDecision: { proposalPk: number, recommendation: ProposalEndStatus | null, commentForUser: string | null, commentForManagement: string | null, rankOrder: number | null, submitted: boolean, submittedBy: number | null } | null }> | null, rejection: { reason: string, context: string | null, exception: string | null } | null } }; +export type CloneProposalsMutation = { cloneProposals: { proposals: Array<{ primaryKey: number, title: string, abstract: string, statusId: number, publicStatus: ProposalPublicStatus, proposalId: string, finalStatus: ProposalEndStatus | null, commentForUser: string | null, commentForManagement: string | null, created: any, updated: any, callId: number, questionaryId: number, notified: boolean, submitted: boolean, managementTimeAllocation: number | null, managementDecisionSubmitted: boolean, proposer: { id: number, firstname: string, lastname: string, preferredname: string | null, organisation: string, organizationId: number, position: string, created: any | null, placeholder: boolean | null } | null, users: Array<{ id: number, firstname: string, lastname: string, preferredname: string | null, organisation: string, organizationId: number, position: string, created: any | null, placeholder: boolean | null }>, questionary: { isCompleted: boolean, questionaryId: number, templateId: number, created: any, steps: Array<{ isCompleted: boolean, topic: { title: string, id: number, templateId: number, sortOrder: number, isEnabled: boolean }, fields: Array<{ answerId: number | null, sortOrder: number, topicId: number, dependenciesOperator: DependenciesLogicOperator | null, value: any | null, question: { id: string, question: string, naturalKey: string, dataType: DataType, categoryId: TemplateCategoryId, config: { small_label: string, required: boolean, tooltip: string } | { small_label: string, required: boolean, tooltip: string, minDate: string | null, maxDate: string | null, defaultDate: string | null, includeTime: boolean } | { html: string, plain: string, omitFromPdf: boolean } | { small_label: string, required: boolean, tooltip: string } | { file_type: Array, max_files: number, pdf_page_limit: number, small_label: string, required: boolean, tooltip: string } | { titlePlaceholder: string, questionLabel: string } | { small_label: string, required: boolean, tooltip: string, units: Array<{ id: string, unit: string, quantity: string, symbol: string, siConversionFormula: string }> } | { numberValueConstraint: NumberValueConstraint | null, small_label: string, required: boolean, tooltip: string, units: Array<{ id: string, unit: string, quantity: string, symbol: string, siConversionFormula: string }> } | { tooltip: string } | { tooltip: string } | { small_label: string, required: boolean, tooltip: string, max: number | null } | { titlePlaceholder: string } | { addEntryButtonLabel: string, minEntries: number | null, maxEntries: number | null, templateId: number | null, esiTemplateId: number | null, templateCategory: string, required: boolean, small_label: string } | { tooltip: string } | { variant: string, options: Array, isMultipleSelect: boolean, small_label: string, required: boolean, tooltip: string } | { small_label: string, required: boolean, tooltip: string } | { addEntryButtonLabel: string, minEntries: number | null, maxEntries: number | null, templateId: number | null, templateCategory: string, required: boolean, small_label: string } | { min: number | null, max: number | null, multiline: boolean, placeholder: string, small_label: string, required: boolean, tooltip: string, htmlQuestion: string | null, isHtmlQuestion: boolean, isCounterHidden: boolean } | { small_label: string, required: boolean, tooltip: string } }, config: { small_label: string, required: boolean, tooltip: string } | { small_label: string, required: boolean, tooltip: string, minDate: string | null, maxDate: string | null, defaultDate: string | null, includeTime: boolean } | { html: string, plain: string, omitFromPdf: boolean } | { small_label: string, required: boolean, tooltip: string } | { file_type: Array, max_files: number, pdf_page_limit: number, small_label: string, required: boolean, tooltip: string } | { titlePlaceholder: string, questionLabel: string } | { small_label: string, required: boolean, tooltip: string, units: Array<{ id: string, unit: string, quantity: string, symbol: string, siConversionFormula: string }> } | { numberValueConstraint: NumberValueConstraint | null, small_label: string, required: boolean, tooltip: string, units: Array<{ id: string, unit: string, quantity: string, symbol: string, siConversionFormula: string }> } | { tooltip: string } | { tooltip: string } | { small_label: string, required: boolean, tooltip: string, max: number | null } | { titlePlaceholder: string } | { addEntryButtonLabel: string, minEntries: number | null, maxEntries: number | null, templateId: number | null, esiTemplateId: number | null, templateCategory: string, required: boolean, small_label: string } | { tooltip: string } | { variant: string, options: Array, isMultipleSelect: boolean, small_label: string, required: boolean, tooltip: string } | { small_label: string, required: boolean, tooltip: string } | { addEntryButtonLabel: string, minEntries: number | null, maxEntries: number | null, templateId: number | null, templateCategory: string, required: boolean, small_label: string } | { min: number | null, max: number | null, multiline: boolean, placeholder: string, small_label: string, required: boolean, tooltip: string, htmlQuestion: string | null, isHtmlQuestion: boolean, isCounterHidden: boolean } | { small_label: string, required: boolean, tooltip: string }, dependencies: Array<{ questionId: string, dependencyId: string, dependencyNaturalKey: string, condition: { condition: EvaluatorOperator, params: any } }> }> }> }, technicalReview: { id: number, comment: string | null, publicComment: string | null, timeAllocation: number | null, status: TechnicalReviewStatus | null, proposalPk: number, submitted: boolean, files: string | null, technicalReviewAssigneeId: number | null, technicalReviewAssignee: { id: number, firstname: string, lastname: string } | null } | null, reviews: Array<{ id: number, grade: number | null, comment: string | null, status: ReviewStatus, userID: number, sepID: number, reviewer: { firstname: string, lastname: string, id: number } | null }> | null, instrument: { id: number, name: string, shortCode: string } | null, call: { id: number, shortCode: string, isActive: boolean, referenceNumberFormat: string | null, startCall: any, endCall: any } | null, status: { id: number, shortCode: string, name: string, description: string, isDefault: boolean } | null, sepMeetingDecision: { proposalPk: number, recommendation: ProposalEndStatus | null, commentForUser: string | null, commentForManagement: string | null, rankOrder: number | null, submitted: boolean, submittedBy: number | null } | null }> | null, rejection: { reason: string, context: string | null, exception: string | null } | null } }; export type CreateProposalMutationVariables = Exact<{ callId: Scalars['Int']; @@ -3945,7 +3945,7 @@ export type GetProposalQueryVariables = Exact<{ }>; -export type GetProposalQuery = { proposal: { primaryKey: number, title: string, abstract: string, statusId: number, publicStatus: ProposalPublicStatus, proposalId: string, finalStatus: ProposalEndStatus | null, commentForUser: string | null, commentForManagement: string | null, created: any, updated: any, callId: number, questionaryId: number, notified: boolean, submitted: boolean, managementTimeAllocation: number | null, managementDecisionSubmitted: boolean, proposer: { id: number, firstname: string, lastname: string, preferredname: string | null, organisation: string, organizationId: number, position: string, created: any | null, placeholder: boolean | null } | null, users: Array<{ id: number, firstname: string, lastname: string, preferredname: string | null, organisation: string, organizationId: number, position: string, created: any | null, placeholder: boolean | null }>, questionary: { isCompleted: boolean, questionaryId: number, templateId: number, created: any, steps: Array<{ isCompleted: boolean, topic: { title: string, id: number, templateId: number, sortOrder: number, isEnabled: boolean }, fields: Array<{ answerId: number | null, sortOrder: number, topicId: number, dependenciesOperator: DependenciesLogicOperator | null, value: any | null, question: { id: string, question: string, naturalKey: string, dataType: DataType, categoryId: TemplateCategoryId, config: { small_label: string, required: boolean, tooltip: string } | { small_label: string, required: boolean, tooltip: string, minDate: string | null, maxDate: string | null, defaultDate: string | null, includeTime: boolean } | { html: string, plain: string, omitFromPdf: boolean } | { small_label: string, required: boolean, tooltip: string } | { file_type: Array, max_files: number, pdf_page_limit: number, small_label: string, required: boolean, tooltip: string } | { titlePlaceholder: string, questionLabel: string } | { small_label: string, required: boolean, tooltip: string, units: Array<{ id: string, unit: string, quantity: string, symbol: string, siConversionFormula: string }> } | { numberValueConstraint: NumberValueConstraint | null, small_label: string, required: boolean, tooltip: string, units: Array<{ id: string, unit: string, quantity: string, symbol: string, siConversionFormula: string }> } | { tooltip: string } | { tooltip: string } | { small_label: string, required: boolean, tooltip: string, max: number | null } | { titlePlaceholder: string } | { addEntryButtonLabel: string, minEntries: number | null, maxEntries: number | null, templateId: number | null, esiTemplateId: number | null, templateCategory: string, required: boolean, small_label: string } | { tooltip: string } | { variant: string, options: Array, isMultipleSelect: boolean, small_label: string, required: boolean, tooltip: string } | { small_label: string, required: boolean, tooltip: string } | { addEntryButtonLabel: string, minEntries: number | null, maxEntries: number | null, templateId: number | null, templateCategory: string, required: boolean, small_label: string } | { min: number | null, max: number | null, multiline: boolean, placeholder: string, small_label: string, required: boolean, tooltip: string, htmlQuestion: string | null, isHtmlQuestion: boolean, isCounterHidden: boolean } | { small_label: string, required: boolean, tooltip: string } }, config: { small_label: string, required: boolean, tooltip: string } | { small_label: string, required: boolean, tooltip: string, minDate: string | null, maxDate: string | null, defaultDate: string | null, includeTime: boolean } | { html: string, plain: string, omitFromPdf: boolean } | { small_label: string, required: boolean, tooltip: string } | { file_type: Array, max_files: number, pdf_page_limit: number, small_label: string, required: boolean, tooltip: string } | { titlePlaceholder: string, questionLabel: string } | { small_label: string, required: boolean, tooltip: string, units: Array<{ id: string, unit: string, quantity: string, symbol: string, siConversionFormula: string }> } | { numberValueConstraint: NumberValueConstraint | null, small_label: string, required: boolean, tooltip: string, units: Array<{ id: string, unit: string, quantity: string, symbol: string, siConversionFormula: string }> } | { tooltip: string } | { tooltip: string } | { small_label: string, required: boolean, tooltip: string, max: number | null } | { titlePlaceholder: string } | { addEntryButtonLabel: string, minEntries: number | null, maxEntries: number | null, templateId: number | null, esiTemplateId: number | null, templateCategory: string, required: boolean, small_label: string } | { tooltip: string } | { variant: string, options: Array, isMultipleSelect: boolean, small_label: string, required: boolean, tooltip: string } | { small_label: string, required: boolean, tooltip: string } | { addEntryButtonLabel: string, minEntries: number | null, maxEntries: number | null, templateId: number | null, templateCategory: string, required: boolean, small_label: string } | { min: number | null, max: number | null, multiline: boolean, placeholder: string, small_label: string, required: boolean, tooltip: string, htmlQuestion: string | null, isHtmlQuestion: boolean, isCounterHidden: boolean } | { small_label: string, required: boolean, tooltip: string }, dependencies: Array<{ questionId: string, dependencyId: string, dependencyNaturalKey: string, condition: { condition: EvaluatorOperator, params: any } }> }> }> }, technicalReview: { id: number, comment: string | null, publicComment: string | null, timeAllocation: number | null, status: TechnicalReviewStatus | null, proposalPk: number, submitted: boolean, files: string | null, technicalReviewAssigneeId: number | null, reviewer: { id: number, firstname: string, lastname: string, preferredname: string | null, organisation: string, organizationId: number, position: string, created: any | null, placeholder: boolean | null } | null, technicalReviewAssignee: { id: number, firstname: string, lastname: string } | null } | null, reviews: Array<{ id: number, grade: number | null, comment: string | null, status: ReviewStatus, userID: number, sepID: number, reviewer: { firstname: string, lastname: string, id: number } | null }> | null, instrument: { id: number, name: string, shortCode: string, beamlineManager: { id: number, firstname: string, lastname: string } | null, scientists: Array<{ id: number, firstname: string, lastname: string }> } | null, call: { id: number, shortCode: string, isActive: boolean, allocationTimeUnit: AllocationTimeUnits, referenceNumberFormat: string | null } | null, sep: { id: number, code: string } | null, samples: Array<{ id: number, title: string, creatorId: number, questionaryId: number, safetyStatus: SampleStatus, safetyComment: string, isPostProposalSubmission: boolean, created: any, proposalPk: number, questionId: string, questionary: { isCompleted: boolean } }> | null, genericTemplates: Array<{ id: number, title: string, creatorId: number, questionaryId: number, created: any, proposalPk: number, questionId: string, questionary: { isCompleted: boolean } }> | null, status: { id: number, shortCode: string, name: string, description: string, isDefault: boolean } | null, sepMeetingDecision: { proposalPk: number, recommendation: ProposalEndStatus | null, commentForUser: string | null, commentForManagement: string | null, rankOrder: number | null, submitted: boolean, submittedBy: number | null } | null } | null }; +export type GetProposalQuery = { proposal: { primaryKey: number, title: string, abstract: string, statusId: number, publicStatus: ProposalPublicStatus, proposalId: string, finalStatus: ProposalEndStatus | null, commentForUser: string | null, commentForManagement: string | null, created: any, updated: any, callId: number, questionaryId: number, notified: boolean, submitted: boolean, managementTimeAllocation: number | null, managementDecisionSubmitted: boolean, proposer: { id: number, firstname: string, lastname: string, preferredname: string | null, organisation: string, organizationId: number, position: string, created: any | null, placeholder: boolean | null } | null, users: Array<{ id: number, firstname: string, lastname: string, preferredname: string | null, organisation: string, organizationId: number, position: string, created: any | null, placeholder: boolean | null }>, questionary: { isCompleted: boolean, questionaryId: number, templateId: number, created: any, steps: Array<{ isCompleted: boolean, topic: { title: string, id: number, templateId: number, sortOrder: number, isEnabled: boolean }, fields: Array<{ answerId: number | null, sortOrder: number, topicId: number, dependenciesOperator: DependenciesLogicOperator | null, value: any | null, question: { id: string, question: string, naturalKey: string, dataType: DataType, categoryId: TemplateCategoryId, config: { small_label: string, required: boolean, tooltip: string } | { small_label: string, required: boolean, tooltip: string, minDate: string | null, maxDate: string | null, defaultDate: string | null, includeTime: boolean } | { html: string, plain: string, omitFromPdf: boolean } | { small_label: string, required: boolean, tooltip: string } | { file_type: Array, max_files: number, pdf_page_limit: number, small_label: string, required: boolean, tooltip: string } | { titlePlaceholder: string, questionLabel: string } | { small_label: string, required: boolean, tooltip: string, units: Array<{ id: string, unit: string, quantity: string, symbol: string, siConversionFormula: string }> } | { numberValueConstraint: NumberValueConstraint | null, small_label: string, required: boolean, tooltip: string, units: Array<{ id: string, unit: string, quantity: string, symbol: string, siConversionFormula: string }> } | { tooltip: string } | { tooltip: string } | { small_label: string, required: boolean, tooltip: string, max: number | null } | { titlePlaceholder: string } | { addEntryButtonLabel: string, minEntries: number | null, maxEntries: number | null, templateId: number | null, esiTemplateId: number | null, templateCategory: string, required: boolean, small_label: string } | { tooltip: string } | { variant: string, options: Array, isMultipleSelect: boolean, small_label: string, required: boolean, tooltip: string } | { small_label: string, required: boolean, tooltip: string } | { addEntryButtonLabel: string, minEntries: number | null, maxEntries: number | null, templateId: number | null, templateCategory: string, required: boolean, small_label: string } | { min: number | null, max: number | null, multiline: boolean, placeholder: string, small_label: string, required: boolean, tooltip: string, htmlQuestion: string | null, isHtmlQuestion: boolean, isCounterHidden: boolean } | { small_label: string, required: boolean, tooltip: string } }, config: { small_label: string, required: boolean, tooltip: string } | { small_label: string, required: boolean, tooltip: string, minDate: string | null, maxDate: string | null, defaultDate: string | null, includeTime: boolean } | { html: string, plain: string, omitFromPdf: boolean } | { small_label: string, required: boolean, tooltip: string } | { file_type: Array, max_files: number, pdf_page_limit: number, small_label: string, required: boolean, tooltip: string } | { titlePlaceholder: string, questionLabel: string } | { small_label: string, required: boolean, tooltip: string, units: Array<{ id: string, unit: string, quantity: string, symbol: string, siConversionFormula: string }> } | { numberValueConstraint: NumberValueConstraint | null, small_label: string, required: boolean, tooltip: string, units: Array<{ id: string, unit: string, quantity: string, symbol: string, siConversionFormula: string }> } | { tooltip: string } | { tooltip: string } | { small_label: string, required: boolean, tooltip: string, max: number | null } | { titlePlaceholder: string } | { addEntryButtonLabel: string, minEntries: number | null, maxEntries: number | null, templateId: number | null, esiTemplateId: number | null, templateCategory: string, required: boolean, small_label: string } | { tooltip: string } | { variant: string, options: Array, isMultipleSelect: boolean, small_label: string, required: boolean, tooltip: string } | { small_label: string, required: boolean, tooltip: string } | { addEntryButtonLabel: string, minEntries: number | null, maxEntries: number | null, templateId: number | null, templateCategory: string, required: boolean, small_label: string } | { min: number | null, max: number | null, multiline: boolean, placeholder: string, small_label: string, required: boolean, tooltip: string, htmlQuestion: string | null, isHtmlQuestion: boolean, isCounterHidden: boolean } | { small_label: string, required: boolean, tooltip: string }, dependencies: Array<{ questionId: string, dependencyId: string, dependencyNaturalKey: string, condition: { condition: EvaluatorOperator, params: any } }> }> }> }, technicalReview: { id: number, comment: string | null, publicComment: string | null, timeAllocation: number | null, status: TechnicalReviewStatus | null, proposalPk: number, submitted: boolean, files: string | null, technicalReviewAssigneeId: number | null, reviewer: { id: number, firstname: string, lastname: string, preferredname: string | null, organisation: string, organizationId: number, position: string, created: any | null, placeholder: boolean | null } | null, technicalReviewAssignee: { id: number, firstname: string, lastname: string } | null } | null, reviews: Array<{ id: number, grade: number | null, comment: string | null, status: ReviewStatus, userID: number, sepID: number, reviewer: { firstname: string, lastname: string, id: number } | null }> | null, instrument: { id: number, name: string, shortCode: string, beamlineManager: { id: number, firstname: string, lastname: string } | null, scientists: Array<{ id: number, firstname: string, lastname: string }> } | null, call: { id: number, shortCode: string, isActive: boolean, allocationTimeUnit: AllocationTimeUnits, referenceNumberFormat: string | null, startCall: any, endCall: any } | null, sep: { id: number, code: string } | null, samples: Array<{ id: number, title: string, creatorId: number, questionaryId: number, safetyStatus: SampleStatus, safetyComment: string, isPostProposalSubmission: boolean, created: any, proposalPk: number, questionId: string, questionary: { isCompleted: boolean } }> | null, genericTemplates: Array<{ id: number, title: string, creatorId: number, questionaryId: number, created: any, proposalPk: number, questionId: string, questionary: { isCompleted: boolean } }> | null, status: { id: number, shortCode: string, name: string, description: string, isDefault: boolean } | null, sepMeetingDecision: { proposalPk: number, recommendation: ProposalEndStatus | null, commentForUser: string | null, commentForManagement: string | null, rankOrder: number | null, submitted: boolean, submittedBy: number | null } | null } | null }; export type GetProposalsQueryVariables = Exact<{ filter?: InputMaybe; @@ -4899,7 +4899,7 @@ export type GetUserMeQuery = { me: { user_title: string, username: string, first export type GetUserProposalsQueryVariables = Exact<{ [key: string]: never; }>; -export type GetUserProposalsQuery = { me: { proposals: Array<{ primaryKey: number, proposalId: string, title: string, publicStatus: ProposalPublicStatus, statusId: number, created: any, finalStatus: ProposalEndStatus | null, notified: boolean, submitted: boolean, status: { id: number, shortCode: string, name: string, description: string, isDefault: boolean } | null, proposer: { id: number } | null, call: { id: number, shortCode: string, isActive: boolean, referenceNumberFormat: string | null } | null }> } | null }; +export type GetUserProposalsQuery = { me: { proposals: Array<{ primaryKey: number, proposalId: string, title: string, publicStatus: ProposalPublicStatus, statusId: number, created: any, finalStatus: ProposalEndStatus | null, notified: boolean, submitted: boolean, status: { id: number, shortCode: string, name: string, description: string, isDefault: boolean } | null, proposer: { id: number } | null, call: { id: number, shortCode: string, isActive: boolean, referenceNumberFormat: string | null, startCall: any, endCall: any } | null }> } | null }; export type GetUserWithRolesQueryVariables = Exact<{ id: Scalars['Int']; @@ -6883,6 +6883,8 @@ export const CloneProposalsDocument = gql` shortCode isActive referenceNumberFormat + startCall + endCall } } rejection { @@ -7041,6 +7043,8 @@ export const GetProposalDocument = gql` isActive allocationTimeUnit referenceNumberFormat + startCall + endCall } sep { id @@ -8816,6 +8820,8 @@ export const GetUserProposalsDocument = gql` shortCode isActive referenceNumberFormat + startCall + endCall } } } diff --git a/src/graphql/proposal/cloneProposals.graphql b/src/graphql/proposal/cloneProposals.graphql index f275e99a7..dd0d3e58a 100644 --- a/src/graphql/proposal/cloneProposals.graphql +++ b/src/graphql/proposal/cloneProposals.graphql @@ -43,6 +43,8 @@ mutation cloneProposals($proposalsToClonePk: [Int!]!, $callId: Int!) { shortCode isActive referenceNumberFormat + startCall + endCall } } rejection { diff --git a/src/graphql/proposal/getProposal.graphql b/src/graphql/proposal/getProposal.graphql index 7797e682b..769f9a6a4 100644 --- a/src/graphql/proposal/getProposal.graphql +++ b/src/graphql/proposal/getProposal.graphql @@ -51,6 +51,8 @@ query getProposal($primaryKey: Int!) { isActive allocationTimeUnit referenceNumberFormat + startCall + endCall } sep { id diff --git a/src/graphql/user/getUserProposals.graphql b/src/graphql/user/getUserProposals.graphql index 4e6b12724..3682dafb8 100644 --- a/src/graphql/user/getUserProposals.graphql +++ b/src/graphql/user/getUserProposals.graphql @@ -21,6 +21,8 @@ query getUserProposals { shortCode isActive referenceNumberFormat + startCall + endCall } } } diff --git a/src/models/questionary/proposal/ProposalWithQuestionary.ts b/src/models/questionary/proposal/ProposalWithQuestionary.ts index 9d87ef9c2..d016786af 100644 --- a/src/models/questionary/proposal/ProposalWithQuestionary.ts +++ b/src/models/questionary/proposal/ProposalWithQuestionary.ts @@ -20,7 +20,11 @@ export type ProposalWithQuestionary = Pick< | 'callId' | 'questionaryId' | 'submitted' -> & { call?: Maybe> } & { +> & { + call?: Maybe< + Pick + >; +} & { samples: Maybe< (SampleFragment & { questionary: Pick })[] >; diff --git a/src/utils/helperFunctions.ts b/src/utils/helperFunctions.ts index f9f68470f..aa6b5f42a 100644 --- a/src/utils/helperFunctions.ts +++ b/src/utils/helperFunctions.ts @@ -5,7 +5,12 @@ import { } from '@user-office-software/duo-localisation'; import { SortDirectionType } from 'components/common/SuperMaterialTable'; -import { Proposal, ProposalEndStatus, ProposalStatus } from 'generated/sdk'; +import { + Proposal, + ProposalEndStatus, + ProposalStatus, + Scalars, +} from 'generated/sdk'; import { ProposalViewData } from 'hooks/proposal/useProposalsCoreData'; import { @@ -120,3 +125,14 @@ export const removeColumns = ( } }); }; + +export const isCallEnded = ( + startDate: Scalars['DateTime'], + endDate: Scalars['DateTime'] +) => { + const now = new Date(); + const startCall = new Date(startDate); + const endCall = new Date(endDate); + + return startCall >= now || endCall <= now; +}; From c57f57133ea8eaddb9241cd026da18f1db622e37 Mon Sep 17 00:00:00 2001 From: Martin Trajanovski Date: Tue, 28 Jun 2022 08:41:51 +0200 Subject: [PATCH 3/3] revert back removed imports --- cypress/integration/templates.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cypress/integration/templates.ts b/cypress/integration/templates.ts index a30e984ea..7ade65756 100644 --- a/cypress/integration/templates.ts +++ b/cypress/integration/templates.ts @@ -1,4 +1,7 @@ +import path from 'path'; + import faker, { lorem } from 'faker'; +import { DateTime } from 'luxon'; import { DataType,