Skip to content

Commit

Permalink
upgraded jest, typescript and fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
darausi committed Sep 7, 2023
1 parent e66f7fc commit c7a02d0
Show file tree
Hide file tree
Showing 8 changed files with 976 additions and 2,238 deletions.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"carbon-components-react": "^8.28.0",
"codemirror": "^5.65.13",
"color": "3.2.1",
"jest-environment-jsdom": "^29.6.4",
"lodash": "^4.17.21",
"micromark": "^3.0.10",
"re-resizable": "6.9.9",
Expand All @@ -87,6 +88,7 @@
"remark-gfm": "^3.0.0",
"remark-parse": "^10.0.0",
"reset-css": "^5.0.1",
"typescript": "^5.2.2",
"unified": "^10.1.1",
"wicg-inert": "^3.1.2"
},
Expand All @@ -107,25 +109,24 @@
"@storybook/preset-scss": "^1.0.3",
"@storybook/react": "^7.0.9",
"@storybook/react-webpack5": "^7.0.9",
"@testing-library/jest-dom": "^5.16.1",
"@testing-library/jest-dom": "^6.1.3",
"@testing-library/react": "^12.1.2",
"@types/carbon-components-react": "^7.55.2",
"@types/codemirror": "^5.60.5",
"@types/color": "^3.0.2",
"@types/jest": "^24.9.1",
"@types/jest": "^29.5.4",
"@types/lodash": "^4.14.194",
"@typescript-eslint/eslint-plugin": "^5.59.11",
"@typescript-eslint/parser": "^5.59.11",
"babel-jest": "^27.5.1",
"babel-jest": "^29.6.4",
"chromatic": "^6.17.4",
"eslint": "^8.42.0",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-simple-import-sort": "^10.0.0",
"husky": "4",
"identity-obj-proxy": "^3.0.0",
"jest": "^26.6.3",
"jest-environment-jsdom-fourteen": "1.0.1",
"jest-pnp-resolver": "^1.2.1",
"jest": "^29.6.4",
"jest-pnp-resolver": "^1.2.3",
"lint-staged": "^13.2.2",
"node-sass-package-importer": "^5.3.2",
"prettier": "^2.8.8",
Expand All @@ -141,7 +142,6 @@
"stylelint-config-standard-scss": "^9.0.0",
"ts-node": "^10.9.1",
"tsc-esm-fix": "^2.20.13",
"typescript": "4.4.4",
"url-loader": "^4.1.1",
"yargs": "^17.7.2"
},
Expand Down Expand Up @@ -194,7 +194,7 @@
"testMatch": [
"<rootDir>/src/**/*(*.)@(spec|test).{js,jsx,ts,tsx}"
],
"testEnvironment": "jest-environment-jsdom-fourteen",
"testEnvironment": "jest-environment-jsdom",
"transform": {
"^.+\\.(js|jsx|ts|tsx)$": "babel-jest"
},
Expand Down
2 changes: 1 addition & 1 deletion scripts/compile-sass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import tildeImporter from "node-sass-package-importer";
import yargs from "yargs";
import sassRenderSyncConfig from "./sassConfig";

const args = yargs(process.argv.slice(2)).argv;
const args = yargs(process.argv.slice(2)).argv as any;

const styles = sass.renderSync({
importer: tildeImporter(),
Expand Down
55 changes: 34 additions & 21 deletions src/components/AutoSuggestion/tests/AutoSuggestion.test.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,50 @@
import React from "react";
import "@testing-library/jest-dom";
import {render} from "@testing-library/react";
import AutoSuggestion, {AutoSuggestionProps} from "../AutoSuggestion"
import { render } from "@testing-library/react";
import AutoSuggestion, { AutoSuggestionProps } from "../AutoSuggestion";

describe("AutoSuggestion", () => {
let props: AutoSuggestionProps
let props: AutoSuggestionProps;

beforeAll(() => {
document.createRange = () => {
const range = new Range();
range.getBoundingClientRect = jest.fn();
range.getClientRects = () => {
return {
item: () => null,
length: 0,
[Symbol.iterator]: jest.fn(),
};
};
return range;
};
});

beforeEach(() => {
props = {
label: "test value path",
initialValue: "",
onChange: jest.fn((value) => {
}),
onChange: jest.fn((value) => {}),
fetchSuggestions: jest.fn((inputString, cursorPosition) => undefined),
checkInput: jest.fn(inputString => ({
valid: true
checkInput: jest.fn((inputString) => ({
valid: true,
})),
onInputChecked: jest.fn(validInput => {
}),
onInputChecked: jest.fn((validInput) => {}),
validationErrorText: "",
clearIconText: "",
onFocusChange: jest.fn(hasFocus => {
}),
id: "test-auto-suggestion"
}
})
onFocusChange: jest.fn((hasFocus) => {}),
id: "test-auto-suggestion",
};
});

it("should render properly", () => {
const {container} = render(<AutoSuggestion {...props} />)
expect(container).not.toBeEmptyDOMElement()
})
const { container } = render(<AutoSuggestion {...props} />);
expect(container).not.toBeEmptyDOMElement();
});

it("should set label prop properly", () => {
const {getByText} = render(<AutoSuggestion {...props}/>)
expect(getByText(props.label!!)).toBeTruthy()
})
})
const { getByText } = render(<AutoSuggestion {...props} />);
expect(getByText(props.label!!)).toBeTruthy();
});
});
29 changes: 20 additions & 9 deletions src/components/AutoSuggestion/tests/SingleLineCodeEditor.test.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
import React from "react";
import "@testing-library/jest-dom";
import { render } from "@testing-library/react";
import {
SingleLineCodeEditor,
SingleLineCodeEditorProps,
} from "../../../../index";
import { SingleLineCodeEditor, SingleLineCodeEditorProps } from "../../../../index";
import CodeMirror from "codemirror";
import { CLASSPREFIX as eccgui } from "../../../configuration/constants";

describe("SingleLineCodeEditor", () => {
let props: SingleLineCodeEditorProps,
codeMirrorEditorInstance: CodeMirror.Editor = null as any;

beforeAll(() => {
document.createRange = () => {
const range = new Range();
range.getBoundingClientRect = jest.fn();
range.getClientRects = () => {
return {
item: () => null,
length: 0,
[Symbol.iterator]: jest.fn(),
};
};
return range;
};
});

beforeEach(() => {
props = {
setEditorInstance: jest.fn((editor) => {
codeMirrorEditorInstance = editor;
}),
onChange: jest.fn((value) => {}),
onCursorChange: jest.fn((pos, coords) => {}),
mode: null,
mode: undefined,
initialValue: "",
onFocusChange: jest.fn((focused) => {}),
onKeyDown: jest.fn((event) => {}),
Expand Down Expand Up @@ -49,14 +62,12 @@ describe("SingleLineCodeEditor", () => {

it("should not allow user to create new lines", () => {
render(<SingleLineCodeEditor {...props} />);
codeMirrorEditorInstance
.getDoc()
.setValue("I'm entering a new line \n character");
codeMirrorEditorInstance.getDoc().setValue("I'm entering a new line \n character");
expect(codeMirrorEditorInstance.lineCount()).toBe(1);
});

it("should convert multiple lines to a single line", () => {
render(<SingleLineCodeEditor {...{...props, initialValue: "1\n2\n3"}} />);
render(<SingleLineCodeEditor {...{ ...props, initialValue: "1\n2\n3" }} />);
expect(codeMirrorEditorInstance.lineCount()).toBe(1);
});
});
2 changes: 1 addition & 1 deletion src/components/Icon/IconButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const IconButton = ({
}: IconButtonProps) => {
const defaultIconTooltipProps = {
hoverOpenDelay: 1000,
openOnTargetFocus: restProps.disabled || (restProps.tabIndex ?? "0") < 0 ? false : undefined,
openOnTargetFocus: restProps.disabled || (restProps.tabIndex ?? 0) < 0 ? false : undefined,
};
const iconProps = {
small: restProps.small,
Expand Down
24 changes: 8 additions & 16 deletions src/components/OverviewItem/OverviewItemDepiction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface OverviewItemDepictionProps extends React.HTMLAttributes<HTMLDiv

export const OverviewItemDepiction = ({
children,
className = '',
className = "",
keepColors = false,
...restProps
}: OverviewItemDepictionProps) => {
Expand All @@ -20,19 +20,11 @@ export const OverviewItemDepiction = ({
border: false,
backgroundColor: keepColors ? undefined : "dark",
ratio: "1:1" as "1:1",
padding: "medium" as "medium"
}
padding: "medium" as "medium",
};
// only return Depiction element if it is wrapped inside OverviewItemDepiction
if (
typeof children === "object" &&
!!children &&
"type" in children &&
children.type === Depiction
) {
return React.cloneElement(
children,
defaultDepictionDisplay
);
if (typeof children === "object" && !!children && "type" in children && children.type === Depiction) {
return React.cloneElement(children, defaultDepictionDisplay);
}
// use Depiction element for basic icons
if (
Expand All @@ -41,7 +33,7 @@ export const OverviewItemDepiction = ({
"type" in children &&
(children.type === Icon || children.type === TestIcon)
) {
return <Depiction image={children} {...defaultDepictionDisplay} />
return <Depiction image={children as JSX.Element} {...defaultDepictionDisplay} />;
}
return (
<div
Expand All @@ -54,7 +46,7 @@ export const OverviewItemDepiction = ({
>
{children}
</div>
)
}
);
};

export default OverviewItemDepiction;
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@
"sourceMap": true
},
"include": ["./src/index.ts", "./declarations.d.ts"],
"exclude": ["node_modules", "dist", ".storybook", "blueprint", "coverage"]
"exclude": ["node_modules/**", "dist", ".storybook", "blueprint", "coverage"]
}
Loading

0 comments on commit c7a02d0

Please sign in to comment.