Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"aria-rowcount",
"mdsvex",
"viewports"
]
],
"js/ts.experimental.useTsgo": false
}
46 changes: 15 additions & 31 deletions src/lib/Tr/RsTr.svelte.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,28 @@ import { page } from 'vitest/browser';
import { render } from 'vitest-browser-svelte';
import type { TableContextOptions } from '$lib/types.js';
import Layout from '$lib/tests/Layout.svelte';
// @ts-expect-error TS2614
import { children1Col, childrenEmptyCell, emptyContent } from '$lib/tests/TestSnippets.svelte';
import { flushSync } from 'svelte';

describe('RsTr', () => {
test('Should render data rows as lists.', async () => {
const optionsCtx: TableContextOptions = {
const ctxOptions: TableContextOptions = {
breakpoint: window.innerWidth,
};
render(Layout, {
props: {
optionsCtx,
ctxOptions,
children: children1Col,
},
});
await expect.element(page.getByRole('list')).toBeInTheDocument();
});
test('Should render header content as list items.', async () => {
const optionsCtx: TableContextOptions = {
const ctxOptions: TableContextOptions = {
breakpoint: window.innerWidth,
};
render(Layout, {
props: {
optionsCtx,
ctxOptions,
children: children1Col,
},
});
Expand All @@ -35,12 +33,12 @@ describe('RsTr', () => {
expect(el.textContent).toBe('Header 1');
});
test("Should render data content inside the element of role 'cell'.", async () => {
const optionsCtx: TableContextOptions = {
const ctxOptions: TableContextOptions = {
breakpoint: window.innerWidth,
};
render(Layout, {
props: {
optionsCtx,
ctxOptions,
children: children1Col,
},
});
Expand All @@ -49,12 +47,12 @@ describe('RsTr', () => {
expect(el.textContent).toBe('Cell 1');
});
test("Should render the element of role 'cell' with the expected attributes.", async () => {
const optionsCtx: TableContextOptions = {
const ctxOptions: TableContextOptions = {
breakpoint: window.innerWidth,
};
render(Layout, {
props: {
optionsCtx,
ctxOptions,
children: children1Col,
},
});
Expand All @@ -66,12 +64,12 @@ describe('RsTr', () => {
});
describe('Empty cell content', () => {
test('Should not render the term element for empty cells.', async () => {
const optionsCtx: TableContextOptions = {
const ctxOptions: TableContextOptions = {
breakpoint: window.innerWidth,
};
render(Layout, {
props: {
optionsCtx,
ctxOptions,
children: childrenEmptyCell,
},
});
Expand All @@ -89,30 +87,16 @@ describe('RsTr', () => {
contentType: 'snippet',
}
])('#7: Should render the $contentType empty content on empty cells.', async ({ emptyCellContent }) => {
let tableCtx: TableContextOptions | undefined;
const ctxOptions: TableContextOptions = {
breakpoint: window.innerWidth,
emptyCellContent,
};
await render(Layout, {
props: {
ctxOptions,
children: childrenEmptyCell,
get tableCtx() {
return tableCtx;
},
set tableCtx(value) {
tableCtx = value;
}
},
});
/*
There's something different in the test environment than real browsers: If I pass optionsCtx to initialize
the context with non-default values, the TestContext constructor doesn't receive the optionsCtx object I
assign via the options.props property of the render() function. It claims that "options" is undefined.

The weird thing is that all other tests work fine with the optionsCtx object passed to the render()
function. I don't know why this test is different, but I can work around it by setting the context values
after the render() function is called.
*/
tableCtx!.breakpoint = window.innerWidth;
tableCtx!.emptyCellContent = emptyCellContent;
flushSync();
const els = page.getByRole('cell').all();
expect(els).toHaveLength(2);
await expect.element(els[0]).toBeInTheDocument();
Expand Down
Loading