-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from rambler-digital-solutions/sort-media-by-a…
…spect-ratio feat: 🎸 add sorting media file by aspect ratio
- Loading branch information
Showing
2 changed files
with
368 additions
and
17 deletions.
There are no files selected for viewing
354 changes: 341 additions & 13 deletions
354
src/adUnit/helpers/media/__tests__/sortMediaByBestFit.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 |
---|---|---|
@@ -1,22 +1,350 @@ | ||
import sortMediaByBestFit from '../sortMediaByBestFit'; | ||
|
||
test('sortMediaByBestFit must sort the mediaFiles by best screen fit', () => { | ||
const mediafiles = [ | ||
{width: 120}, | ||
{width: 100}, | ||
{width: 90}, | ||
{width: 95}, | ||
{width: 150} | ||
let mediafiles; | ||
|
||
beforeEach(() => { | ||
mediafiles = [ | ||
{ | ||
height: 360, | ||
width: 640 | ||
}, | ||
{ | ||
height: 1080, | ||
width: 1920 | ||
}, | ||
{ | ||
height: 480, | ||
width: 854 | ||
}, | ||
{ | ||
height: 720, | ||
width: 1280 | ||
}, | ||
{ | ||
height: 270, | ||
width: 480 | ||
}, | ||
{ | ||
height: 640, | ||
width: 360 | ||
}, | ||
{ | ||
height: 1920, | ||
width: 1080 | ||
}, | ||
{ | ||
height: 854, | ||
width: 480 | ||
}, | ||
{ | ||
height: 1280, | ||
width: 720 | ||
}, | ||
{ | ||
height: 480, | ||
width: 270 | ||
} | ||
]; | ||
}); | ||
|
||
test('sortMediaByBestFit must sort the mediaFiles by best fit into the horizontally oriented screen', () => { | ||
const sortedMediaFiles = sortMediaByBestFit(mediafiles, { | ||
height: 480, | ||
width: 854 | ||
}); | ||
|
||
expect(sortedMediaFiles).not.toBe(mediafiles); | ||
expect(sortedMediaFiles).toEqual([ | ||
{ | ||
height: 480, | ||
width: 854 | ||
}, | ||
{ | ||
height: 360, | ||
width: 640 | ||
}, | ||
{ | ||
height: 270, | ||
width: 480 | ||
}, | ||
{ | ||
height: 720, | ||
width: 1280 | ||
}, | ||
{ | ||
height: 1080, | ||
width: 1920 | ||
}, | ||
{ | ||
height: 1280, | ||
width: 720 | ||
}, | ||
{ | ||
height: 1920, | ||
width: 1080 | ||
}, | ||
{ | ||
height: 854, | ||
width: 480 | ||
}, | ||
{ | ||
height: 640, | ||
width: 360 | ||
}, | ||
{ | ||
height: 480, | ||
width: 270 | ||
} | ||
]); | ||
}); | ||
|
||
test('sortMediaByBestFit must sort the mediaFiles by best fit into the vertically oriented screen', () => { | ||
const sortedMediaFiles = sortMediaByBestFit(mediafiles, { | ||
height: 854, | ||
width: 480 | ||
}); | ||
|
||
expect(sortedMediaFiles).not.toBe(mediafiles); | ||
expect(sortedMediaFiles).toEqual([ | ||
{ | ||
height: 854, | ||
width: 480 | ||
}, | ||
{ | ||
height: 640, | ||
width: 360 | ||
}, | ||
{ | ||
height: 480, | ||
width: 270 | ||
}, | ||
{ | ||
height: 1280, | ||
width: 720 | ||
}, | ||
{ | ||
height: 1920, | ||
width: 1080 | ||
}, | ||
{ | ||
height: 270, | ||
width: 480 | ||
}, | ||
{ | ||
height: 360, | ||
width: 640 | ||
}, | ||
{ | ||
height: 480, | ||
width: 854 | ||
}, | ||
{ | ||
height: 720, | ||
width: 1280 | ||
}, | ||
{ | ||
height: 1080, | ||
width: 1920 | ||
} | ||
]); | ||
}); | ||
|
||
test('sortMediaByBestFit must sort the mediaFiles by best fit, with vertical non identical values', () => { | ||
mediafiles = [ | ||
{ | ||
height: 360, | ||
width: 640 | ||
}, | ||
{ | ||
height: 1080, | ||
width: 1920 | ||
}, | ||
{ | ||
height: 480, | ||
width: 854 | ||
}, | ||
{ | ||
height: 720, | ||
width: 1280 | ||
}, | ||
{ | ||
height: 270, | ||
width: 480 | ||
}, | ||
{ | ||
height: 640, | ||
width: 360 | ||
}, | ||
{ | ||
height: 1920, | ||
width: 1080 | ||
}, | ||
{ | ||
height: 1280, | ||
width: 720 | ||
}, | ||
{ | ||
height: 480, | ||
width: 270 | ||
} | ||
]; | ||
const sortedMediaFiles = sortMediaByBestFit(mediafiles, { | ||
height: 854, | ||
width: 480 | ||
}); | ||
|
||
expect(sortedMediaFiles).not.toBe(mediafiles); | ||
expect(sortedMediaFiles).toEqual([ | ||
{ | ||
height: 640, | ||
width: 360 | ||
}, | ||
{ | ||
height: 480, | ||
width: 270 | ||
}, | ||
{ | ||
height: 1280, | ||
width: 720 | ||
}, | ||
{ | ||
height: 1920, | ||
width: 1080 | ||
}, | ||
{ | ||
height: 270, | ||
width: 480 | ||
}, | ||
{ | ||
height: 360, | ||
width: 640 | ||
}, | ||
{ | ||
height: 480, | ||
width: 854 | ||
}, | ||
{ | ||
height: 720, | ||
width: 1280 | ||
}, | ||
{ | ||
height: 1080, | ||
width: 1920 | ||
} | ||
]); | ||
}); | ||
|
||
const sortedMediaFiles = sortMediaByBestFit(mediafiles, {width: 100}); | ||
test('sortMediaByBestFit must sort the mediaFiles by best fit, with horizontally non identical values', () => { | ||
mediafiles = [ | ||
{ | ||
height: 360, | ||
width: 640 | ||
}, | ||
{ | ||
height: 1080, | ||
width: 1920 | ||
}, | ||
{ | ||
height: 720, | ||
width: 1280 | ||
}, | ||
{ | ||
height: 270, | ||
width: 480 | ||
}, | ||
{ | ||
height: 640, | ||
width: 360 | ||
}, | ||
{ | ||
height: 1920, | ||
width: 1080 | ||
}, | ||
{ | ||
height: 1280, | ||
width: 720 | ||
}, | ||
{ | ||
height: 480, | ||
width: 270 | ||
} | ||
]; | ||
const sortedMediaFiles = sortMediaByBestFit(mediafiles, { | ||
height: 480, | ||
width: 854 | ||
}); | ||
|
||
expect(sortedMediaFiles).not.toBe(mediafiles); | ||
expect(sortedMediaFiles).toEqual([ | ||
{width: 100}, | ||
{width: 95}, | ||
{width: 90}, | ||
{width: 120}, | ||
{width: 150} | ||
{ | ||
height: 360, | ||
width: 640 | ||
}, | ||
{ | ||
height: 270, | ||
width: 480 | ||
}, | ||
{ | ||
height: 720, | ||
width: 1280 | ||
}, | ||
{ | ||
height: 1080, | ||
width: 1920 | ||
}, | ||
{ | ||
height: 1280, | ||
width: 720 | ||
}, | ||
{ | ||
height: 1920, | ||
width: 1080 | ||
}, | ||
{ | ||
height: 640, | ||
width: 360 | ||
}, | ||
{ | ||
height: 480, | ||
width: 270 | ||
} | ||
]); | ||
}); | ||
|
||
test('sortMediaByBestFit must sort the mediaFiles by best fit, with square video', () => { | ||
mediafiles = [ | ||
{ | ||
height: 300, | ||
width: 300 | ||
}, | ||
{ | ||
height: 200, | ||
width: 200 | ||
}, | ||
{ | ||
height: 100, | ||
width: 100 | ||
} | ||
]; | ||
const sortedMediaFiles = sortMediaByBestFit(mediafiles, { | ||
height: 220, | ||
width: 220 | ||
}); | ||
|
||
expect(sortedMediaFiles).not.toBe(mediafiles); | ||
expect(sortedMediaFiles).toEqual([ | ||
{ | ||
height: 200, | ||
width: 200 | ||
}, | ||
{ | ||
height: 300, | ||
width: 300 | ||
}, | ||
|
||
{ | ||
height: 100, | ||
width: 100 | ||
} | ||
]); | ||
}); |
Oops, something went wrong.