-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: table component should be scoped when searching items (#10211)
* fix: table component should be scoped when searching items it was searching items on the whole document/page it should only search in its children fixes podman-desktop/podman-desktop#10210 Signed-off-by: Florent Benoit <[email protected]>
- Loading branch information
Showing
5 changed files
with
164 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/********************************************************************** | ||
* Copyright (C) 2024 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
***********************************************************************/ | ||
|
||
import '@testing-library/jest-dom/vitest'; | ||
|
||
import { render, screen, within } from '@testing-library/svelte'; | ||
import { tick } from 'svelte'; | ||
import { expect, test } from 'vitest'; | ||
|
||
import TestMultiTables from './TestMultiTables.svelte'; | ||
|
||
test('Expect each table receive its own grid-tables-column values', async () => { | ||
const extractGridTableColumnsWidth = async (tableName: string): Promise<string> => { | ||
const table = await screen.findByRole('table', { name: tableName }); | ||
expect(table).toBeDefined(); | ||
|
||
// get the elements having the role "row" inside the table html element | ||
const rows = await within(table).findAllByRole('row'); | ||
const gridTableColumnsValuesSet = new Set<string>(); | ||
for (const element of rows) { | ||
gridTableColumnsValuesSet.add(element.style.gridTemplateColumns); | ||
} | ||
|
||
// all values should be the same in the set gridTableColumnsValues | ||
const items = Array.from(gridTableColumnsValuesSet.values()); | ||
expect(items.length).toBe(1); | ||
|
||
const item = items[0]; | ||
|
||
// split by space and keep the second value | ||
const values = item.split(' '); | ||
|
||
expect(values.length).toBe(3); | ||
|
||
return values[1]; | ||
}; | ||
|
||
render(TestMultiTables, {}); | ||
|
||
// Wait for the tables to update | ||
await tick(); | ||
|
||
// expect to receive for each table, the good values of the width (which is different for each table) | ||
const gridTableColumnsValuesPersonWidth = await extractGridTableColumnsWidth('person'); | ||
expect(gridTableColumnsValuesPersonWidth).toBe('3fr'); | ||
|
||
const gridTableColumnsValuesBookWidth = await extractGridTableColumnsWidth('book'); | ||
expect(gridTableColumnsValuesBookWidth).toBe('2fr'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<script lang="ts"> | ||
import SimpleColumn from './SimpleColumn.svelte'; | ||
import { Column, Row } from './table'; | ||
import Table from './Table.svelte'; | ||
let personTable: Table; | ||
let bookTable: Table; | ||
type Person = { | ||
name: string; | ||
}; | ||
type Book = { | ||
title: string; | ||
name?: string; | ||
}; | ||
const persons: Person[] = [{ name: 'James' }, { name: 'John' }, { name: 'Robert' }]; | ||
const books: Book[] = [ | ||
{ title: 'Twenty Thousand Leagues Under the Seas' }, | ||
{ title: 'From the Earth to the Moon' }, | ||
{ title: 'Around the World in Eighty Days' }, | ||
{ title: 'From the Earth to the Moon' }, | ||
]; | ||
export const nameColPerson: Column<Person, string> = new Column('Name', { | ||
width: '3fr', | ||
renderMapping: obj => obj.name, | ||
renderer: SimpleColumn, | ||
comparator: (a, b) => a.name.localeCompare(b.name), | ||
}); | ||
const columnsPerson = [nameColPerson]; | ||
const rowPerson = new Row<Person>({}); | ||
export const titleColBook: Column<Book, string> = new Column('Title', { | ||
width: '2fr', | ||
renderMapping: obj => obj.title, | ||
renderer: SimpleColumn, | ||
comparator: (a, b) => a.title.localeCompare(b.title), | ||
}); | ||
const columnsBook = [titleColBook]; | ||
const rowBook = new Row<Book>({}); | ||
</script> | ||
|
||
<Table | ||
kind="person" | ||
bind:this={personTable} | ||
data={persons} | ||
columns={columnsPerson} | ||
row={rowPerson} | ||
defaultSortColumn="Name"> | ||
</Table> | ||
|
||
<Table | ||
kind="book" | ||
bind:this={bookTable} | ||
data={books} | ||
columns={columnsBook} | ||
row={rowBook} | ||
defaultSortColumn="Title"> | ||
</Table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters