Skip to content

Commit ad1f180

Browse files
Merge pull request #979 from fossa-app/update-offboarding-instructions
update: Enhance company offboarding instructions page, disable compan…
2 parents f393610 + d8b0b44 commit ad1f180

35 files changed

Lines changed: 210 additions & 100 deletions

cypress/e2e/Department/DepartmentCatalog.cy.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ describe('Department Catalog Tests', () => {
300300
);
301301
});
302302

303-
it(`should ${isAdminRole ? '' : 'not '}be able to manually navigate to department management page`, () => {
303+
it(`should ${isAdminRole ? '' : 'not '}be able to manually navigate to the Department Management page`, () => {
304304
interceptFetchDepartmentsRequest();
305305
interceptFetchEmployeesRequest();
306306
interceptFetchEmployeesByIdsRequest({ ids: [333333333335, 333333333334, 333333333333] });
@@ -314,7 +314,7 @@ describe('Department Catalog Tests', () => {
314314
});
315315
});
316316

317-
it('should be able to navigate by buttons to the department view page', () => {
317+
it('should be able to navigate by buttons to the View Department page', () => {
318318
interceptFetchDepartmentsRequest();
319319
interceptFetchEmployeesByIdsRequest({ ids: [333333333335, 333333333334, 333333333333] });
320320
interceptFetchDepartmentsByIdsRequest({ ids: [444444444444] });
@@ -367,7 +367,7 @@ describe('Department Catalog Tests', () => {
367367
);
368368
});
369369

370-
it('should be able to navigate to the department view page by clicking the department name cell', () => {
370+
it('should be able to navigate to the View Department page by clicking the department name cell', () => {
371371
interceptFetchDepartmentsRequest();
372372
interceptFetchEmployeesByIdsRequest({ ids: [333333333335, 333333333334, 333333333333] });
373373
interceptFetchDepartmentsByIdsRequest({ ids: [444444444444] });
@@ -456,7 +456,7 @@ describe('Department Catalog Tests', () => {
456456
getTestSelectorByModule(Module.departmentManagement, SubModule.departmentCatalog, 'table-body-row', true).should('have.length', 5);
457457
});
458458

459-
it('should be able to navigate by buttons to the department management page', () => {
459+
it('should be able to navigate by buttons to the Department Management page', () => {
460460
interceptFetchDepartmentsRequest();
461461
interceptFetchEmployeesByIdsRequest({ ids: [333333333335, 333333333334, 333333333333] });
462462
interceptFetchDepartmentsByIdsRequest({ ids: [444444444444] });
@@ -528,6 +528,26 @@ describe('Department Catalog Tests', () => {
528528
'not.exist'
529529
);
530530
getLinearLoader(Module.departmentManagement, SubModule.departmentCatalog, 'table').should('not.exist');
531+
532+
interceptFetchEmployeesRequest(
533+
{ pageNumber: 1, pageSize: 10 },
534+
{ alias: 'fetchEmployeesRequest', fixture: 'employee/employees-multiple' }
535+
);
536+
537+
getTestSelectorByModule(Module.departmentManagement, SubModule.departmentCatalog, 'table-layout-action-button').click();
538+
getTestSelectorByModule(Module.departmentManagement, SubModule.departmentDetails, 'form-field-parentDepartmentId').click();
539+
540+
getTestSelectorByModule(
541+
Module.departmentManagement,
542+
SubModule.departmentDetails,
543+
'form-field-parentDepartmentId-option',
544+
true
545+
).should('have.length', 4);
546+
getTestSelectorByModule(
547+
Module.departmentManagement,
548+
SubModule.departmentDetails,
549+
'form-field-parentDepartmentId-option-444444444448'
550+
).should('not.exist');
531551
});
532552
});
533553
});

cypress/e2e/Department/DepartmentManagement.cy.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ describe('Department Management Tests', () => {
155155
cy.url().should('include', ROUTES.newDepartment.path);
156156
});
157157

158-
it('should be able to create a new department and be navigated back to department catalog page if the form is valid and the department creation succeeded', () => {
158+
it('should be able to create a new department and be navigated back to the Department Catalog page if the form is valid and the department creation succeeded', () => {
159159
interceptFetchDepartmentsRequest();
160160
interceptFetchEmployeesByIdsRequest({ ids: [333333333335, 333333333334, 333333333333] });
161161
interceptFetchEmployeesByIdsRequest({ ids: [333333333335, 333333333334] });
@@ -198,9 +198,20 @@ describe('Department Management Tests', () => {
198198
'have.text',
199199
'Set Design'
200200
);
201+
202+
getTestSelectorByModule(Module.departmentManagement, SubModule.departmentCatalog, 'table-layout-action-button').click();
203+
getTestSelectorByModule(Module.departmentManagement, SubModule.departmentDetails, 'form-field-parentDepartmentId').click();
204+
205+
getTestSelectorByModule(Module.departmentManagement, SubModule.departmentDetails, 'form-field-parentDepartmentId-option', true).should(
206+
'have.length',
207+
5
208+
);
209+
getTestSelectorByModule(Module.departmentManagement, SubModule.departmentDetails, 'form-field-parentDepartmentId-option-444444444448')
210+
.should('exist')
211+
.and('have.text', 'Set Design');
201212
});
202213

203-
it('should display not found page if the department was not found', () => {
214+
it('should display Not Found page if the department was not found', () => {
204215
interceptFetchDepartmentsRequest();
205216
interceptFetchEmployeesByIdsRequest({ ids: [333333333335, 333333333334, 333333333333] });
206217
interceptFetchDepartmentsByIdsRequest({ ids: [444444444444] });
@@ -214,7 +225,7 @@ describe('Department Management Tests', () => {
214225
cy.location('pathname').should('eq', ROUTES.flows.path);
215226
});
216227

217-
it('should reset the form and be navigated back to the department catalog page if the cancel button is clicked', () => {
228+
it('should reset the form and be navigated back to the Department Catalog page if the cancel button is clicked', () => {
218229
interceptFetchDepartmentsRequest();
219230
interceptFetchEmployeesByIdsRequest({ ids: [333333333335, 333333333334, 333333333333] });
220231
interceptFetchDepartmentsByIdsRequest({ ids: [444444444444] });
@@ -359,7 +370,7 @@ describe('Department Management Tests', () => {
359370
.and('contain.text', 'Failed to create a Department');
360371
});
361372

362-
it('should be able to edit the department and be navigated back to the department catalog page if the form is valid and department updating succeeded', () => {
373+
it('should be able to edit the department and be navigated back to the Department Catalog page if the form is valid and department updating succeeded', () => {
363374
interceptFetchDepartmentsRequest();
364375
interceptFetchEmployeesByIdsRequest({ ids: [333333333335, 333333333334, 333333333333] });
365376
interceptFetchDepartmentsByIdsRequest({ ids: [444444444444] });
@@ -429,6 +440,17 @@ describe('Department Management Tests', () => {
429440
getTestSelectorByModule(Module.shared, SubModule.snackbar, 'success')
430441
.should('exist')
431442
.and('contain.text', 'Department has been successfully updated');
443+
444+
getTestSelectorByModule(Module.departmentManagement, SubModule.departmentCatalog, 'table-layout-action-button').click();
445+
getTestSelectorByModule(Module.departmentManagement, SubModule.departmentDetails, 'form-field-parentDepartmentId').click();
446+
447+
getTestSelectorByModule(Module.departmentManagement, SubModule.departmentDetails, 'form-field-parentDepartmentId-option', true).should(
448+
'have.length',
449+
4
450+
);
451+
getTestSelectorByModule(Module.departmentManagement, SubModule.departmentDetails, 'form-field-parentDepartmentId-option-444444444447')
452+
.should('exist')
453+
.and('have.text', 'Costume Updated');
432454
});
433455

434456
it('should be able to navigate back when the back button is clicked', () => {

cypress/e2e/Onboarding.cy.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ describe('Onboarding Flow Tests', () => {
193193
'have.attr',
194194
'disabled'
195195
);
196+
getTestSelectorByModule(Module.uploadCompanyLicense, SubModule.companyLicenseDetails, 'form-cancel-button').should(
197+
'have.attr',
198+
'disabled'
199+
);
196200
}
197201

198202
getTestSelectorByModule(Module.shared, SubModule.header, 'menu-icon').should('have.attr', 'disabled');

src/components/UI/FileUpload.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ import { Module, SubModule } from 'shared/models';
88
export type FileUploadProps = {
99
module: Module;
1010
subModule: SubModule;
11+
disabled?: boolean;
1112
accept?: string;
1213
file?: File;
1314
onFileSelect: (file: File) => void;
1415
} & BoxProps;
1516

16-
const FileUpload: React.FC<FileUploadProps> = ({ module, subModule, file, accept = '*/*', onFileSelect, ...props }) => {
17+
const FileUpload: React.FC<FileUploadProps> = ({ module, subModule, file, accept = '*/*', disabled, onFileSelect, ...props }) => {
1718
const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
1819
const selectedFile = event.target.files?.[0];
1920

@@ -25,8 +26,8 @@ const FileUpload: React.FC<FileUploadProps> = ({ module, subModule, file, accept
2526
return (
2627
<Box sx={{ display: 'flex', alignItems: 'center', gap: 2, ...props.sx }} {...props}>
2728
<Input id="file-upload-input" type="file" onChange={handleFileChange} inputProps={{ accept }} style={{ display: 'none' }} />
28-
<label htmlFor="file-upload-input">
29-
<Button aria-label="Choose File" variant="contained" component="span">
29+
<label htmlFor="file-upload-input" style={{ pointerEvents: disabled ? 'none' : 'auto' }}>
30+
<Button aria-label="Choose File" variant="contained" component="span" disabled={disabled}>
3031
Choose File
3132
</Button>
3233
</label>

src/components/UI/Form/Form.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const Form = <T extends Item>({
5151
}, [watchedValues, onChange]);
5252

5353
return (
54-
<FormContext.Provider value={{ module, subModule }}>
54+
<FormContext.Provider value={{ module, subModule, loading }}>
5555
<ReactHookFormProvider {...methods}>
5656
<Paper
5757
data-cy={`${module}-${subModule}-form`}

src/components/UI/Form/FormContent.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,19 @@ const FormContent = <T,>({ fields, values, children }: FormContentProps<T>) => {
2929
throw new Error('FormContent must be used within a Form component using FormContext.');
3030
}
3131

32-
const { module, subModule } = context;
32+
const { module, subModule, loading } = context;
3333
const {
3434
formState: { errors },
3535
} = reactHookFormContext();
3636
const generalErrorMessage = getGeneralErrorMessage<T>(errors, fields);
3737

38-
// TODO: hide form content while loading, cleanup CompanyOffboardingInstructionsPage
38+
if (loading) {
39+
return null;
40+
}
41+
3942
return (
4043
<Box sx={{ display: 'flex', flexDirection: 'column', justifyContent: 'space-between', flexGrow: 1, padding: 6, overflowY: 'auto' }}>
41-
{fields ? (
44+
{fields?.length ? (
4245
<Grid container spacing={4}>
4346
{fields.map((field) => (
4447
<Grid key={field.name} {...field.grid}>

src/components/UI/Form/FormContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import { Module, SubModule } from 'shared/models';
33

4-
const FormContext = React.createContext<{ module: Module; subModule: SubModule } | undefined>(undefined);
4+
const FormContext = React.createContext<{ module: Module; subModule: SubModule; loading: boolean } | undefined>(undefined);
55

66
export const useFormContext = () => {
77
const context = React.useContext(FormContext);

src/components/UI/Form/fields/FileUploadField.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const FileUploadField: React.FC<FileUploadFieldProps> = ({ name, label, ...props
2323
module={module}
2424
subModule={subModule}
2525
file={value}
26+
disabled={props.disabled}
2627
onFileSelect={(file: File) => {
2728
onChange(file);
2829
onBlur();

src/components/UI/Form/form.model.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { GridBaseProps } from '@mui/material/Grid2';
1010
import { TypographyProps } from '@mui/material/Typography';
1111
import { Module, SubModule, ThemeMode, UserRole } from 'shared/models';
1212
import { LoadingButtonProps } from '../LoadingButton';
13-
import { FileUploadProps } from '../FileUpload';
1413

1514
type Validate<T> = {
1615
[key: string]: (value: T) => boolean | string | Promise<boolean | string>;
@@ -104,8 +103,9 @@ export type SwitchFieldProps = BaseFormFieldProps & {
104103
export type FileUploadFieldProps = BaseFormFieldProps & {
105104
type: FormFieldType.fileUpload;
106105
accept?: string;
106+
disabled?: boolean;
107107
onFileSelect?: (file: File) => void;
108-
} & Partial<FileUploadProps>;
108+
};
109109

110110
export type ColorSchemeFieldProps = BaseFormFieldProps & {
111111
type: FormFieldType.colorScheme;

src/components/UI/CopyableField.tsx renamed to src/components/UI/helpers/renderCopyableField.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import Typography from '@mui/material/Typography';
44
import { Module, SubModule } from 'shared/models';
55
import CopyToClipboard from 'components/UI/CopyToClipboard';
66

7-
interface CopyableFieldProps {
7+
interface CopyableFieldParams {
88
module: Module;
99
subModule: SubModule;
1010
text: string;
1111
label?: string;
1212
}
1313

14-
export const renderCopyableField: React.FC<CopyableFieldProps> = ({ module, subModule, label, text }) => (
14+
export const renderCopyableField: React.FC<CopyableFieldParams> = ({ module, subModule, label, text }) => (
1515
<>
1616
{label && (
1717
<Typography data-cy={`${module}-${subModule}-copyable-field-label`} variant="body2" color="textSecondary">

0 commit comments

Comments
 (0)