diff --git a/PlotLine.Tests/Browser/scene-creation-acceptance.cjs b/PlotLine.Tests/Browser/scene-creation-acceptance.cjs new file mode 100644 index 00000000..887e639d --- /dev/null +++ b/PlotLine.Tests/Browser/scene-creation-acceptance.cjs @@ -0,0 +1,71 @@ +const assert = require('node:assert/strict'); +const {open} = require('./dev-acceptance.cjs'); +let session; +let stage = 'login'; +(async () => { + try { + session = await open(); + const project = await session.project(); + const book = await session.create('Books', '?projectId='+project, {BookTitle:'Scene creation acceptance',BookNumber:1}); + const chapter = await session.create('Chapters','?bookId='+book,{ChapterTitle:'Disposable scene chapter',ChapterNumber:1}); + const page = session.page; + const chapterUrl = '/Chapters/Details/'+chapter; + const rows = () => page.locator('a[href^="/Scenes/Edit/"]'); + stage = 'cancel'; + await session.goto(chapterUrl); + const before = await rows().count(); + await page.getByRole('link',{name:'Add scene',exact:true}).click(); + await page.locator('#scene-create-form').waitFor(); + assert.equal(await page.locator('#ChapterID').inputValue(),String(chapter)); + assert.equal(await page.locator('#SceneNumber').inputValue(),'1'); + await page.locator('#SceneTitle').fill('Cancelled scene'); + await page.getByRole('link',{name:'Cancel',exact:true}).click(); + await page.reload(); + assert.equal(await rows().count(),before); + stage = 'validation'; + await page.getByRole('link',{name:'Add scene',exact:true}).click(); + await page.locator('#scene-create-form').waitFor(); + await page.getByRole('button',{name:'Create scene',exact:true}).click(); + assert.equal(await page.locator('#scene-create-form').count(),1); + // Bypass only client validation to exercise the server's invalid-model path. + await page.locator('#Summary').fill('Preserved after invalid submission'); + await page.locator('#scene-create-form').evaluate(form=>HTMLFormElement.prototype.submit.call(form)); + await page.waitForURL('**/Scenes/Save'); + assert.equal(await page.locator('#Summary').inputValue(),'Preserved after invalid submission'); + assert.match(await page.locator('[data-valmsg-for="SceneTitle"]').innerText(),/required/i); + stage = 'create'; + await page.locator('#SceneTitle').fill('Persisted acceptance scene'); + await page.getByRole('button',{name:'Create scene',exact:true}).click(); + await page.waitForURL('**/Scenes/Edit/*'); + const sceneUrl = new URL(page.url()).pathname; + await page.reload(); + assert.match(await page.locator('main').innerText(),/Persisted acceptance scene/); + await session.goto(chapterUrl); + assert.equal(await rows().count(),before+1); + const row = page.locator('tr').filter({hasText:'Persisted acceptance scene'}); + assert.match(await row.innerText(),/1/); + stage = 'existing edit'; + await session.goto(sceneUrl); + await page.getByRole('button',{name:'Edit scene details',exact:true}).click(); + const editor = page.locator('form[data-scene-editor-form]'); + await editor.locator('[name=SceneTitle]').fill('Edited acceptance scene'); + await editor.getByRole('button',{name:'Save details',exact:true}).click(); + await page.locator('[data-scene-editor-overlay]').waitFor({state:'hidden'}); + await page.reload(); + assert.match(await page.locator('main').innerText(),/Edited acceptance scene/); + stage = 'sequence'; + await session.goto('/Scenes/Create?chapterId='+chapter); + assert.equal(await page.locator('#SceneNumber').inputValue(),'2'); + await page.getByRole('link',{name:'Cancel',exact:true}).click(); + await session.close(); + session = await open(); + stage = 'fresh login persistence'; + await session.goto(sceneUrl); + assert.match(await session.page.locator('main').innerText(),/Edited acceptance scene/); + await session.page.getByRole('button',{name:'Edit scene details',exact:true}).click(); + assert.equal(await session.page.locator('form[data-scene-editor-form] [name=Summary]').inputValue(),'Preserved after invalid submission'); + console.log(JSON.stringify({status:'passed',checks:['cancel without mutation','required title client and server validation','field preservation','chapter context and sequence','creation workspace redirect','existing workspace editing','reload and fresh login persistence'],featureUrl:'https://dev.plotdirector.com'+sceneUrl,chapterUrl:'https://dev.plotdirector.com'+chapterUrl})); + } finally { + if(session) {try {await session.cleanup();console.log('PASS disposable project cleanup');} finally {await session.close();}} + } +})().catch(()=>{console.error('Scene creation acceptance failed at stage: '+stage+'; no credentials logged.');process.exitCode=1;}); diff --git a/PlotLine.Tests/Program.cs b/PlotLine.Tests/Program.cs index 365962fe..82552f59 100644 --- a/PlotLine.Tests/Program.cs +++ b/PlotLine.Tests/Program.cs @@ -15,6 +15,7 @@ using PlotLine.Models; using PlotLine.Services; using PlotLine.ViewModels; +if(args.Contains("--scene-creation")){await SceneCreationTests.Run();return;} if(args.Contains("--help-visibility")){HelpVisibilityTests.Run();return;} if(args.Contains("--application-domain")){ApplicationDomainBoundaryTests.Run();return;} if(args.Contains("--spatial-context-database")){await SpatialContextDatabaseTests.Run(args.Last());return;} diff --git a/PlotLine.Tests/SceneCreationTests.cs b/PlotLine.Tests/SceneCreationTests.cs new file mode 100644 index 00000000..701c55ec --- /dev/null +++ b/PlotLine.Tests/SceneCreationTests.cs @@ -0,0 +1,50 @@ +using System.Reflection; +using Microsoft.AspNetCore.Mvc; +using PlotLine.Controllers; +using PlotLine.Services; +using PlotLine.ViewModels; + +internal static class SceneCreationTests +{ + public static async Task Run() + { + var saves = 0; + var limited = false; + var model = new SceneEditViewModel { ChapterID = 42, SceneNumber = 3, SceneTitle = "Draft" }; + var service = DispatchProxy.Create(); + ((StoryPointProxy)(object)service).Handler = (method, args) => method switch + { + "GetCreateAsync" => Task.FromResult((int)args![0]! == 42 + ? new SceneEditViewModel { ChapterID = 42, SceneNumber = 3 } : null), + "GetEditAsync" => Task.FromResult(model), + "SaveAsync" => Save(), + _ => throw new InvalidOperationException(method) + }; + Task Save() + { + saves++; + return limited ? Task.FromException(new SubscriptionLimitException("Scene limit reached")) : Task.FromResult(81); + } + ScenesController Controller() => new(service, null!, null!, null!, null!, null!, null!, null!, null!); + void Check(bool value, string message) { if (!value) throw new Exception(message); } + var controller = Controller(); + Check(await controller.Create(999) is NotFoundResult, "Unknown chapter must not show creation form"); + Check(await controller.Create(42) is ViewResult { ViewName: "Create", Model: SceneEditViewModel { ChapterID: 42, SceneNumber: 3 } }, "Creation must use dedicated form and chapter defaults"); + controller.ModelState.AddModelError("SceneTitle", "Required"); + var invalid = (ViewResult)await controller.Save(model); + Check(invalid.ViewName == "Create" && ((SceneEditViewModel)invalid.Model!).SceneTitle == "Draft" && saves == 0, "Invalid creation must preserve fields without saving"); + limited = true; + controller = Controller(); + var limit = (ViewResult)await controller.Save(model); + Check(limit.ViewName == "Create" && !controller.ModelState.IsValid, "Creation limit must return usable form with error"); + limited = false; + controller = Controller(); + var saved = (RedirectToActionResult)await controller.Save(model); + Check(saved.ActionName == "Edit" && (int)saved.RouteValues!["id"]! == 81, "New scene must open persisted workspace"); + model.SceneID = 81; + controller = Controller(); + controller.ModelState.AddModelError("SceneTitle", "Required"); + Check(await controller.Save(model) is ViewResult { ViewName: "Edit" }, "Invalid existing edits must retain workspace"); + Console.WriteLine("PASS scene creation routes, chapter defaults, validation preservation, limits and persisted workspace redirect"); + } +} diff --git a/PlotLine/Controllers/ScenesController.cs b/PlotLine/Controllers/ScenesController.cs index 9cf003b7..a2c9af5d 100644 --- a/PlotLine/Controllers/ScenesController.cs +++ b/PlotLine/Controllers/ScenesController.cs @@ -25,7 +25,7 @@ public sealed class ScenesController( public async Task Create(int chapterId) { var model = await scenes.GetCreateAsync(chapterId); - return model is null ? NotFound() : View("Edit", model); + return model is null ? NotFound() : View("Create", model); } public async Task Edit(int id) @@ -49,7 +49,7 @@ public sealed class ScenesController( } CopyPostedSceneFields(model, hydratedModel); - return View("Edit", hydratedModel); + return View(model.SceneID == 0 ? "Create" : "Edit", hydratedModel); } int sceneId; @@ -67,7 +67,12 @@ public sealed class ScenesController( } CopyPostedSceneFields(model, createModel); - return View("Edit", createModel); + return View("Create", createModel); + } + + if (model.SceneID == 0) + { + return RedirectToAction(nameof(Edit), new { id = sceneId }); } if (TryGetLocalReturnUrl(out var returnUrl)) @@ -1728,6 +1733,7 @@ public sealed class ScenesController( target.SceneTitle = source.SceneTitle; target.SceneNumber = source.SceneNumber; target.Summary = source.Summary; + target.POVCharacterID = source.POVCharacterID; target.TimeModeID = source.TimeModeID; target.StartDateTime = source.StartDateTime; target.EndDateTime = source.EndDateTime; diff --git a/PlotLine/Help/Articles/Scenes/Edit.md b/PlotLine/Help/Articles/Scenes/Edit.md index 39ee555b..de22eba2 100644 --- a/PlotLine/Help/Articles/Scenes/Edit.md +++ b/PlotLine/Help/Articles/Scenes/Edit.md @@ -22,6 +22,8 @@ Use this page when creating a new story beat, adjusting an existing scene, or ch # How To Use It +From Chapter Details, choose **Add scene** to open the New Scene form for that chapter. Enter a scene title and review the suggested scene number and revision status. **Create scene** saves it and opens the persisted Scene Workspace. **Cancel** returns to Chapter Details without creating a scene. Validation messages keep your entered values in the form so you can correct them. + Start with the scene title, summary and revision status. Add time, location and point-of-view details when they matter. Record enough continuity information that later scenes can rely on it. # Example diff --git a/PlotLine/Views/Scenes/Create.cshtml b/PlotLine/Views/Scenes/Create.cshtml new file mode 100644 index 00000000..4ff6b4c3 --- /dev/null +++ b/PlotLine/Views/Scenes/Create.cshtml @@ -0,0 +1,126 @@ +@model SceneEditViewModel +@{ + ViewData["Title"] = "New Scene"; + ViewData["ProjectSection"] = "Overview"; + ViewData["ShellClass"] = "plotline-shell-wide"; +} + +
+ + +@if (Model.Project is not null) +{ + +} + +
+
+

@Model.Book?.BookTitle / Chapter @Model.Chapter?.ChapterNumber

+

New Scene

+

Create the scene, then continue in its Scene Workspace.

+
+
+
+
+ + + +
+ Scene details +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
Timing +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
Purpose and outcome + @foreach (var purpose in Model.ScenePurposeTypes) + { + + } +
+
+
+ @if (Model.Metrics.Count > 0) + { +
Scene metrics + @for (var index = 0; index < Model.Metrics.Count; index++) + { +
+ + + + + + + + + +
+ } +
+ } +
+ + Cancel +
+
+
+
+@section Scripts { + +}