|
| 1 | +import { trimLeadingDisabledSpecifications } from '$lib/helpers/specifications'; |
| 2 | +import type { Models } from '@appwrite.io/console'; |
| 3 | +import { describe, expect, it } from 'vitest'; |
| 4 | + |
| 5 | +const specification = (slug: string, enabled: boolean): Models.Specification => ({ |
| 6 | + slug, |
| 7 | + enabled, |
| 8 | + cpus: 1, |
| 9 | + memory: 512 |
| 10 | +}); |
| 11 | + |
| 12 | +describe('trimLeadingDisabledSpecifications', () => { |
| 13 | + it('hides disabled specifications before the first enabled specification', () => { |
| 14 | + const list = { |
| 15 | + total: 4, |
| 16 | + specifications: [ |
| 17 | + specification('disabled-small', false), |
| 18 | + specification('enabled-small', true), |
| 19 | + specification('enabled-large', true), |
| 20 | + specification('disabled-large', false) |
| 21 | + ] |
| 22 | + }; |
| 23 | + |
| 24 | + expect(trimLeadingDisabledSpecifications(list)).toEqual({ |
| 25 | + total: 3, |
| 26 | + specifications: list.specifications.slice(1) |
| 27 | + }); |
| 28 | + expect(list.specifications).toHaveLength(4); |
| 29 | + }); |
| 30 | + |
| 31 | + it('keeps the list unchanged when the first specification is enabled', () => { |
| 32 | + const list = { |
| 33 | + total: 2, |
| 34 | + specifications: [specification('enabled', true), specification('disabled', false)] |
| 35 | + }; |
| 36 | + |
| 37 | + expect(trimLeadingDisabledSpecifications(list)).toEqual(list); |
| 38 | + }); |
| 39 | + |
| 40 | + it('returns an empty list when no specification is enabled', () => { |
| 41 | + const list = { |
| 42 | + total: 2, |
| 43 | + specifications: [ |
| 44 | + specification('disabled-small', false), |
| 45 | + specification('disabled-large', false) |
| 46 | + ] |
| 47 | + }; |
| 48 | + |
| 49 | + expect(trimLeadingDisabledSpecifications(list)).toEqual({ |
| 50 | + total: 0, |
| 51 | + specifications: [] |
| 52 | + }); |
| 53 | + }); |
| 54 | + |
| 55 | + it('keeps an empty list empty', () => { |
| 56 | + expect(trimLeadingDisabledSpecifications({ total: 0, specifications: [] })).toEqual({ |
| 57 | + total: 0, |
| 58 | + specifications: [] |
| 59 | + }); |
| 60 | + }); |
| 61 | +}); |
0 commit comments