-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🎸 DeckBuilder can accept a predefined shapes\animations
DeckBuilder.start() method can accept a predefined set of shapes and animations created before. Moreover, it infers the names of the shapes and animations and can suggest autocompletion for slide builders inside of deck builder chaining. BREAKING CHANGE: 🧨 DeckBuilder has no longer methods withShape(), withAnimation(). If you want to add a "global" shape, you can create a predefined set of shapes\animations and pass them into DeckBuilder.start(shapes, animations).
- Loading branch information
Showing
2 changed files
with
53 additions
and
30 deletions.
There are no files selected for viewing
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,34 +1,56 @@ | ||
import { AnimationBuilder, ShapeBuilder, SlideBuilder } from '../src/Deck'; | ||
import { AnimationBuilder, ShapeBuilder } from '../src/Deck'; | ||
import { Canvas } from 'terminal-canvas'; | ||
import { DeckBuilder } from '../src/DeckBuilder'; | ||
|
||
describe('deck builder', () => { | ||
it('should properly create deck using DeckBuilder', () => { | ||
expect.hasAssertions(); | ||
|
||
const PREDEFINED_SHAPES = { 'Test Shape': ShapeBuilder.start('Text').end() }; | ||
const PREDEFINED_ANIMATIONS = { 'Test Animation': AnimationBuilder.start('Focus').end() }; | ||
const deck = DeckBuilder | ||
.start() | ||
.start(PREDEFINED_SHAPES, PREDEFINED_ANIMATIONS) | ||
.withCanvas(Canvas.create()) | ||
.withAnimation( | ||
'Test Animation', | ||
AnimationBuilder | ||
.start('Focus') | ||
.end() | ||
) | ||
.withShape( | ||
'Test Shape', | ||
ShapeBuilder | ||
.start('Text') | ||
.withSlide( | ||
(builder) => builder | ||
.withName('Slide #1') | ||
.withOrder('Test Shape', ['Test Animation']) | ||
.end() | ||
) | ||
.withSlide( | ||
SlideBuilder | ||
.start() | ||
(builder) => builder | ||
.withName('Slide #2') | ||
.withAnimation('Local Animation', AnimationBuilder.start('Focus').end()) | ||
.withOrder('Test Shape', ['Test Animation', 'Local Animation']) | ||
.end() | ||
) | ||
.end(); | ||
|
||
expect(deck.canvas).toBeInstanceOf(Canvas); | ||
|
||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-expect-error | ||
const [firstSlide, secondSlide] = deck.slides; | ||
|
||
expect(firstSlide.shapes.size).toBe(1); | ||
expect(firstSlide.shapes.has('Test Shape')).toBe(true); | ||
expect(firstSlide.animations.size).toBe(1); | ||
expect(firstSlide.animations.has('Test Animation')).toBe(true); | ||
expect(firstSlide.order).toStrictEqual([{ | ||
shape: 'Test Shape', | ||
animations: ['Test Animation'] | ||
}]); | ||
|
||
expect(secondSlide.shapes.size).toBe(1); | ||
expect(secondSlide.shapes.has('Test Shape')).toBe(true); | ||
expect(secondSlide.animations.size).toBe(2); | ||
expect(secondSlide.animations.has('Test Animation')).toBe(true); | ||
expect(secondSlide.animations.has('Local Animation')).toBe(true); | ||
expect(secondSlide.order).toStrictEqual([{ | ||
shape: 'Test Shape', | ||
animations: ['Test Animation', 'Local Animation'] | ||
}]); | ||
|
||
deck.exit(); | ||
}); | ||
}); |
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