Skip to content

Commit 308f2b5

Browse files
committed
chore(types): fix up tests for new types, and add more type tests for plugin APIs
1 parent 791848e commit 308f2b5

File tree

4 files changed

+41
-10
lines changed

4 files changed

+41
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { expectTypeOf } from 'expect-type';
2+
3+
import { ColumnReordering } from '../../plugins/column-reordering';
4+
import { ColumnResizing } from '../../plugins/column-resizing';
5+
import { DataSorting } from '../../plugins/data-sorting';
6+
7+
import type { Table } from '[public-types]';
8+
9+
// We're testing types, not behaviors
10+
const x = 0 as unknown as Table<{ x: number }>;
11+
12+
//////////////////////////////
13+
// <Table>#pluginOf
14+
expectTypeOf(x.pluginOf(DataSorting)).toEqualTypeOf<DataSorting | undefined>();
15+
expectTypeOf(x.pluginOf(ColumnReordering)).toEqualTypeOf<ColumnReordering | undefined>();
16+
expectTypeOf(x.pluginOf(ColumnResizing)).toEqualTypeOf<ColumnResizing | undefined>();

ember-headless-table/src/-private/-type-tests/table-config.test.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import { expectTypeOf } from 'expect-type';
22

33
import { BasePlugin } from '../../plugins/-private/base';
44
import { ColumnReordering } from '../../plugins/column-reordering';
5-
import { Plugins } from '../../plugins/-private/utils';
6-
import { DataSorting, SortItem } from '../../plugins/data-sorting';
75
import { ColumnResizing } from '../../plugins/column-resizing';
86
import { ColumnVisibility } from '../../plugins/column-visibility';
7+
import { DataSorting } from '../../plugins/data-sorting';
98
import { StickyColumns } from '../../plugins/sticky-columns';
109

10+
import type { Plugins } from '../../plugins/-private/utils';
11+
import type { SortItem } from '../../plugins/data-sorting';
1112
import type { Plugin } from '[public-plugin-types]';
1213
import type { TableConfig } from '[public-types]';
1314
import type { Constructor } from '#private-types';
@@ -26,8 +27,10 @@ expectTypeOf<
2627
[Constructor<BasePlugin>, Constructor<BasePlugin>]
2728
>().toMatchTypeOf<TablePluginConfig>();
2829

29-
class SomeClass { foo = 'bar' }
30-
class LocalPlugin extends BasePlugin<{ Meta: { Table: SomeClass} }> {
30+
class SomeClass {
31+
foo = 'bar';
32+
}
33+
class LocalPlugin extends BasePlugin<{ Meta: { Table: SomeClass } }> {
3134
name = 'local-plugin';
3235
}
3336

@@ -51,8 +54,10 @@ expectTypeOf([StickyColumns]).toMatchTypeOf<TablePluginConfig>();
5154
// The various ways to define plugins
5255
expectTypeOf([DataSorting, ColumnReordering]).toMatchTypeOf<TablePluginConfig>();
5356

54-
const onSort = (_sorts: SortItem<number>[]) => {};
57+
const onSort = (_sorts: SortItem<number>[]) => {
58+
/* intentionally empty */
59+
};
5560
const sorts: SortItem<number>[] = [];
56-
expectTypeOf([DataSorting.with(() => ({ }))]).toMatchTypeOf<TablePluginConfig>();
57-
expectTypeOf([DataSorting.with(() => ({ onSort, sorts }))]).toMatchTypeOf<TablePluginConfig>();
5861

62+
expectTypeOf([DataSorting.with(() => ({}))]).toMatchTypeOf<TablePluginConfig>();
63+
expectTypeOf([DataSorting.with(() => ({ onSort, sorts }))]).toMatchTypeOf<TablePluginConfig>();

ember-headless-table/src/-private/table.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export class Table<DataType = unknown> extends Resource<Signature<DataType>> {
178178
/**
179179
* Get the active plugin instance for the given plugin class
180180
*/
181-
pluginOf<Instance extends BasePlugin>(klass: Class<Instance>): Instance | undefined {
181+
pluginOf<Instance extends BasePlugin<any>>(klass: Class<Instance>): Instance | undefined {
182182
let result = this.plugins.find((plugin) => plugin instanceof klass);
183183

184184
/**

test-app/tests/plugins/queries/meta-test.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,23 @@ module('Plugins | Queries | meta', function (hooks) {
230230
});
231231

232232
module('withFeature', function () {
233-
class FeatureProvidingPlugin extends BasePlugin {
233+
class FeatureProvidingPlugin extends BasePlugin<{
234+
Meta: {
235+
Table: TestTableMeta;
236+
Column: TestColumnMeta;
237+
};
238+
}> {
234239
static features = ['feature-a'];
235240
name = 'queries-feature-a-test-plugin';
236241
meta = { column: TestColumnMeta, table: TestTableMeta };
237242
}
238243

239-
class FeatureProvidingPlugin2 extends BasePlugin {
244+
class FeatureProvidingPlugin2 extends BasePlugin<{
245+
Meta: {
246+
Table: TestTableMeta;
247+
Column: TestColumnMeta;
248+
};
249+
}> {
240250
static features = ['feature-b'];
241251
name = 'queries-feature-b-test-plugin';
242252
meta = { column: TestColumnMeta, table: TestTableMeta };

0 commit comments

Comments
 (0)