@@ -15,7 +15,7 @@ import { ScheduleDialogPresenter } from "./ScheduleDialogPresenter.js";
1515 * `cancel()` resolves, and shows the error when they reject. So a failed action must reject,
1616 * and the dialog must not be left loading.
1717 */
18- const setup = ( params : { fail : boolean } ) => {
18+ const setup = ( params : { fail : boolean ; getExecute ?: ( ) => Promise < unknown > } ) => {
1919 const execute = vi . fn ( async ( ) => {
2020 if ( params . fail ) {
2121 throw new Error ( "Could not schedule the action." ) ;
@@ -24,7 +24,9 @@ const setup = (params: { fail: boolean }) => {
2424 } ) ;
2525
2626 const container = new Container ( ) ;
27- container . registerInstance ( GetScheduledActionGateway , { execute : vi . fn ( ) } as any ) ;
27+ container . registerInstance ( GetScheduledActionGateway , {
28+ execute : params . getExecute ?? vi . fn ( )
29+ } as any ) ;
2830 container . registerInstance ( CancelScheduledActionGateway , { execute } as any ) ;
2931 container . registerInstance ( SchedulePublishActionGateway , { execute } as any ) ;
3032 container . registerInstance ( ScheduleUnpublishActionGateway , { execute } as any ) ;
@@ -74,4 +76,33 @@ describe("ScheduleDialogPresenter", () => {
7476 ) . resolves . toBeUndefined ( ) ;
7577 expect ( presenter . vm . loading ) . toBe ( false ) ;
7678 } ) ;
79+
80+ /*
81+ * The dialog loads the existing schedule before it opens. A failed load used to leave the
82+ * entry empty, which reads as "nothing scheduled" and invites scheduling a duplicate.
83+ */
84+ it ( "rejects when loading the scheduled action fails" , async ( ) => {
85+ const presenter = setup ( {
86+ fail : false ,
87+ getExecute : async ( ) => {
88+ throw new Error ( "Could not fetch scheduled action." ) ;
89+ }
90+ } ) ;
91+
92+ await expect ( presenter . load ( { namespace : "cms/article" , id : "entry-1" } ) ) . rejects . toThrow (
93+ "Could not fetch scheduled action."
94+ ) ;
95+ expect ( presenter . vm . loading ) . toBe ( false ) ;
96+ expect ( presenter . vm . entry ) . toBeNull ( ) ;
97+ } ) ;
98+
99+ it ( "resolves with no entry when nothing is scheduled" , async ( ) => {
100+ const presenter = setup ( { fail : false , getExecute : async ( ) => null } ) ;
101+
102+ await expect (
103+ presenter . load ( { namespace : "cms/article" , id : "entry-1" } )
104+ ) . resolves . toBeUndefined ( ) ;
105+ expect ( presenter . vm . loading ) . toBe ( false ) ;
106+ expect ( presenter . vm . entry ) . toBeNull ( ) ;
107+ } ) ;
77108} ) ;
0 commit comments