1+ /**
2+ * Licensed to the Apache Software Foundation (ASF) under one or more
3+ * contributor license agreements. See the NOTICE file distributed with
4+ * this work for additional information regarding copyright ownership.
5+ * The ASF licenses this file to You under the Apache License, Version 2.0
6+ * (the "License"); you may not use this file except in compliance with
7+ * the License. You may obtain a copy of the License at
8+ *
9+ * http://www.apache.org/licenses/LICENSE-2.0
10+ *
11+ * Unless required by applicable law or agreed to in writing, software
12+ * distributed under the License is distributed on an "AS IS" BASIS,
13+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ * See the License for the specific language governing permissions and
15+ * limitations under the License.
16+ */
17+
18+ import { routesPom } from '@e2e/pom/routes' ;
19+ import { e2eReq } from '@e2e/utils/req' ;
20+ import { test } from '@e2e/utils/test' ;
21+ import { expect } from '@playwright/test' ;
22+
23+ import { deleteAllRoutes , putRouteReq } from '@/apis/routes' ;
24+ import { API_ROUTES } from '@/config/constant' ;
25+ import type { APISIXType } from '@/types/schema/apisix' ;
26+
27+ // Sample routes for testing search functionality
28+ const testRoutes : APISIXType [ 'Route' ] [ ] = [
29+ {
30+ id : 'search_route_1' ,
31+ name : 'alpha_route' ,
32+ uri : '/alpha' ,
33+ desc : 'First test route' ,
34+ methods : [ 'GET' ] ,
35+ upstream : {
36+ nodes : [ { host : '127.0.0.1' , port : 80 , weight : 100 } ] ,
37+ } ,
38+ } ,
39+ {
40+ id : 'search_route_2' ,
41+ name : 'beta_route' ,
42+ uri : '/beta' ,
43+ desc : 'Second test route' ,
44+ methods : [ 'POST' ] ,
45+ upstream : {
46+ nodes : [ { host : '127.0.0.1' , port : 80 , weight : 100 } ] ,
47+ } ,
48+ } ,
49+ {
50+ id : 'search_route_3' ,
51+ name : 'gamma_route' ,
52+ uri : '/gamma' ,
53+ desc : 'Third test route' ,
54+ methods : [ 'GET' ] ,
55+ upstream : {
56+ nodes : [ { host : '127.0.0.1' , port : 80 , weight : 100 } ] ,
57+ } ,
58+ } ,
59+ ] ;
60+
61+ test . describe ( 'Routes search functionality' , ( ) => {
62+ test . describe . configure ( { mode : 'serial' } ) ;
63+
64+ test . beforeAll ( async ( ) => {
65+ await deleteAllRoutes ( e2eReq ) ;
66+ await Promise . all ( testRoutes . map ( ( route ) => putRouteReq ( e2eReq , route ) ) ) ;
67+ } ) ;
68+
69+ test . afterAll ( async ( ) => {
70+ await Promise . all (
71+ testRoutes . map ( ( route ) => e2eReq . delete ( `${ API_ROUTES } /${ route . id } ` ) )
72+ ) ;
73+ } ) ;
74+
75+ test ( 'should filter routes by name' , async ( { page } ) => {
76+ await test . step ( 'navigate to routes page' , async ( ) => {
77+ await routesPom . getRouteNavBtn ( page ) . click ( ) ;
78+ await routesPom . isIndexPage ( page ) ;
79+ } ) ;
80+
81+ await test . step ( 'search for routes with "alpha" in name' , async ( ) => {
82+ const nameInput = page . getByLabel ( 'Name' ) ; // Matches the label from SearchForm
83+ await nameInput . fill ( 'alpha' ) ;
84+ const searchButton = page . getByRole ( 'button' , { name : 'Search' } ) ;
85+ await searchButton . click ( ) ;
86+
87+ // Wait for table to update
88+ await expect ( page . getByText ( 'alpha_route' ) ) . toBeVisible ( ) ;
89+
90+ // Verify only matching route is shown
91+ const tableRows = page . getByRole ( 'row' ) ;
92+ await expect ( tableRows ) . toHaveCount ( 2 ) ; // Header + 1 data row
93+ await expect ( page . getByText ( 'beta_route' ) ) . toBeHidden ( ) ;
94+ await expect ( page . getByText ( 'gamma_route' ) ) . toBeHidden ( ) ;
95+ } ) ;
96+
97+ await test . step ( 'reset search and verify all routes are shown' , async ( ) => {
98+ const resetButton = page . getByRole ( 'button' , { name : 'Reset' } ) ;
99+ await resetButton . click ( ) ;
100+
101+ // Wait for table to update
102+ await expect ( page . getByText ( 'beta_route' ) ) . toBeVisible ( ) ;
103+
104+ // Verify all routes are back
105+ const tableRows = page . getByRole ( 'row' ) ;
106+ await expect ( tableRows ) . toHaveCount ( 4 ) ; // Header + 3 data rows
107+ await expect ( page . getByText ( 'alpha_route' ) ) . toBeVisible ( ) ;
108+ await expect ( page . getByText ( 'gamma_route' ) ) . toBeVisible ( ) ;
109+ } ) ;
110+ } ) ;
111+
112+ test ( 'should show no results for non-matching search' , async ( { page } ) => {
113+ await test . step ( 'navigate to routes page' , async ( ) => {
114+ await routesPom . getRouteNavBtn ( page ) . click ( ) ;
115+ await routesPom . isIndexPage ( page ) ;
116+ } ) ;
117+
118+ await test . step ( 'search for non-existent name' , async ( ) => {
119+ const nameInput = page . getByLabel ( 'Name' ) ;
120+ await nameInput . fill ( 'nonexistent' ) ;
121+ const searchButton = page . getByRole ( 'button' , { name : 'Search' } ) ;
122+ await searchButton . click ( ) ;
123+
124+ // Wait for table to update
125+ await expect ( page . getByText ( 'No Data' ) ) . toBeVisible ( ) ; // Assuming Antd's empty state
126+ } ) ;
127+ } ) ;
128+ } ) ;
0 commit comments