From bdf598ca12d4fb2f1356fd60a1b4eaced3d891cf Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sat, 13 Jun 2020 14:44:33 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20issue=20with=20"Untitled?= =?UTF-8?q?=20Slide"=20already=20exists=20in=20builder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/main/kittik-slide/spec/Slide.spec.ts | 7 +++++++ src/main/kittik-slide/src/slide/Slide.ts | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/kittik-slide/spec/Slide.spec.ts b/src/main/kittik-slide/spec/Slide.spec.ts index 71b9aa2..a7961a7 100644 --- a/src/main/kittik-slide/spec/Slide.spec.ts +++ b/src/main/kittik-slide/spec/Slide.spec.ts @@ -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(); diff --git a/src/main/kittik-slide/src/slide/Slide.ts b/src/main/kittik-slide/src/slide/Slide.ts index 2819942..419d378 100644 --- a/src/main/kittik-slide/src/slide/Slide.ts +++ b/src/main/kittik-slide/src/slide/Slide.ts @@ -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 = new Map(); public readonly animations: Map = new Map(); public readonly order: OrderDeclaration[] = [];