Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
liady committed Dec 9, 2024
1 parent b087759 commit d82deec
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions editor/src/components/canvas/responsive-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as csstree from 'css-tree'
import { mediaQueryToScreenSize, selectValueByBreakpoint } from './responsive-utils'
import type { ScreenSize, MediaQuery } from './responsive-types'
import { extractScreenSizeFromCss } from './responsive-utils'
import type { StyleMediaSizeModifier } from './canvas-types'
import type { StyleMediaSizeModifier, StyleModifier } from './canvas-types'

describe('extractScreenSizeFromCss', () => {
it('extracts screen size from simple media query', () => {
Expand Down Expand Up @@ -60,7 +60,7 @@ describe('extractScreenSizeFromCss', () => {
})

describe('selectValueByBreakpoint', () => {
const variants: { value: string; modifiers?: StyleMediaSizeModifier[] }[] = [
const variants: { value: string; modifiers?: StyleModifier[] }[] = [
{
value: 'Desktop Value',
modifiers: [{ type: 'media-size', size: { min: { value: 200, unit: 'px' } } }],
Expand Down Expand Up @@ -116,21 +116,27 @@ describe('selectValueByBreakpoint', () => {
})

it('selects null if no matching breakpoint and no default value', () => {
expect(selectValueByBreakpoint(variants.slice(0, 2), 50)).toBeNull()
const largeVariants: { value: string; modifiers?: StyleModifier[] }[] = [
{
value: 'Desktop Value',
modifiers: [{ type: 'media-size', size: { min: { value: 200, unit: 'px' } } }],
},
{
value: 'Tablet Value',
modifiers: [{ type: 'media-size', size: { min: { value: 100, unit: 'px' } } }],
},
]
expect(selectValueByBreakpoint(largeVariants, 50)).toBeNull()
})
it('selects default value if no media modifiers', () => {
expect(
selectValueByBreakpoint(
[
{
value: 'Hover Value',
modifiers: [{ type: 'hover' }],
},
{ value: 'Default Value' },
],
50,
)?.value,
).toEqual('Default Value')
const noMediaVariants: { value: string; modifiers?: StyleModifier[] }[] = [
{
value: 'Hover Value',
modifiers: [{ type: 'hover' }],
},
{ value: 'Default Value' },
]
expect(selectValueByBreakpoint(noMediaVariants, 50)?.value).toEqual('Default Value')
})
})

Expand Down

0 comments on commit d82deec

Please sign in to comment.