Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ui-kit): Add tests for types #32678

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions packages/ui-kit/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module.exports = {
module.exports = /** @satisfies {import('jest').Config} */ ({
preset: 'ts-jest',
testEnvironment: 'node',
errorOnDeprecated: true,
testMatch: ['<rootDir>/src/**/*.spec.[jt]s?(x)'],
};
setupFilesAfterEnv: ['<rootDir>/src/jest-setup.ts'],
collectCoverage: true,
});
5 changes: 3 additions & 2 deletions packages/ui-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
"build": "run-s .:build:prepare .:build:clean .:build:esm .:build:cjs",
".:build:prepare": "ts-patch install && typia patch",
".:build:clean": "rimraf dist",
".:build:esm": "tsc -p tsconfig.json",
".:build:cjs": "tsc -p tsconfig-cjs.json",
".:build:esm": "tsc -p tsconfig.esm.json",
".:build:cjs": "tsc -p tsconfig.cjs.json",
"typecheck": "tsc --noEmit",
"lint": "eslint . --ext .ts,.tsx",
"test": "jest"
},
Expand Down
6 changes: 6 additions & 0 deletions packages/ui-kit/src/blocks/BlockElementType.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { BlockElement } from './BlockElement';
import type { BlockElementType } from './BlockElementType';

it("should be enum for `BlockElement['type']`", () => {
expect<Expect<EnumToMatchTaggedUnionTags<typeof BlockElementType, BlockElement, 'type'>>>(true).toBeTruthy();
});
7 changes: 0 additions & 7 deletions packages/ui-kit/src/blocks/BlockElementType.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { BlockElement } from './BlockElement';

export enum BlockElementType {
BUTTON = 'button',
IMAGE = 'image',
Expand Down Expand Up @@ -29,8 +27,3 @@ export enum BlockElementType {
TIME_PICKER = 'time_picker',
TAB = 'tab',
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
type AssertEnumKeysFromBlockUnionTypes = {
[B in BlockElement as Uppercase<B['type']>]: (typeof BlockElementType)[Uppercase<B['type']>];
};
6 changes: 6 additions & 0 deletions packages/ui-kit/src/blocks/LayoutBlock.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { LayoutBlock } from './LayoutBlock';
import type { LayoutBlockish } from './LayoutBlockish';

it('should have the same shape of `LayoutBlockish<{}>`', () => {
expect<Expect<Required<LayoutBlock> extends Required<LayoutBlockish<object>> ? true : false>>(true).toBeTruthy();
});
6 changes: 6 additions & 0 deletions packages/ui-kit/src/blocks/LayoutBlockType.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { LayoutBlock } from './LayoutBlock';
import type { LayoutBlockType } from './LayoutBlockType';

it("should be enum for `LayoutBlock['type']`", () => {
expect<Expect<EnumToMatchTaggedUnionTags<typeof LayoutBlockType, LayoutBlock, 'type'>>>(true).toBeTruthy();
});
7 changes: 0 additions & 7 deletions packages/ui-kit/src/blocks/LayoutBlockType.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { LayoutBlock } from './LayoutBlock';

export enum LayoutBlockType {
SECTION = 'section',
DIVIDER = 'divider',
Expand All @@ -13,8 +11,3 @@ export enum LayoutBlockType {
CALLOUT = 'callout',
TAB_NAVIGATION = 'tab_navigation',
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
type AssertEnumKeysFromBlockUnionTypes = {
[B in LayoutBlock as Uppercase<B['type']>]: (typeof LayoutBlockType)[Uppercase<B['type']>];
};
6 changes: 6 additions & 0 deletions packages/ui-kit/src/blocks/TextObjectType.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { TextObject } from './TextObject';
import type { TextObjectType } from './TextObjectType';

it("should be enum for `TextObject['type']`", () => {
expect<Expect<EnumToMatchTaggedUnionTags<typeof TextObjectType, TextObject, 'type'>>>(true).toBeTruthy();
});
7 changes: 0 additions & 7 deletions packages/ui-kit/src/blocks/TextObjectType.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { TextObject } from './TextObject';

export enum TextObjectType {
/** @deprecated */
PLAINTEXT = 'plain_text',
Expand All @@ -8,8 +6,3 @@ export enum TextObjectType {
MARKDOWN = 'mrkdwn',
MRKDWN = 'mrkdwn',
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
type AssertEnumKeysFromBlockUnionTypes = {
[B in TextObject as Uppercase<B['type']>]: (typeof TextObjectType)[Uppercase<B['type']>];
};
6 changes: 3 additions & 3 deletions packages/ui-kit/src/blocks/layout/PreviewBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ type Image = {
};
};

export type PreviewBlockBase = {
export type PreviewBlockBase = LayoutBlockish<{
type: `${LayoutBlockType.PREVIEW}`;
title: TextObject[];
description: TextObject[];
footer?: ContextBlock;
};
}>;

export type PreviewBlockWithThumb = PreviewBlockBase & {
thumb: Image;
Expand All @@ -29,7 +29,7 @@ export type PreviewBlockWithPreview = PreviewBlockBase & {
thumb: undefined;
};

export type PreviewBlock = LayoutBlockish<PreviewBlockBase | PreviewBlockWithThumb | PreviewBlockWithPreview>;
export type PreviewBlock = PreviewBlockBase | PreviewBlockWithThumb | PreviewBlockWithPreview;

export const isPreviewBlockWithThumb = (previewBlock: PreviewBlock): previewBlock is PreviewBlockWithThumb => 'thumb' in previewBlock;

Expand Down
14 changes: 14 additions & 0 deletions packages/ui-kit/src/jest-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
declare global {
type Expect<T extends true> = T;
type EnumToMatchTaggedUnionTags<
TEnum extends Record<Uppercase<TTaggedUnion[TTagField]>, any>,
TTaggedUnion extends Record<string, any>,
TTagField extends keyof TTaggedUnion,
> = TEnum extends {
[K in TTaggedUnion as Uppercase<K[TTagField]>]: TEnum[Uppercase<K[TTagField]>];
}
? true
: false;
}

export {};
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"rootDir": "./src",
"outDir": "./dist/cjs/",
"module": "CommonJS",
"plugins": [{ "transform": "typia/lib/transform" }]
}
},
"include": ["./src/**/*"],
"exclude": ["./src/**/*.spec.ts", "./src/jest-setup.ts"],
}
9 changes: 9 additions & 0 deletions packages/ui-kit/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist/esm"
},
"include": ["./src/**/*"],
"exclude": ["./src/**/*.spec.ts", "./src/jest-setup.ts"]
}
5 changes: 3 additions & 2 deletions packages/ui-kit/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"target": "ES5",
"module": "ES2020",
"lib": ["ES2020"],
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"outDir": "./dist/esm/",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
Expand All @@ -15,5 +15,6 @@
"resolveJsonModule": true,
"plugins": [{ "transform": "typia/lib/transform" }]
},
"exclude": ["dist/", "src/**/*.spec.ts"]
"include": ["./src/**/*.ts"],
"exclude": []
}
Loading