mirror of
https://github.com/LukeHagar/firecamp.git
synced 2025-12-10 04:19:54 +00:00
test: basic jest errors are resolved and store facade created
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect, FC } from 'react';
|
import { FC } from 'react';
|
||||||
import cx from 'classnames';
|
import cx from 'classnames';
|
||||||
import { UserCircle2 } from 'lucide-react';
|
import { UserCircle2 } from 'lucide-react';
|
||||||
// import ReactTooltip from 'react-tooltip';
|
// import ReactTooltip from 'react-tooltip';
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { FC, useState, useEffect } from 'react';
|
import { FC, useState, useEffect } from 'react';
|
||||||
import _compact from 'lodash/compact';
|
import _compact from 'lodash/compact';
|
||||||
import cx from 'classnames';
|
import cx from 'classnames';
|
||||||
import isEqual from 'react-fast-compare';
|
// import isEqual from 'react-fast-compare';
|
||||||
import { VscTriangleDown } from '@react-icons/all-files/vsc/VscTriangleDown';
|
import { VscTriangleDown } from '@react-icons/all-files/vsc/VscTriangleDown';
|
||||||
import { _misc, _object } from '@firecamp/utils';
|
import { _misc, _object } from '@firecamp/utils';
|
||||||
import {
|
import {
|
||||||
@@ -30,7 +30,7 @@ import {
|
|||||||
Digest,
|
Digest,
|
||||||
// Hawk,
|
// Hawk,
|
||||||
Netrc,
|
Netrc,
|
||||||
Ntlm,
|
// Ntlm,
|
||||||
OAuth1,
|
OAuth1,
|
||||||
OAuth2,
|
OAuth2,
|
||||||
NoAuth,
|
NoAuth,
|
||||||
@@ -42,11 +42,11 @@ const AuthPanel: FC<IProps> = ({
|
|||||||
value,
|
value,
|
||||||
activeAuthType = EAuthTypes.None,
|
activeAuthType = EAuthTypes.None,
|
||||||
allowInherit = true,
|
allowInherit = true,
|
||||||
onChangeAuthType = () => {},
|
onChangeAuthType = () => { },
|
||||||
onChangeAuthValue = () => {},
|
onChangeAuthValue = () => { },
|
||||||
onChangeOAuth2Value = () => {},
|
onChangeOAuth2Value = () => { },
|
||||||
fetchTokenOnChangeOAuth2 = (authPayload: any) => {},
|
fetchTokenOnChangeOAuth2 = (authPayload: any) => { },
|
||||||
fetchInheritedAuth = () => {},
|
fetchInheritedAuth = () => { },
|
||||||
oauth2LastToken = '',
|
oauth2LastToken = '',
|
||||||
}) => {
|
}) => {
|
||||||
const _authTypeList = allowInherit
|
const _authTypeList = allowInherit
|
||||||
@@ -174,7 +174,7 @@ const AuthTypesDD: FC<any> = ({ types, name, onSelect }) => {
|
|||||||
handler={() => (
|
handler={() => (
|
||||||
<Button
|
<Button
|
||||||
text={name || ''}
|
text={name || ''}
|
||||||
classNames={{root: "font-bold"}}
|
classNames={{ root: "font-bold" }}
|
||||||
rightIcon={
|
rightIcon={
|
||||||
<VscTriangleDown
|
<VscTriangleDown
|
||||||
size={12}
|
size={12}
|
||||||
|
|||||||
@@ -84,16 +84,20 @@ const Atlassion = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const _onKeyDown = ({ key }: { key: string }) => {
|
// const _onKeyDown = ({ key }: { key: string }) => {
|
||||||
if (key == 'Enter') {
|
// if (key == 'Enter') {
|
||||||
setState(initialState);
|
// setState(initialState);
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form className="fc-form grid">
|
<form className="fc-form grid">
|
||||||
{(inputList || []).map((input, i) => {
|
{(inputList || []).map((input, i) => {
|
||||||
const { id, labelFor, label, type, placeholder, value } = input;
|
const { id,
|
||||||
|
// labelFor,
|
||||||
|
label, type,
|
||||||
|
// placeholder,
|
||||||
|
value } = input;
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={
|
className={
|
||||||
@@ -117,7 +121,7 @@ const Atlassion = () => {
|
|||||||
height="21px"
|
height="21px"
|
||||||
language={EEditorLanguage.FcText}
|
language={EEditorLanguage.FcText}
|
||||||
onChange={(e) => _handleChange(e)}
|
onChange={(e) => _handleChange(e)}
|
||||||
// onKeyDown={_onKeyDown}
|
// onKeyDown={_onKeyDown}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import cx from 'classnames';
|
|||||||
import { VscTriangleDown } from '@react-icons/all-files/vsc/VscTriangleDown';
|
import { VscTriangleDown } from '@react-icons/all-files/vsc/VscTriangleDown';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
CheckboxInGrid,
|
// CheckboxInGrid,
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
SingleLineEditor,
|
SingleLineEditor,
|
||||||
} from '@firecamp/ui';
|
} from '@firecamp/ui';
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ const OAuth2: FC<IOAuth2Comp> = ({
|
|||||||
return { ...p, [n.id]: false };
|
return { ...p, [n.id]: false };
|
||||||
}, {})
|
}, {})
|
||||||
);
|
);
|
||||||
const [isDDOpen, toggleDD] = useState(false);
|
// const [isDDOpen, toggleDD] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setDirtyInputs({}); //TODO: check this later
|
setDirtyInputs({}); //TODO: check this later
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { FC } from "react";
|
import { FC } from "react";
|
||||||
import MD from 'markdown-it';
|
// import MD from 'markdown-it';
|
||||||
const md = new MD();
|
// const md = new MD();
|
||||||
|
|
||||||
import { Controlled as CodeMirror } from 'react-codemirror2';
|
import { Controlled as CodeMirror } from 'react-codemirror2';
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { FC, Key, ReactChild, ReactFragment, ReactPortal } from 'react';
|
import { FC, ReactChild, ReactFragment, ReactPortal } from 'react';
|
||||||
import classnames from 'classnames';
|
import classnames from 'classnames';
|
||||||
import { IQuickSelection } from './interfaces/QuickSelection.interface';
|
import { IQuickSelection } from './interfaces/QuickSelection.interface';
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ const CloseIconPlacement = ({
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
const ReorderType = 'tab';
|
// const ReorderType = 'tab';
|
||||||
|
|
||||||
const Tab: FC<ITab> = ({
|
const Tab: FC<ITab> = ({
|
||||||
id = '',
|
id = '',
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
"fix": "run-s fix:*",
|
"fix": "run-s fix:*",
|
||||||
"fix:prettier": "prettier \"src/**/*.ts\" --write",
|
"fix:prettier": "prettier \"src/**/*.ts\" --write",
|
||||||
"fix:lint": "eslint src --ext .ts --fix",
|
"fix:lint": "eslint src --ext .ts --fix",
|
||||||
"test": "npx jest --bail --silent --verbose",
|
"test": "npx jest --verbose",
|
||||||
"test:lint": "eslint src --ext .ts",
|
"test:lint": "eslint src --ext .ts",
|
||||||
"test:prettier": "prettier \"src/**/*.ts\" --list-different",
|
"test:prettier": "prettier \"src/**/*.ts\" --list-different",
|
||||||
"test:spelling": "cspell \"{README.md,.github/*.md,src/**/*.ts}\"",
|
"test:spelling": "cspell \"{README.md,.github/*.md,src/**/*.ts}\"",
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
import { render, screen } from "@testing-library/react"
|
||||||
|
import UrlBarContainer from "./UrlBarContainer"
|
||||||
|
// import useUrlBarFacade, { useUrlBarSuffixButtonsFacade } from "./useUrlBarFacade"
|
||||||
|
import useUrlBarFacade from "./useUrlBarFacade"
|
||||||
|
|
||||||
|
jest.mock("./useUrlBarFacade", () => {
|
||||||
|
const originalModule = jest.requireActual('./useUrlBarFacade');
|
||||||
|
return {
|
||||||
|
__esModule: true,
|
||||||
|
...originalModule,
|
||||||
|
default: jest.fn(),
|
||||||
|
// useUrlBarSuffixButtonsFacade: jest.fn(),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("UrlBarContainer render", () => {
|
||||||
|
|
||||||
|
const prepareStore = (a = {}, b = {}) => {
|
||||||
|
//@ts-ignore
|
||||||
|
useUrlBarFacade.mockImplementationOnce(() => (a));
|
||||||
|
//@ts-ignore
|
||||||
|
useUrlBarSuffixButtonsFacade.mockImplementationOnce(() => (b))
|
||||||
|
}
|
||||||
|
test("should have default ui: path, copy button, method dropdown, url value, send and save buttons", () => {
|
||||||
|
prepareStore({
|
||||||
|
url: { raw: "https://firecamp.io" },
|
||||||
|
method: "GET"
|
||||||
|
});
|
||||||
|
render(<UrlBarContainer />);
|
||||||
|
|
||||||
|
const urlInput = screen.getByTestId("single-line-editor");
|
||||||
|
expect(urlInput).toBeInTheDocument();
|
||||||
|
expect(urlInput).toHaveTextContent('https://firecamp.io');
|
||||||
|
|
||||||
|
const reqPath = screen.getByTestId("request-path");
|
||||||
|
expect(reqPath).toBeInTheDocument();
|
||||||
|
expect(reqPath).toHaveTextContent('Untitled Request');
|
||||||
|
|
||||||
|
const copyBtn = screen.getByTestId("copy-button")
|
||||||
|
expect(copyBtn).toBeInTheDocument();
|
||||||
|
|
||||||
|
const methodBtn = screen.getByTestId("http-method-label")
|
||||||
|
expect(methodBtn).toBeInTheDocument();
|
||||||
|
expect(methodBtn).toHaveAttribute('title', 'HTTP Method');
|
||||||
|
expect(methodBtn).toHaveTextContent('GET');
|
||||||
|
|
||||||
|
const sendBtn = screen.getByTestId("send-request")
|
||||||
|
expect(sendBtn).toBeInTheDocument();
|
||||||
|
expect(sendBtn).toHaveAttribute('title', 'Send Request');
|
||||||
|
expect(sendBtn).toHaveTextContent('Send');
|
||||||
|
|
||||||
|
const saveBtn = screen.getByTestId("save-request")
|
||||||
|
expect(saveBtn).toBeInTheDocument();
|
||||||
|
expect(saveBtn).toHaveAttribute('title', 'Save Request');
|
||||||
|
expect(saveBtn).toHaveTextContent('Save');
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should have POST method selected", () => {
|
||||||
|
prepareStore({
|
||||||
|
url: { raw: "https://firecamp.io" },
|
||||||
|
method: "POST"
|
||||||
|
});
|
||||||
|
render(<UrlBarContainer />);
|
||||||
|
const methodBtn = screen.getByTestId("http-method-label")
|
||||||
|
expect(methodBtn).toBeInTheDocument();
|
||||||
|
expect(methodBtn).toHaveAttribute('title', 'HTTP Method');
|
||||||
|
expect(methodBtn).toHaveTextContent('POST');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
test("should have request path shown", () => {
|
||||||
|
prepareStore({
|
||||||
|
url: { raw: "https://firecamp.io" },
|
||||||
|
requestPath: { path: "Firecamp Collection > Create Request" }
|
||||||
|
});
|
||||||
|
render(<UrlBarContainer />);
|
||||||
|
const reqPath = screen.getByTestId("request-path")
|
||||||
|
expect(reqPath).toBeInTheDocument();
|
||||||
|
expect(reqPath).toHaveTextContent('Firecamp Collection > Create Request');
|
||||||
|
});
|
||||||
|
})
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import { shallow } from 'zustand/shallow';
|
||||||
|
import { IStore, useStore } from '../../../store';
|
||||||
|
|
||||||
|
const useUrlBarFacade = () => {
|
||||||
|
return useStore(
|
||||||
|
(s: IStore) => ({
|
||||||
|
tabId: s.runtime.tabId,
|
||||||
|
url: s.request.url,
|
||||||
|
method: s.request.method,
|
||||||
|
__meta: s.request.__meta,
|
||||||
|
__ref: s.request.__ref,
|
||||||
|
requestPath: s.runtime.requestPath,
|
||||||
|
isRequestSaved: s.runtime.isRequestSaved,
|
||||||
|
context: s.context,
|
||||||
|
changeUrl: s.changeUrl,
|
||||||
|
changeMethod: s.changeMethod,
|
||||||
|
fetchIntrospectionSchema: s.fetchIntrospectionSchema,
|
||||||
|
}),
|
||||||
|
shallow
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useUrlBarFacade;
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
"inlineSourceMap": true,
|
"inlineSourceMap": true,
|
||||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
|
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
|
||||||
"resolveJsonModule": true /* Include modules imported with .json extension. */,
|
"resolveJsonModule": true /* Include modules imported with .json extension. */,
|
||||||
"noUnusedLocals": true /* Report errors on unused locals. */,
|
"noUnusedLocals": false /* Report errors on unused locals. */,
|
||||||
"noUnusedParameters": false /* Report errors on unused parameters. */,
|
"noUnusedParameters": false /* Report errors on unused parameters. */,
|
||||||
"noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
|
"noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
|
||||||
"noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */,
|
"noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */,
|
||||||
|
|||||||
Reference in New Issue
Block a user