@@ -15,13 +15,18 @@ import { describe, expect, it } from "vitest";
1515import { NULL_LAG_TEXT } from "~/api/materialize/freshness/lagHistory" ;
1616import { renderComponent } from "~/test/utils" ;
1717
18+ import { FreshnessScope } from "./constants" ;
1819import { FreshnessRow , UNREADABLE } from "./freshnessRows" ;
1920import { FreshnessTable } from "./FreshnessTable" ;
2021
2122const buildRow = ( overrides : Partial < FreshnessRow > ) : FreshnessRow => ( {
2223 key : "u1" ,
2324 objectName : "orders_mv" ,
24- namespace : "materialize.public" ,
25+ databaseName : "materialize" ,
26+ schemaId : "u3" ,
27+ schemaName : "public" ,
28+ clusterId : "u1" ,
29+ clusterName : "quickstart" ,
2530 objectType : "materialized-view" ,
2631 hydratedReplicas : 2 ,
2732 totalReplicas : 2 ,
@@ -64,15 +69,15 @@ const rows: FreshnessRow[] = [
6469
6570describe ( "FreshnessTable" , ( ) => {
6671 it ( "lists every object, over threshold or not" , async ( ) => {
67- await renderComponent ( < FreshnessTable rows = { rows } /> ) ;
72+ await renderComponent ( < FreshnessTable rows = { rows } scope = "cluster" /> ) ;
6873
6974 expect ( await screen . findByText ( "orders_mv" ) ) . toBeVisible ( ) ;
7075 expect ( screen . getByText ( "users_idx" ) ) . toBeVisible ( ) ;
7176 expect ( screen . getByText ( "legacy_sink" ) ) . toBeVisible ( ) ;
7277 } ) ;
7378
7479 it ( "marks only the rows drawn on the graph" , async ( ) => {
75- await renderComponent ( < FreshnessTable rows = { rows } /> ) ;
80+ await renderComponent ( < FreshnessTable rows = { rows } scope = "cluster" /> ) ;
7681
7782 // The swatch is the only link between a row and its line, so an extra or a
7883 // missing one misattributes.
@@ -84,15 +89,15 @@ describe("FreshnessTable", () => {
8489 } ) ;
8590
8691 it ( "renders a missing reading as a dash rather than a zero" , async ( ) => {
87- await renderComponent ( < FreshnessTable rows = { rows } /> ) ;
92+ await renderComponent ( < FreshnessTable rows = { rows } scope = "cluster" /> ) ;
8893
8994 const nullRow = ( await screen . findByText ( "legacy_sink" ) ) . closest ( "tr" ) ;
9095 // An object with no reading has not been measured at zero lag.
9196 expect ( within ( nullRow ! ) . getAllByText ( "—" ) ) . toHaveLength ( 3 ) ;
9297 } ) ;
9398
9499 it ( "labels hydration with the same buckets as the other tables" , async ( ) => {
95- await renderComponent ( < FreshnessTable rows = { rows } /> ) ;
100+ await renderComponent ( < FreshnessTable rows = { rows } scope = "cluster" /> ) ;
96101
97102 // Three buckets, not a boolean: "hydrating" is a real state, and collapsing
98103 // it into "not hydrated" would misreport an object that is catching up.
@@ -101,7 +106,7 @@ describe("FreshnessTable", () => {
101106 } ) ;
102107
103108 it ( "sorts on a column when its header is clicked" , async ( ) => {
104- await renderComponent ( < FreshnessTable rows = { rows } /> ) ;
109+ await renderComponent ( < FreshnessTable rows = { rows } scope = "cluster" /> ) ;
105110
106111 await userEvent . click ( await screen . findByText ( / ^ O b j e c t / ) ) ;
107112 const names = screen
@@ -116,6 +121,7 @@ describe("FreshnessTable", () => {
116121 // the screen.
117122 await renderComponent (
118123 < FreshnessTable
124+ scope = "cluster"
119125 rows = { [
120126 buildRow ( {
121127 key : "u9" ,
@@ -135,19 +141,37 @@ describe("FreshnessTable", () => {
135141 expect ( screen . queryByText ( / ∞ | I n f i n i t y / ) ) . not . toBeInTheDocument ( ) ;
136142 } ) ;
137143
138- it ( "links each object to its detail drawer" , async ( ) => {
139- await renderComponent ( < FreshnessTable rows = { rows } /> ) ;
144+ it ( "links every type the page shows to its workflow graph" , async ( ) => {
145+ // Tables included: they appear by schema, and the Maintained Objects
146+ // drawer has nothing to show for one.
147+ const typed = [
148+ buildRow ( { key : "u1" , objectName : "t" , objectType : "table" } ) ,
149+ buildRow ( { key : "u2" , objectName : "s" , objectType : "source" } ) ,
150+ buildRow ( { key : "u3" , objectName : "m" , objectType : "materialized-view" } ) ,
151+ buildRow ( { key : "u4" , objectName : "i" , objectType : "index" } ) ,
152+ buildRow ( { key : "u5" , objectName : "k" , objectType : "sink" } ) ,
153+ ] ;
154+ await renderComponent ( < FreshnessTable rows = { typed } scope = "cluster" /> ) ;
140155
141- const link = await screen . findByRole ( "link" , { name : "orders_mv" } ) ;
142- // A link rather than a row handler, so it is reachable without a mouse.
143- expect ( link ) . toHaveAttribute (
144- "href" ,
145- expect . stringContaining ( "/maintained-objects/u1" ) ,
156+ const hrefs = await Promise . all (
157+ typed . map ( async ( row ) =>
158+ ( await screen . findByRole ( "link" , { name : row . objectName } ) )
159+ . getAttribute ( "href" )
160+ ?. replace ( / ^ .* \/ o b j e c t s \/ / , "" ) ,
161+ ) ,
146162 ) ;
163+ // A link rather than a row handler, so it is reachable without a mouse.
164+ expect ( hrefs ) . toEqual ( [
165+ "materialize/schemas/public/tables/t/u1/workflow" ,
166+ "materialize/schemas/public/sources/s/u2/workflow" ,
167+ "materialize/schemas/public/materialized-views/m/u3/workflow" ,
168+ "materialize/schemas/public/indexes/i/u4/workflow" ,
169+ "materialize/schemas/public/sinks/k/u5/workflow" ,
170+ ] ) ;
147171 } ) ;
148172
149173 it ( "opens sorted worst first" , async ( ) => {
150- await renderComponent ( < FreshnessTable rows = { rows } /> ) ;
174+ await renderComponent ( < FreshnessTable rows = { rows } scope = "cluster" /> ) ;
151175
152176 await screen . findByText ( "orders_mv" ) ;
153177 const names = screen
@@ -168,11 +192,77 @@ describe("FreshnessTable", () => {
168192 peak : 1_000 + i ,
169193 } ) ,
170194 ) ;
171- await renderComponent ( < FreshnessTable rows = { many } /> ) ;
195+ await renderComponent ( < FreshnessTable rows = { many } scope = "cluster" /> ) ;
172196
173197 await screen . findByText ( "object_00" ) ;
174198 // 25 rows plus the header.
175199 expect ( screen . getAllByRole ( "row" ) ) . toHaveLength ( 26 ) ;
176200 expect ( screen . queryByText ( "object_59" ) ) . not . toBeInTheDocument ( ) ;
177201 } ) ;
178202} ) ;
203+
204+ describe ( "FreshnessTable placement column" , ( ) => {
205+ const renderAt = (
206+ scope : FreshnessScope ,
207+ search : string ,
208+ tableRows : FreshnessRow [ ] ,
209+ ) =>
210+ renderComponent ( < FreshnessTable rows = { tableRows } scope = { scope } /> , {
211+ initialRouterEntries : [ search ] ,
212+ } ) ;
213+ const searchOf = ( link : HTMLElement ) =>
214+ new URLSearchParams ( link . getAttribute ( "href" ) ?. split ( "?" ) [ 1 ] ) ;
215+
216+ it ( "by cluster, shows each object's schema, linking to that schema" , async ( ) => {
217+ await renderAt ( "cluster" , "/?cluster=u1&threshold=5000&type=index,sink" , [
218+ buildRow ( { } ) ,
219+ ] ) ;
220+
221+ expect (
222+ await screen . findByRole ( "columnheader" , { name : "Schema" } ) ,
223+ ) . toBeVisible ( ) ;
224+ // Once, in its column: the line that used to repeat it under the name is
225+ // gone.
226+ expect ( screen . getAllByText ( "materialize.public" ) ) . toHaveLength ( 1 ) ;
227+ const search = searchOf (
228+ screen . getByRole ( "link" , { name : "materialize.public" } ) ,
229+ ) ;
230+ expect ( search . get ( "scope" ) ) . toBe ( "schema" ) ;
231+ expect ( search . get ( "schema" ) ) . toBe ( "u3" ) ;
232+ expect ( search . get ( "cluster" ) ) . toBeNull ( ) ;
233+ // The reader's other controls survive the jump.
234+ expect ( search . get ( "threshold" ) ) . toBe ( "5000" ) ;
235+ expect ( search . get ( "type" ) ) . toBe ( "index,sink" ) ;
236+ } ) ;
237+
238+ it ( "by schema, shows each object's cluster, linking to that cluster" , async ( ) => {
239+ await renderAt ( "schema" , "/?scope=schema&schema=u3&type=table,index" , [
240+ buildRow ( { } ) ,
241+ ] ) ;
242+
243+ expect (
244+ await screen . findByRole ( "columnheader" , { name : "Cluster" } ) ,
245+ ) . toBeVisible ( ) ;
246+ const search = searchOf ( screen . getByRole ( "link" , { name : "quickstart" } ) ) ;
247+ expect ( search . get ( "scope" ) ) . toBe ( "cluster" ) ;
248+ expect ( search . get ( "cluster" ) ) . toBe ( "u1" ) ;
249+ expect ( search . get ( "schema" ) ) . toBeNull ( ) ;
250+ // A cluster never holds a table, so that filter cannot follow.
251+ expect ( search . get ( "type" ) ) . toBe ( "index" ) ;
252+ } ) ;
253+
254+ it ( "by schema, shows no cluster for a table" , async ( ) => {
255+ await renderAt ( "schema" , "/?scope=schema&schema=u3" , [
256+ buildRow ( {
257+ objectName : "orders" ,
258+ objectType : "table" ,
259+ clusterId : null ,
260+ clusterName : null ,
261+ } ) ,
262+ ] ) ;
263+
264+ const row = ( await screen . findByText ( "orders" ) ) . closest ( "tr" ) ;
265+ expect ( within ( row ! ) . getAllByRole ( "link" ) ) . toHaveLength ( 1 ) ;
266+ expect ( within ( row ! ) . getAllByText ( "—" ) . length ) . toBeGreaterThan ( 0 ) ;
267+ } ) ;
268+ } ) ;
0 commit comments