-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unit tests for billing address (#17749)
- Loading branch information
Showing
6 changed files
with
454 additions
and
174 deletions.
There are no files selected for viewing
116 changes: 70 additions & 46 deletions
116
...eckout/components/opf-checkout-billing-address-form/get-address-card-content.pipe.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,70 @@ | ||
// TODO: Add unit tests | ||
|
||
// import { Address } from '@spartacus/core'; | ||
// import { Card } from '@spartacus/storefront'; | ||
// import { GetAddressCardContent } from './get-address-card-content.pipe'; | ||
|
||
// const mockedAddress: Address = { | ||
// country: { isocode: 'PL' }, | ||
// titleCode: 'mr', | ||
// firstName: 'John', | ||
// lastName: 'Doe', | ||
// line1: 'Noname street', | ||
// line2: '', | ||
// town: 'Warsaw', | ||
// postalCode: '02651', | ||
// phone: '', | ||
// cellphone: '', | ||
// defaultAddress: false, | ||
// }; | ||
|
||
// describe('GetAddressCardContent', () => { | ||
// const pipe = new GetAddressCardContent(); | ||
|
||
// it('should return empty object if address has not been provided', () => { | ||
// expect(pipe.transform(undefined as unknown as Address)).toEqual({}); | ||
// }); | ||
|
||
// it('should show region as address region iso code if iso code present', () => { | ||
// const isocode: string = 'testIso'; | ||
// const address: Address = { | ||
// ...mockedAddress, | ||
// region: { isocode }, | ||
// }; | ||
|
||
// expect(pipe.transform(address)).toContain(isocode); | ||
// }); | ||
|
||
// it('should transform address object to card object', () => { | ||
// const expectedResult: Card = { | ||
// textBold: 'John Doe', | ||
// text: ['Noname street', '', 'Warsaw, PL', '02651', ''], | ||
// }; | ||
|
||
// expect(pipe.transform(mockedAddress)).toEqual(expectedResult); | ||
// }); | ||
// }); | ||
/* | ||
* SPDX-FileCopyrightText: 2023 SAP Spartacus team <[email protected]> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { TestBed } from '@angular/core/testing'; | ||
import { Address } from '@spartacus/core'; | ||
import { GetAddressCardContent } from './get-address-card-content.pipe'; | ||
|
||
describe('GetAddressCardContentPipe', () => { | ||
let pipe: GetAddressCardContent; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [GetAddressCardContent], | ||
}); | ||
|
||
pipe = TestBed.inject(GetAddressCardContent); | ||
}); | ||
|
||
it('should create an instance', () => { | ||
expect(pipe).toBeTruthy(); | ||
}); | ||
|
||
it('should transform address to card content', () => { | ||
const address = { | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
line1: '123 Main St', | ||
line2: 'Apt 4B', | ||
town: 'Cityville', | ||
region: { isocode: 'CA' }, | ||
country: { isocode: 'US' }, | ||
postalCode: '12345', | ||
phone: '555-1234', | ||
}; | ||
|
||
const result = pipe.transform(address); | ||
|
||
expect(result).toEqual({ | ||
textBold: 'John Doe', | ||
text: ['123 Main St', 'Apt 4B', 'Cityville, CA, US', '12345', '555-1234'], | ||
}); | ||
}); | ||
|
||
it('should handle missing address', () => { | ||
const result = pipe.transform(null as unknown as Address); | ||
|
||
expect(result).toEqual({}); | ||
}); | ||
|
||
it('should handle missing region and country', () => { | ||
const address = { | ||
firstName: 'Jane', | ||
lastName: 'Smith', | ||
line1: '456 Elm St', | ||
town: 'Townsville', | ||
postalCode: '67890', | ||
phone: '555-5678', | ||
}; | ||
|
||
const result = pipe.transform(address); | ||
console.log(result); | ||
expect(result).toEqual({ | ||
textBold: 'Jane Smith', | ||
text: ['456 Elm St', undefined, 'Townsville', '67890', '555-5678'], | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.