@@ -7,11 +7,22 @@ import {
77 streamFactory ,
88} from 'src/factories' ;
99import { StreamLanding } from 'src/features/Delivery/Streams/Stream/StreamLanding' ;
10- import { http , HttpResponse , server } from 'src/mocks/testServer' ;
1110import { renderWithTheme } from 'src/utilities/testHelpers' ;
1211
1312import type { Flags } from 'src/featureFlags' ;
1413
14+ const queryMocks = vi . hoisted ( ( ) => ( {
15+ useStreamQuery : vi . fn ( ) . mockReturnValue ( { } ) ,
16+ } ) ) ;
17+
18+ vi . mock ( '@linode/queries' , async ( ) => {
19+ const actual = await vi . importActual ( '@linode/queries' ) ;
20+ return {
21+ ...actual ,
22+ useStreamQuery : queryMocks . useStreamQuery ,
23+ } ;
24+ } ) ;
25+
1526const streamId = 123 ;
1627const mockDestinations = [
1728 akamaiObjectStorageDestinationFactory . build ( { id : 1 } ) ,
@@ -30,45 +41,83 @@ describe('StreamLanding', () => {
3041 } ) ;
3142 } ;
3243
33- beforeEach ( async ( ) => {
34- server . use (
35- http . get ( `*/monitor/streams/${ streamId } ` , ( ) => {
36- return HttpResponse . json ( mockStream ) ;
37- } )
38- ) ;
44+ describe ( 'and stream has loaded successfully' , ( ) => {
45+ beforeEach ( async ( ) => {
46+ queryMocks . useStreamQuery . mockReturnValue ( {
47+ data : mockStream ,
48+ isLoading : false ,
49+ } ) ;
50+ } ) ;
51+
52+ describe ( 'and metrics are not enabled' , ( ) => {
53+ const flags = {
54+ aclpLogs : {
55+ enabled : true ,
56+ beta : false ,
57+ metricsEnabled : false ,
58+ } ,
59+ } ;
60+
61+ it ( 'should render the summary and not the metrics tab' , async ( ) => {
62+ renderComponent ( flags ) ;
63+
64+ screen . getByText ( 'Summary' ) ;
65+ expect ( screen . queryByText ( 'Metrics' ) ) . not . toBeInTheDocument ( ) ;
66+ } ) ;
67+ } ) ;
68+
69+ describe ( 'and metrics are enabled' , ( ) => {
70+ const flags = {
71+ aclpLogs : {
72+ enabled : true ,
73+ beta : false ,
74+ metricsEnabled : true ,
75+ } ,
76+ } ;
77+
78+ it ( 'should render the summary tab and metrics tab' , async ( ) => {
79+ renderComponent ( flags ) ;
80+
81+ screen . getByText ( 'Summary' ) ;
82+ expect ( screen . queryByText ( 'Metrics' ) ) . toBeInTheDocument ( ) ;
83+ } ) ;
84+ } ) ;
3985 } ) ;
4086
41- describe ( 'and metrics are not enabled' , ( ) => {
42- const flags = {
43- aclpLogs : {
44- enabled : true ,
45- beta : false ,
46- metricsEnabled : false ,
47- } ,
48- } ;
87+ describe ( 'and stream is loading' , ( ) => {
88+ beforeEach ( async ( ) => {
89+ queryMocks . useStreamQuery . mockReturnValue ( {
90+ isLoading : true ,
91+ } ) ;
92+ } ) ;
4993
50- it ( 'should render the summary and not the metrics tab ' , async ( ) => {
51- renderComponent ( flags ) ;
94+ it ( 'should render loading spinner ' , async ( ) => {
95+ renderComponent ( { } ) ;
5296
53- screen . getByText ( 'Summary' ) ;
97+ expect ( screen . queryByText ( 'Summary' ) ) . not . toBeInTheDocument ( ) ;
5498 expect ( screen . queryByText ( 'Metrics' ) ) . not . toBeInTheDocument ( ) ;
99+
100+ const loadingElement = screen . queryByTestId ( 'circle-progress' ) ;
101+ expect ( loadingElement ) . toBeInTheDocument ( ) ;
55102 } ) ;
56103 } ) ;
57104
58- describe ( 'and metrics are enabled' , ( ) => {
59- const flags = {
60- aclpLogs : {
61- enabled : true ,
62- beta : false ,
63- metricsEnabled : true ,
64- } ,
65- } ;
105+ describe ( 'and stream request threw error' , ( ) => {
106+ const streamErrorMessage = 'Stream not found' ;
107+ beforeEach ( async ( ) => {
108+ queryMocks . useStreamQuery . mockReturnValue ( {
109+ isLoading : false ,
110+ error : [ { reason : streamErrorMessage } ] ,
111+ } ) ;
112+ } ) ;
113+
114+ it ( 'should render error state with message' , async ( ) => {
115+ renderComponent ( { } ) ;
66116
67- it ( 'should render the summary tab and metrics tab' , async ( ) => {
68- renderComponent ( flags ) ;
117+ expect ( screen . queryByText ( 'Summary' ) ) . not . toBeInTheDocument ( ) ;
118+ expect ( screen . queryByText ( 'Metrics' ) ) . not . toBeInTheDocument ( ) ;
69119
70- screen . getByText ( 'Summary' ) ;
71- expect ( screen . queryByText ( 'Metrics' ) ) . toBeInTheDocument ( ) ;
120+ expect ( screen . queryByText ( streamErrorMessage ) ) . toBeInTheDocument ( ) ;
72121 } ) ;
73122 } ) ;
74123} ) ;
0 commit comments