import { describe, it, expect } from 'vitest' import * as Style from '../../src/style/index.js' describe('Style', () => { describe('.ClassList', () => { describe('.setStyle', () => { it('should change it', () => { expect( Style.ClassList.setStyle( ['-section--cool'], Style.Rule({ type: 'block', details: { slug: 'section--bad', collectionId: 'section' } }) ) ).to.eql(['-section--bad']) }) it('should remove previously assigned combo', () => { expect( Style.ClassList.setStyle( ['-section--cool', '--test'], Style.Rule({ type: 'block', details: { slug: 'section--bad', collectionId: 'section' } }) ) ).to.eql(['-section--bad']) }) it('should remove previously assigned aspects ', () => { expect( Style.ClassList.setStyle( ['-section--cool', '-decoration--test'], Style.Rule({ type: 'block', details: { slug: 'section--bad', collectionId: 'section' } }) ) ).to.eql(['-section--bad']) }) it('should retain assigned styles that are not elements aspects ', () => { expect( Style.ClassList.setStyle( ['-section--cool', '-dimensions--test'], Style.Rule({ type: 'block', details: { slug: 'section--bad', collectionId: 'section' } }) ) ).to.eql(['-section--bad', '-dimensions--test']) }) it('should add disguise list item as paragraph', () => { expect( Style.ClassList.setStyle( ['-list-item'], Style.Rule({ type: 'text', details: { slug: 'paragraph--test', collectionId: 'paragraph' } }) ) ).to.eql(['-list-item', '-paragraph--test']) }) it('should remove element class if disguise doesnt match', () => { expect( Style.ClassList.setStyle( ['-list-item'], Style.Rule({ type: 'text', details: { slug: 'heading1--test', collectionId: 'heading1' } }) ) ).to.eql(['-heading1--test']) }) it('should retain unknown classes', () => { expect( Style.ClassList.setStyle( ['-section--cool', 'really-cool'], Style.Rule({ type: 'text', details: { slug: 'heading1--test', collectionId: 'heading1' } }) ) ).to.eql(['-heading1--test', 'really-cool']) }) it('should reset to default class name when removing style', () => { expect(Style.ClassList.setStyle(['-heading1--test'], { type: 'text' })).to.eql(['-heading1']) expect(Style.ClassList.setStyle(['-heading1'], { type: 'text' })).to.eql(['-heading1']) expect(Style.ClassList.setStyle(['-inline--type--style'], { type: 'inline' })).to.eql(['-inline--type']) }) }) describe('.setCombo', () => { it('should be able to remove combo', () => { expect(Style.ClassList.setCombo(['-inline--type--style', '--combo'], null)).to.eql(['-inline--type--style']) }) it('should not crash', () => { expect(Style.ClassList.setCombo(['-inline--type--style'], null)).to.eql(['-inline--type--style']) }) }) describe('.setThemeCombo', () => { const combo: Style.Theme.Combo = { decorationId: null, fillId: null, id: 'my-combo-id', isDefault: false, paletteId: null, refId: 'combo-style-id', spacingId: null, typographyId: null } const sameCategoryCombo: Style.Theme.Combo = { decorationId: null, fillId: null, id: 'same-category-combo-id', isDefault: false, paletteId: null, refId: 'same-category-combo-style-id', spacingId: null, typographyId: null } const otherCategoryCombo: Style.Theme.Combo = { decorationId: null, fillId: null, id: 'other-category-combo-id', isDefault: false, paletteId: null, refId: 'other-category-combo-style-id', spacingId: null, typographyId: null } const styles = ( [ { details: { description: '', id: 'my-theme-id', slug: 'test', title: 'test' }, props: { blocks: [combo, sameCategoryCombo, otherCategoryCombo], inlines: [], texts: [] }, type: 'theme' }, { type: 'block', props: {}, details: { id: 'combo-style-id', title: 'Combo', collectionId: 'collection-id' } }, { type: 'block', props: {}, details: { id: 'same-category-combo-style-id', title: 'Combo2', collectionId: 'collection-id' } }, { type: 'block', props: {}, details: { id: 'other-category-combo-style-id', title: 'Combo3', collectionId: 'other-collection-id' } }, { type: 'collection', props: { type: 'block' }, details: { id: 'collection-id', title: 'Collection' } } ] as const ).map(Style.Rule) it('should be able to apply theme combo to classList', () => { const oldClassList = ['class-a', 'class-b'] const newClassList = Style.ClassList.setThemeCombo(oldClassList, combo, styles) expect(newClassList).toStrictEqual(['-use--my-combo-id', 'class-a', 'class-b']) }) it('should get rid of combos that no longer exist in stylesheet - removed', () => { const oldClassList = ['class-a', 'class-b', '-use--removed-combo-id'] const newClassList = Style.ClassList.setThemeCombo(oldClassList, combo, styles) expect(newClassList).toStrictEqual(['-use--my-combo-id', 'class-a', 'class-b']) }) it('should get rid of combos that belong to same collection', () => { const oldClassList = ['class-a', 'class-b', '-use--same-category-combo-id'] const newClassList = Style.ClassList.setThemeCombo(oldClassList, combo, styles) expect(newClassList).toStrictEqual(['-use--my-combo-id', 'class-a', 'class-b']) }) it('should not get rid of combos that belong to other categories', () => { const oldClassList = ['class-a', 'class-b', '-use--other-category-combo-id'] const newClassList = Style.ClassList.setThemeCombo(oldClassList, combo, styles) expect(newClassList).toStrictEqual(['-use--my-combo-id', '-use--other-category-combo-id', 'class-a', 'class-b']) }) }) describe('getDefinition', () => { it('should resolve form', () => { expect(Style.ClassList.getDefinition(['-component--form'])?.name).toEqual('form') expect(Style.ClassList.getDefinition(['-component--form'])?.name).toEqual('form') }) }) }) })