File tree Expand file tree Collapse file tree 2 files changed +11
-5
lines changed
webcomponents/tool/src/main/frontend/packages/sakai-conversations Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -113,14 +113,14 @@ export class SakaiTopic extends reactionsAndUpvotingMixin(SakaiElement) {
113
113
114
114
// If there are no new posts to mark as viewed, return early
115
115
if ( newPostIds . length === 0 ) {
116
- return ;
116
+ return Promise . resolve ( ) ;
117
117
}
118
118
119
119
// Add these posts to our tracked set before making the request
120
120
newPostIds . forEach ( id => this . _observedPosts . add ( id ) ) ;
121
121
122
122
const url = this . topic . links . find ( l => l . rel === "markpostsviewed" ) . href ;
123
- fetch ( url , {
123
+ return fetch ( url , {
124
124
method : "POST" ,
125
125
headers : { "Content-Type" : "application/json" } ,
126
126
body : JSON . stringify ( newPostIds ) ,
@@ -149,7 +149,10 @@ export class SakaiTopic extends reactionsAndUpvotingMixin(SakaiElement) {
149
149
throw new Error ( `Network error while marking posts as viewed at url ${ url } ` ) ;
150
150
}
151
151
} )
152
- . catch ( error => console . error ( error ) ) ;
152
+ . catch ( error => {
153
+ console . error ( error ) ;
154
+ throw error ;
155
+ } ) ;
153
156
}
154
157
155
158
_savePostAsDraft ( ) { this . _postToTopic ( true ) ; }
Original file line number Diff line number Diff line change @@ -566,10 +566,13 @@ describe("sakai-topic tests", () => {
566
566
const originalObserver = el . observer ;
567
567
el . observer = { observe : observeSpy , unobserve : unobserveSpy } ;
568
568
569
+ // Set up event listener for "posts-viewed" before calling the method
570
+ const eventPromise = oneEvent ( el , "posts-viewed" ) ;
571
+
569
572
// Call the method directly with the post IDs
570
- el . _markPostsViewed ( [ "post1" ] ) ;
573
+ await el . _markPostsViewed ( [ "post1" ] ) ;
571
574
572
- const { detail } = await oneEvent ( el , "posts-viewed" ) ;
575
+ const { detail } = await eventPromise ;
573
576
574
577
expect ( detail . postIds ) . to . include ( "post1" ) ;
575
578
expect ( detail . topicId ) . to . equal ( topic . id ) ;
You can’t perform that action at this time.
0 commit comments