Skip to content

Commit

Permalink
fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoGuarnaccia5 committed Nov 15, 2023
1 parent 166237b commit 9d885f6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 40 deletions.
78 changes: 42 additions & 36 deletions src/manufacturer/manufacturerDialog.component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('Add manufacturer dialog', () => {
open: true,
onClose: onClose,
onChangeManufacturerDetails: onChangeManufacturerDetails,
manufacturer: {
manufacturerDetails: {
name: '',
url: undefined,
address: {
Expand Down Expand Up @@ -55,7 +55,7 @@ describe('Add manufacturer dialog', () => {
});

it('adds manufacturer correctly', async () => {
props.manufacturer = {
props.manufacturerDetails = {
name: 'Manufacturer D',
url: 'http://test.co.uk',
address: {
Expand Down Expand Up @@ -99,7 +99,7 @@ describe('Add manufacturer dialog', () => {
});

it('duplicate manufacturer name displays warning message', async () => {
props.manufacturer = {
props.manufacturerDetails = {
name: 'Manufacturer A',
url: 'http://test.co.uk',
address: {
Expand Down Expand Up @@ -141,7 +141,7 @@ describe('Add manufacturer dialog', () => {
});

it('invalid url displays error', async () => {
props.manufacturer = {
props.manufacturerDetails = {
name: 'Manufacturer D',
url: 'invalid',
address: {
Expand Down Expand Up @@ -175,7 +175,7 @@ describe('Add manufacturer dialog', () => {
});

expect(onChangeManufacturerDetails).toHaveBeenCalledWith({
...props.manufacturer,
...props.manufacturerDetails,
name: newManufacturerName,
});
});
Expand All @@ -192,7 +192,7 @@ describe('Add manufacturer dialog', () => {
});

expect(onChangeManufacturerDetails).toHaveBeenCalledWith({
...props.manufacturer,
...props.manufacturerDetails,
url: newManufacturerURL,
});
});
Expand All @@ -209,9 +209,9 @@ describe('Add manufacturer dialog', () => {
});

expect(onChangeManufacturerDetails).toHaveBeenCalledWith({
...props.manufacturer,
...props.manufacturerDetails,
address: {
...props.manufacturer.address,
...props.manufacturerDetails.address,
country: newManufacturerCountry,
},
});
Expand All @@ -230,9 +230,9 @@ describe('Add manufacturer dialog', () => {
});

expect(onChangeManufacturerDetails).toHaveBeenCalledWith({
...props.manufacturer,
...props.manufacturerDetails,
address: {
...props.manufacturer.address,
...props.manufacturerDetails.address,
address_line: newManufacturerAddressLine,
},
});
Expand All @@ -250,8 +250,11 @@ describe('Add manufacturer dialog', () => {
});

expect(onChangeManufacturerDetails).toHaveBeenCalledWith({
...props.manufacturer,
address: { ...props.manufacturer.address, town: newManufacturerTown },
...props.manufacturerDetails,
address: {
...props.manufacturerDetails.address,
town: newManufacturerTown,
},
});
});

Expand All @@ -267,9 +270,9 @@ describe('Add manufacturer dialog', () => {
});

expect(onChangeManufacturerDetails).toHaveBeenCalledWith({
...props.manufacturer,
...props.manufacturerDetails,
address: {
...props.manufacturer.address,
...props.manufacturerDetails.address,
county: newManufacturerCounty,
},
});
Expand All @@ -287,9 +290,9 @@ describe('Add manufacturer dialog', () => {
});

expect(onChangeManufacturerDetails).toHaveBeenCalledWith({
...props.manufacturer,
...props.manufacturerDetails,
address: {
...props.manufacturer.address,
...props.manufacturerDetails.address,
postcode: newManufacturerpostcode,
},
});
Expand All @@ -308,7 +311,7 @@ describe('Add manufacturer dialog', () => {
});

expect(onChangeManufacturerDetails).toHaveBeenCalledWith({
...props.manufacturer,
...props.manufacturerDetails,
telephone: newManufacturerTelephone,
});
});
Expand Down Expand Up @@ -342,7 +345,7 @@ describe('Add manufacturer dialog', () => {
},
};

props.manufacturer = {
props.manufacturerDetails = {
name: 'test',
url: 'https://test.co.uk',
address: {
Expand Down Expand Up @@ -393,7 +396,7 @@ describe('Add manufacturer dialog', () => {
},
telephone: '07334893348',
},
manufacturer: {
manufacturerDetails: {
name: 'Manufacturer A',
url: 'http://example.com',
address: {
Expand Down Expand Up @@ -423,7 +426,7 @@ describe('Add manufacturer dialog', () => {
it('Invalid url displays correct error message', async () => {
props = {
...props,
manufacturer: {
manufacturerDetails: {
name: 'test',
url: 'invalid',
address: {
Expand Down Expand Up @@ -462,7 +465,7 @@ describe('Add manufacturer dialog', () => {
it('Duplicate name displays error message', async () => {
props = {
...props,
manufacturer: {
manufacturerDetails: {
name: 'test_dup',
url: 'https://test.co.uk',
address: {
Expand Down Expand Up @@ -505,7 +508,7 @@ describe('Add manufacturer dialog', () => {
it('Required fields show error if they are whitespace or current value just removed', async () => {
props = {
...props,
manufacturer: {
manufacturerDetails: {
name: '',
url: 'https://test.co.uk',
address: {
Expand Down Expand Up @@ -550,7 +553,7 @@ describe('Add manufacturer dialog', () => {
it('CatchAllError request works correctly and displays refresh page message', async () => {
props = {
...props,
manufacturer: {
manufacturerDetails: {
name: 'Error 500',
url: 'https://test.co.uk',
address: {
Expand Down Expand Up @@ -609,7 +612,7 @@ describe('Add manufacturer dialog', () => {
});

expect(onChangeManufacturerDetails).toHaveBeenCalledWith({
...props.manufacturer,
...props.manufacturerDetails,
name: newManufacturerName,
});
});
Expand All @@ -626,7 +629,7 @@ describe('Add manufacturer dialog', () => {
});

expect(onChangeManufacturerDetails).toHaveBeenCalledWith({
...props.manufacturer,
...props.manufacturerDetails,
url: newManufacturerURL,
});
});
Expand All @@ -643,9 +646,9 @@ describe('Add manufacturer dialog', () => {
});

expect(onChangeManufacturerDetails).toHaveBeenCalledWith({
...props.manufacturer,
...props.manufacturerDetails,
address: {
...props.manufacturer.address,
...props.manufacturerDetails.address,
country: newManufacturerCountry,
},
});
Expand All @@ -664,9 +667,9 @@ describe('Add manufacturer dialog', () => {
});

expect(onChangeManufacturerDetails).toHaveBeenCalledWith({
...props.manufacturer,
...props.manufacturerDetails,
address: {
...props.manufacturer.address,
...props.manufacturerDetails.address,
address_line: newManufacturerAddressLine,
},
});
Expand All @@ -684,8 +687,11 @@ describe('Add manufacturer dialog', () => {
});

expect(onChangeManufacturerDetails).toHaveBeenCalledWith({
...props.manufacturer,
address: { ...props.manufacturer.address, town: newManufacturerTown },
...props.manufacturerDetails,
address: {
...props.manufacturerDetails.address,
town: newManufacturerTown,
},
});
});

Expand All @@ -701,9 +707,9 @@ describe('Add manufacturer dialog', () => {
});

expect(onChangeManufacturerDetails).toHaveBeenCalledWith({
...props.manufacturer,
...props.manufacturerDetails,
address: {
...props.manufacturer.address,
...props.manufacturerDetails.address,
county: newManufacturerCounty,
},
});
Expand All @@ -722,9 +728,9 @@ describe('Add manufacturer dialog', () => {
});

expect(onChangeManufacturerDetails).toHaveBeenCalledWith({
...props.manufacturer,
...props.manufacturerDetails,
address: {
...props.manufacturer.address,
...props.manufacturerDetails.address,
postcode: newManufacturerpostcode,
},
});
Expand All @@ -743,7 +749,7 @@ describe('Add manufacturer dialog', () => {
});

expect(onChangeManufacturerDetails).toHaveBeenCalledWith({
...props.manufacturer,
...props.manufacturerDetails,
telephone: newManufacturerTelephone,
});
});
Expand Down
4 changes: 0 additions & 4 deletions src/manufacturer/manufacturerDialog.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,6 @@ function ManufacturerDialog(props: ManufacturerDialogProps) {
}, [handleErrors, manufacturerDetails, addManufacturer, handleClose]);

const handleEditManufacturer = React.useCallback(() => {
console.log(manufacturerDetails);
console.log(selectedManufacturerData);
if (manufacturerDetails && selectedManufacturerData) {
const hasErrors = handleErrors();

Expand Down Expand Up @@ -251,8 +249,6 @@ function ManufacturerDialog(props: ManufacturerDialogProps) {
id: selectedManufacturerData?.id,
};

console.log(selectedManufacturerData);

isNameUpdated && (ManufacturerToEdit.name = manufacturerDetails.name);
isURLUpdated && (ManufacturerToEdit.url = manufacturerDetails.url);

Expand Down

0 comments on commit 9d885f6

Please sign in to comment.