forked from shopware/shopware
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NEXT-26011 - add tests for admin filter
- Loading branch information
Showing
26 changed files
with
454 additions
and
89 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/Administration/Resources/app/administration/src/app/filter/asset.filter.spec.js
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
describe('src/app/filter/asset.filter.ts', () => { | ||
const assetFilter = Shopware.Filter.getByName('asset'); | ||
|
||
beforeEach(() => { | ||
Shopware.Context.api.assetsPath = ''; | ||
}); | ||
|
||
it('should contain a filter', () => { | ||
expect(assetFilter).toBeDefined(); | ||
}); | ||
|
||
it('should return empty string when no value is given', () => { | ||
const result = assetFilter(); | ||
|
||
expect(result).toBe(''); | ||
}); | ||
|
||
it('should remove the first slash because double slashes does not work on external storage like s3', () => { | ||
const result = assetFilter('/test.jpg'); | ||
|
||
expect(result).toBe('test.jpg'); | ||
}); | ||
|
||
it('should use the assetsPath from the Context API', () => { | ||
Shopware.Context.api.assetsPath = 'https://www.shopware.com/'; | ||
const result = assetFilter('/test.jpg'); | ||
|
||
expect(result).toBe('https://www.shopware.com/test.jpg'); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -21,3 +21,4 @@ Shopware.Filter.register('asset', (value: string) => { | |
* @deprecated tag:v6.6.0 - Will be private | ||
*/ | ||
export {}; | ||
|
22 changes: 0 additions & 22 deletions
22
src/Administration/Resources/app/administration/src/app/filter/currency.filter.js
This file was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
src/Administration/Resources/app/administration/src/app/filter/currency.filter.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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* @package admin | ||
*/ | ||
import type { CurrencyOptions } from 'src/core/service/utils/format.utils'; | ||
|
||
const { currency } = Shopware.Utils.format; | ||
|
||
/** | ||
* @deprecated tag:v6.6.0 - Will be private | ||
*/ | ||
Shopware.Filter.register('currency', ( | ||
value: string|boolean, | ||
format: string, | ||
decimalPlaces: number, | ||
additionalOptions: CurrencyOptions, | ||
) => { | ||
if ((!value || value === true) && (!Shopware.Utils.types.isNumber(value) || Shopware.Utils.types.isEqual(value, NaN))) { | ||
return '-'; | ||
} | ||
|
||
if (Shopware.Utils.types.isEqual(parseInt(value, 10), NaN)) { | ||
return value; | ||
} | ||
|
||
return currency(parseFloat(value), format, decimalPlaces, additionalOptions); | ||
}); |
30 changes: 30 additions & 0 deletions
30
src/Administration/Resources/app/administration/src/app/filter/date.filter.spec.js
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
describe('src/app/filter/date.filter.ts', () => { | ||
const dateFilter = Shopware.Filter.getByName('date'); | ||
|
||
Shopware.Utils.format.date = jest.fn(); | ||
|
||
beforeEach(() => { | ||
Shopware.Utils.format.date.mockClear(); | ||
}); | ||
|
||
it('should contain a filter', () => { | ||
expect(dateFilter).toBeDefined(); | ||
}); | ||
|
||
it('should return empty string when no value is given', () => { | ||
expect(dateFilter()).toBe(''); | ||
}); | ||
|
||
it('should call the date format util for formatting', () => { | ||
dateFilter('01.01.1997', { | ||
myDateOptions: 'foo', | ||
}); | ||
|
||
expect(Shopware.Utils.format.date).toHaveBeenCalledWith( | ||
'01.01.1997', | ||
{ | ||
myDateOptions: 'foo', | ||
}, | ||
); | ||
}); | ||
}); |
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
17 changes: 0 additions & 17 deletions
17
src/Administration/Resources/app/administration/src/app/filter/file-size.filter.js
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
src/Administration/Resources/app/administration/src/app/filter/file-size.filter.spec.js
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
describe('src/app/filter/file-size.filter.js', () => { | ||
const fileSizeFilter = Shopware.Filter.getByName('fileSize'); | ||
|
||
Shopware.Utils.format.fileSize = jest.fn(); | ||
|
||
beforeEach(() => { | ||
Shopware.Utils.format.fileSize.mockClear(); | ||
}); | ||
|
||
it('should contain a filter', () => { | ||
expect(fileSizeFilter).toBeDefined(); | ||
}); | ||
|
||
it('should return empty string when no value is given', () => { | ||
expect(fileSizeFilter()).toBe(''); | ||
}); | ||
|
||
it('should call the fileSize format util for formatting', () => { | ||
fileSizeFilter( | ||
1856165, | ||
{ | ||
myLocaleOptions: 'foo', | ||
}, | ||
); | ||
|
||
expect(Shopware.Utils.format.fileSize).toHaveBeenCalledWith( | ||
1856165, | ||
{ | ||
myLocaleOptions: 'foo', | ||
}, | ||
); | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
src/Administration/Resources/app/administration/src/app/filter/file-size.filter.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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @package admin | ||
*/ | ||
|
||
/** | ||
* @deprecated tag:v6.6.0 - Will be private | ||
*/ | ||
Shopware.Filter.register('fileSize', (value: number, locale: string) => { | ||
if (!value) { | ||
return ''; | ||
} | ||
|
||
return Shopware.Utils.format.fileSize(value, locale); | ||
}); | ||
|
||
/* @private */ | ||
export {}; |
20 changes: 0 additions & 20 deletions
20
src/Administration/Resources/app/administration/src/app/filter/media-name.filter.js
This file was deleted.
Oops, something went wrong.
41 changes: 41 additions & 0 deletions
41
src/Administration/Resources/app/administration/src/app/filter/media-name.filter.spec.js
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
describe('src/app/filter/media-name.filter.js', () => { | ||
const mediaNameFilter = Shopware.Filter.getByName('mediaName'); | ||
|
||
it('should contain a filter', () => { | ||
expect(mediaNameFilter).toBeDefined(); | ||
}); | ||
|
||
it('should return empty string fallback when no value is given', () => { | ||
expect(mediaNameFilter()).toBe(''); | ||
}); | ||
|
||
it('should return given fallback when no value is given', () => { | ||
expect(mediaNameFilter(undefined, 'fooBar')).toBe('fooBar'); | ||
}); | ||
|
||
it('should return the values inside the entity by default', () => { | ||
expect(mediaNameFilter({ | ||
entity: { | ||
fileName: 'my-file-name', | ||
fileExtension: 'jpg', | ||
}, | ||
})).toBe('my-file-name.jpg'); | ||
}); | ||
|
||
it('should return the values even when not entity is given', () => { | ||
expect(mediaNameFilter({ | ||
fileName: 'my-file-name', | ||
fileExtension: 'jpg', | ||
})).toBe('my-file-name.jpg'); | ||
}); | ||
|
||
it('should return the fallback when fileName or fileExtension is missing', () => { | ||
expect(mediaNameFilter( | ||
{ | ||
fileNameFoo: 'my-file-name', | ||
fileExtensionBar: 'jpg', | ||
}, | ||
'my-fallback', | ||
)).toBe('my-fallback'); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
src/Administration/Resources/app/administration/src/app/filter/media-name.filter.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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* @package content | ||
*/ | ||
Shopware.Filter.register('mediaName', ( | ||
value: { | ||
entity?: { | ||
fileName?: string, | ||
fileExtension?: string | ||
}, | ||
fileName?: string, | ||
fileExtension?: string | ||
}, | ||
// eslint-disable-next-line @typescript-eslint/no-inferrable-types | ||
fallback: string = '', | ||
): string => { | ||
if (!value) { | ||
return fallback; | ||
} | ||
|
||
if (value.entity) { | ||
value = value.entity; | ||
} | ||
|
||
if ((!value.fileName) || (!value.fileExtension)) { | ||
return fallback; | ||
} | ||
|
||
return `${value.fileName}.${value.fileExtension}`; | ||
}); | ||
|
||
/* @private */ | ||
export {}; |
54 changes: 54 additions & 0 deletions
54
src/Administration/Resources/app/administration/src/app/filter/salutation.filter.spec.js
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
describe('src/app/filter/salutation.filter.ts', () => { | ||
const salutationFilter = Shopware.Filter.getByName('salutation'); | ||
|
||
it('should contain a filter', () => { | ||
expect(salutationFilter).toBeDefined(); | ||
}); | ||
|
||
it('should return empty string fallback when no value is given', () => { | ||
expect(salutationFilter()).toBe(''); | ||
}); | ||
|
||
it('should return given fallback when no value is given', () => { | ||
expect(salutationFilter(undefined, 'fooBar')).toBe('fooBar'); | ||
}); | ||
|
||
it('should return the correct salutation', () => { | ||
expect(salutationFilter({ | ||
salutation: { | ||
id: '1', | ||
salutationKey: 'mr', | ||
displayName: 'Mr.', | ||
}, | ||
title: 'Dr.', | ||
firstName: 'Max', | ||
lastName: 'Mustermann', | ||
})).toBe('Mr. Dr. Max Mustermann'); | ||
}); | ||
|
||
it('should hide salutation when no salutationKey was defined', () => { | ||
expect(salutationFilter({ | ||
salutation: { | ||
id: '1', | ||
salutationKey: 'not_specified', | ||
displayName: 'Mr.', | ||
}, | ||
title: 'Dr.', | ||
firstName: 'Max', | ||
lastName: 'Mustermann', | ||
})).toBe('Dr. Max Mustermann'); | ||
}); | ||
|
||
it('should return the fallback snippet when no subvalues are given', () => { | ||
expect(salutationFilter({ | ||
salutation: { | ||
id: '1', | ||
salutationKey: 'mr', | ||
displayName: '', | ||
}, | ||
title: '', | ||
firstName: '', | ||
lastName: '', | ||
})).toBe(''); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -46,3 +46,4 @@ Filter.register('salutation', ( | |
* @deprecated tag:v6.6.0 - Will be private | ||
*/ | ||
export default {}; | ||
|
27 changes: 27 additions & 0 deletions
27
...nistration/Resources/app/administration/src/app/filter/stock-color-variant.filter.spec.js
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
describe('src/app/filter/stock-color-variant.filter.ts', () => { | ||
const stockColorVariantFilter = Shopware.Filter.getByName('stockColorVariant'); | ||
|
||
it('should contain a filter', () => { | ||
expect(stockColorVariantFilter).toBeDefined(); | ||
}); | ||
|
||
it('should return empty string fallback when no value is given', () => { | ||
expect(stockColorVariantFilter()).toBe(''); | ||
}); | ||
|
||
it('should return success when value is 25 or higher', () => { | ||
expect(stockColorVariantFilter(25)).toBe('success'); | ||
expect(stockColorVariantFilter(29)).toBe('success'); | ||
}); | ||
|
||
it('should return warning when value is between 1 and 25', () => { | ||
expect(stockColorVariantFilter(1)).toBe('warning'); | ||
expect(stockColorVariantFilter(18)).toBe('warning'); | ||
expect(stockColorVariantFilter(24)).toBe('warning'); | ||
}); | ||
|
||
it('should return error when value is below 0', () => { | ||
expect(stockColorVariantFilter(0)).toBe('error'); | ||
expect(stockColorVariantFilter(-5)).toBe('error'); | ||
}); | ||
}); |
Oops, something went wrong.