Skip to content

Commit

Permalink
fix: 🐛 issue with "Untitled Slide" already exists in builder
Browse files Browse the repository at this point in the history
When adding new slides via withSlide() in DeckBuilder and do not provide
names for these slides, it uses "Untitled Slide" by default. The problem
is that when you adding more than one such slide, it throws an error
that slide already exists. This commit fixes it by introducing a random
suffix to "Untitled Slide" name.
  • Loading branch information
ghaiklor committed Jun 13, 2020
1 parent dbd1734 commit bdf598c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/main/kittik-slide/spec/Slide.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ const SERIALIZED_SLIDE_DECLARATION: SlideDeclaration = {
};

describe('slide', () => {
it('should properly generate a unique name by default', () => {
expect.hasAssertions();

const slide = new Slide();
expect((/Untitled Slide #.{7}/u).test(slide.name)).toBe(true);
});

it('should properly throw an error if shape type is unknown', () => {
expect.hasAssertions();

Expand Down
2 changes: 1 addition & 1 deletion src/main/kittik-slide/src/slide/Slide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export { SlideDeclaration } from './SlideDeclaration';

export class Slide {
public canvas: Canvas = Canvas.create();
public name = 'Untitled Slide';
public name = `Untitled Slide #${Math.random().toString(36).slice(2)}`;
public readonly shapes: Map<string, ShapeRenderable> = new Map<string, ShapeRenderable>();
public readonly animations: Map<string, Animationable> = new Map<string, Animationable>();
public readonly order: OrderDeclaration[] = [];
Expand Down

0 comments on commit bdf598c

Please sign in to comment.