|
| 1 | +/* |
| 2 | + * Copyright 2025 Adobe. All rights reserved. |
| 3 | + * This file is licensed to you under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. You may obtain a copy |
| 5 | + * of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | + * |
| 7 | + * Unless required by applicable law or agreed to in writing, software distributed under |
| 8 | + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS |
| 9 | + * OF ANY KIND, either express or implied. See the License for the specific language |
| 10 | + * governing permissions and limitations under the License. |
| 11 | + */ |
| 12 | + |
| 13 | +import { strict as assert } from 'node:assert'; |
| 14 | +import { sortImagesByRole } from '../../src/utils/product.js'; |
| 15 | + |
| 16 | +describe('product utils', () => { |
| 17 | + describe('sortImagesByRole()', () => { |
| 18 | + it('should sort images by role', () => { |
| 19 | + /** @type {Product['images']} */ |
| 20 | + const images = [{ |
| 21 | + url: 'https://example.com/image4.jpg', |
| 22 | + label: 'four', |
| 23 | + roles: ['teriary'], |
| 24 | + }, { |
| 25 | + url: 'https://example.com/image1.jpg', |
| 26 | + label: 'one', |
| 27 | + roles: ['thumbnail'], |
| 28 | + }, { |
| 29 | + url: 'https://example.com/image2.jpg', |
| 30 | + label: 'two', |
| 31 | + roles: ['primary'], |
| 32 | + }, { |
| 33 | + url: 'https://example.com/image3.jpg', |
| 34 | + label: 'three', |
| 35 | + roles: ['thumbnail', 'secondary'], |
| 36 | + }]; |
| 37 | + |
| 38 | + const sortedImages = sortImagesByRole(images, ['thumbnail', 'primary']); |
| 39 | + assert.deepStrictEqual(sortedImages, [{ |
| 40 | + url: 'https://example.com/image1.jpg', |
| 41 | + label: 'one', |
| 42 | + roles: ['thumbnail'], |
| 43 | + }, { |
| 44 | + url: 'https://example.com/image3.jpg', |
| 45 | + label: 'three', |
| 46 | + roles: ['thumbnail', 'secondary'], |
| 47 | + }, { |
| 48 | + url: 'https://example.com/image2.jpg', |
| 49 | + label: 'two', |
| 50 | + roles: ['primary'], |
| 51 | + }, { |
| 52 | + url: 'https://example.com/image4.jpg', |
| 53 | + label: 'four', |
| 54 | + roles: ['teriary'], |
| 55 | + }]); |
| 56 | + }); |
| 57 | + }); |
| 58 | +}); |
0 commit comments