vitess.io/vitess@v0.16.2/web/vtadmin/src/components/routes/Tablets.test.tsx (about) 1 /** 2 * Copyright 2021 The Vitess Authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 import { vtadmin as pb, topodata } from '../../proto/vtadmin'; 17 import { formatRows } from './Tablets'; 18 19 describe('Tablets', () => { 20 describe('filterRows', () => { 21 const tests: { 22 name: string; 23 filter: string | null; 24 tablets: pb.Tablet[] | null; 25 // Undefined `expected` keys will be ignored. 26 // Unfortunately, Partial<ReturnType<typeof formatRows>> does not 27 // work as expected + requires all property keys to be defined. 28 expected: { [k: string]: unknown }[]; 29 }[] = [ 30 { 31 name: 'empty tablets', 32 filter: null, 33 tablets: null, 34 expected: [], 35 }, 36 { 37 name: 'sort by primary first, then other tablet types alphabetically', 38 filter: null, 39 tablets: [ 40 pb.Tablet.create({ 41 tablet: { 42 alias: { 43 cell: 'cell1', 44 uid: 4, 45 }, 46 type: topodata.TabletType.BACKUP, 47 }, 48 }), 49 pb.Tablet.create({ 50 tablet: { 51 alias: { 52 cell: 'cell1', 53 uid: 2, 54 }, 55 type: topodata.TabletType.REPLICA, 56 }, 57 }), 58 pb.Tablet.create({ 59 tablet: { 60 alias: { 61 cell: 'cell1', 62 uid: 3, 63 }, 64 type: topodata.TabletType.PRIMARY, 65 }, 66 }), 67 pb.Tablet.create({ 68 tablet: { 69 alias: { 70 cell: 'cell1', 71 uid: 1, 72 }, 73 type: topodata.TabletType.REPLICA, 74 }, 75 }), 76 ], 77 expected: [ 78 { alias: 'cell1-3', type: 'PRIMARY' }, 79 { alias: 'cell1-4', type: 'BACKUP' }, 80 { alias: 'cell1-1', type: 'REPLICA' }, 81 { alias: 'cell1-2', type: 'REPLICA' }, 82 ], 83 }, 84 ]; 85 86 test.each(tests.map(Object.values))( 87 '%s', 88 (name: string, filter: string, tablets: pb.Tablet[], expected: { [k: string]: unknown }[]) => { 89 const result = formatRows(tablets, [], filter); 90 expect(result).toMatchObject(expected); 91 } 92 ); 93 }); 94 });