@@ -39,6 +39,18 @@ vi.mock("@/hooks/usePipelineRunData");
3939vi . mock ( "@/services/pipelineRunService" ) ;
4040vi . mock ( "@/providers/BackendProvider" ) ;
4141
42+ vi . mock ( "@/hooks/useUserDetails" , ( ) => ( {
43+ useUserDetails : vi . fn ( ( ) => ( {
44+ data : {
45+ name : "test-user" ,
46+ permissions : {
47+ read : true ,
48+ write : true ,
49+ } ,
50+ } ,
51+ } ) ) ,
52+ } ) ) ;
53+
4254describe ( "<RunDetails/>" , ( ) => {
4355 const queryClient = new QueryClient ( {
4456 defaultOptions : {
@@ -237,7 +249,7 @@ describe("<RunDetails/>", () => {
237249 } ) ;
238250
239251 describe ( "Cancel Pipeline Run Button" , ( ) => {
240- test ( "should render cancel button when status is RUNNING" , async ( ) => {
252+ test ( "should render cancel button when status is RUNNING and user is the creator of the run " , async ( ) => {
241253 // arrange
242254 vi . mocked ( usePipelineRunData ) . mockReturnValue ( {
243255 executionData : {
@@ -276,6 +288,35 @@ describe("<RunDetails/>", () => {
276288 const cancelButton = screen . queryByTestId ( "cancel-pipeline-run-button" ) ;
277289 expect ( cancelButton ) . not . toBeInTheDocument ( ) ;
278290 } ) ;
291+
292+ test ( "should NOT render cancel button when the user is not the creator of the run" , async ( ) => {
293+ // arrange
294+ const pipelineRunWithDifferentCreator = {
295+ ...mockPipelineRun ,
296+ created_by : "different-user" ,
297+ } ;
298+
299+ vi . mocked ( pipelineRunService . fetchPipelineRunById ) . mockResolvedValue (
300+ pipelineRunWithDifferentCreator ,
301+ ) ;
302+
303+ vi . mocked ( usePipelineRunData ) . mockReturnValue ( {
304+ executionData : {
305+ details : mockExecutionDetails ,
306+ state : mockRunningExecutionState ,
307+ } ,
308+ rootExecutionId : "test-execution-id" ,
309+ isLoading : false ,
310+ error : null ,
311+ } ) ;
312+
313+ // act
314+ await act ( async ( ) => renderWithQueryClient ( < RunDetails /> ) ) ;
315+
316+ // assert
317+ const cancelButton = screen . queryByTestId ( "cancel-pipeline-run-button" ) ;
318+ expect ( cancelButton ) . not . toBeInTheDocument ( ) ;
319+ } ) ;
279320 } ) ;
280321
281322 describe ( "Rerun Pipeline Run Button" , ( ) => {
0 commit comments