fix(web): offset sticky table headers below layout header
This commit is contained in:
@@ -32,7 +32,10 @@ for (const [file, width] of files) {
|
||||
test(`${file} 保留表头吸顶、分页和固定列`, () => {
|
||||
assert.equal(tables.length, 1);
|
||||
const props = tables[0].attributes.properties;
|
||||
assert.ok(props.some(prop => prop.name?.getText(source) === 'sticky'));
|
||||
const sticky = props.find(prop => prop.name?.getText(source) === 'sticky');
|
||||
assert.ok(sticky?.initializer && ts.isJsxExpression(sticky.initializer), '表头吸顶必须预留顶部栏高度');
|
||||
assert.equal(sticky.initializer.expression.getText(source), 'sticky');
|
||||
assert.match(code, /const sticky = useTableSticky\(\);/);
|
||||
assert.match(code, /pagination=\{tablePagination\(\)\}/);
|
||||
assert.doesNotMatch(code, /pagination=\{false\}/);
|
||||
assert.match(code, /\.\.\.fixedLeft</);
|
||||
@@ -67,9 +70,45 @@ const tableCode = ts.transpileModule(readFileSync(tableFile, 'utf8'), {
|
||||
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022 },
|
||||
}).outputText;
|
||||
const tableModule = { exports: {} };
|
||||
vm.runInNewContext(tableCode, { exports: tableModule.exports }, { filename: tableFile });
|
||||
const routeContext = {}, proProvider = {};
|
||||
let layout = {}, token = {};
|
||||
vm.runInNewContext(tableCode, { exports: tableModule.exports, require: id => {
|
||||
if (id === '@ant-design/pro-components') return { RouteContext: routeContext, ProProvider: proProvider };
|
||||
if (id === 'react') return { useContext: context => context === routeContext ? layout : { token } };
|
||||
throw new Error(`Unexpected import: ${id}`);
|
||||
} }, { filename: tableFile });
|
||||
const helpers = tableModule.exports;
|
||||
|
||||
test('mix 布局默认固定顶部栏,表头须避让;自定义高度随布局更新', () => {
|
||||
for (const height of [56, 72, 96]) {
|
||||
for (const isMobile of [false, true]) {
|
||||
layout = { hasHeader: true, layout: 'mix', fixedHeader: false, isMobile };
|
||||
token = { layout: { header: { heightLayoutHeader: height } } };
|
||||
assert.equal(helpers.useTableSticky().offsetHeader, height);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('遵循 ProLayout 默认顶部栏高度', () => {
|
||||
layout = { hasHeader: true, layout: 'mix' };
|
||||
token = {};
|
||||
assert.equal(helpers.useTableSticky().offsetHeader, 56);
|
||||
});
|
||||
|
||||
test('其他布局只在存在固定顶部栏时预留高度', () => {
|
||||
token = { layout: { header: { heightLayoutHeader: 72 } } };
|
||||
for (const kind of ['top', 'side']) {
|
||||
for (const hasHeader of [false, true]) {
|
||||
for (const fixedHeader of [false, true]) {
|
||||
layout = { layout: kind, hasHeader, fixedHeader };
|
||||
assert.equal(helpers.useTableSticky().offsetHeader, hasHeader && fixedHeader ? 72 : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
layout = { layout: 'mix', hasHeader: false, fixedHeader: true };
|
||||
assert.equal(helpers.useTableSticky().offsetHeader, 0);
|
||||
});
|
||||
|
||||
test('分页仍为每页 20 条,单页隐藏分页条', () => {
|
||||
assert.equal(helpers.TABLE_PAGE_SIZE, 20);
|
||||
const pagination = helpers.tablePagination();
|
||||
|
||||
Reference in New Issue
Block a user