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 { UserCircle2 } from 'lucide-react';
|
||||
// import ReactTooltip from 'react-tooltip';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { FC, useState, useEffect } from 'react';
|
||||
import _compact from 'lodash/compact';
|
||||
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 { _misc, _object } from '@firecamp/utils';
|
||||
import {
|
||||
@@ -30,7 +30,7 @@ import {
|
||||
Digest,
|
||||
// Hawk,
|
||||
Netrc,
|
||||
Ntlm,
|
||||
// Ntlm,
|
||||
OAuth1,
|
||||
OAuth2,
|
||||
NoAuth,
|
||||
@@ -42,11 +42,11 @@ const AuthPanel: FC<IProps> = ({
|
||||
value,
|
||||
activeAuthType = EAuthTypes.None,
|
||||
allowInherit = true,
|
||||
onChangeAuthType = () => {},
|
||||
onChangeAuthValue = () => {},
|
||||
onChangeOAuth2Value = () => {},
|
||||
fetchTokenOnChangeOAuth2 = (authPayload: any) => {},
|
||||
fetchInheritedAuth = () => {},
|
||||
onChangeAuthType = () => { },
|
||||
onChangeAuthValue = () => { },
|
||||
onChangeOAuth2Value = () => { },
|
||||
fetchTokenOnChangeOAuth2 = (authPayload: any) => { },
|
||||
fetchInheritedAuth = () => { },
|
||||
oauth2LastToken = '',
|
||||
}) => {
|
||||
const _authTypeList = allowInherit
|
||||
@@ -174,7 +174,7 @@ const AuthTypesDD: FC<any> = ({ types, name, onSelect }) => {
|
||||
handler={() => (
|
||||
<Button
|
||||
text={name || ''}
|
||||
classNames={{root: "font-bold"}}
|
||||
classNames={{ root: "font-bold" }}
|
||||
rightIcon={
|
||||
<VscTriangleDown
|
||||
size={12}
|
||||
|
||||
@@ -84,16 +84,20 @@ const Atlassion = () => {
|
||||
});
|
||||
};
|
||||
|
||||
const _onKeyDown = ({ key }: { key: string }) => {
|
||||
if (key == 'Enter') {
|
||||
setState(initialState);
|
||||
}
|
||||
};
|
||||
// const _onKeyDown = ({ key }: { key: string }) => {
|
||||
// if (key == 'Enter') {
|
||||
// setState(initialState);
|
||||
// }
|
||||
// };
|
||||
|
||||
return (
|
||||
<form className="fc-form grid">
|
||||
{(inputList || []).map((input, i) => {
|
||||
const { id, labelFor, label, type, placeholder, value } = input;
|
||||
const { id,
|
||||
// labelFor,
|
||||
label, type,
|
||||
// placeholder,
|
||||
value } = input;
|
||||
return (
|
||||
<div
|
||||
className={
|
||||
|
||||
@@ -3,7 +3,7 @@ import cx from 'classnames';
|
||||
import { VscTriangleDown } from '@react-icons/all-files/vsc/VscTriangleDown';
|
||||
import {
|
||||
Button,
|
||||
CheckboxInGrid,
|
||||
// CheckboxInGrid,
|
||||
DropdownMenu,
|
||||
SingleLineEditor,
|
||||
} from '@firecamp/ui';
|
||||
|
||||
@@ -29,7 +29,7 @@ const OAuth2: FC<IOAuth2Comp> = ({
|
||||
return { ...p, [n.id]: false };
|
||||
}, {})
|
||||
);
|
||||
const [isDDOpen, toggleDD] = useState(false);
|
||||
// const [isDDOpen, toggleDD] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setDirtyInputs({}); //TODO: check this later
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { FC } from "react";
|
||||
import MD from 'markdown-it';
|
||||
const md = new MD();
|
||||
// import MD from 'markdown-it';
|
||||
// const md = new MD();
|
||||
|
||||
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 { IQuickSelection } from './interfaces/QuickSelection.interface';
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ const CloseIconPlacement = ({
|
||||
</div>
|
||||
);
|
||||
|
||||
const ReorderType = 'tab';
|
||||
// const ReorderType = 'tab';
|
||||
|
||||
const Tab: FC<ITab> = ({
|
||||
id = '',
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
"fix": "run-s fix:*",
|
||||
"fix:prettier": "prettier \"src/**/*.ts\" --write",
|
||||
"fix:lint": "eslint src --ext .ts --fix",
|
||||
"test": "npx jest --bail --silent --verbose",
|
||||
"test": "npx jest --verbose",
|
||||
"test:lint": "eslint src --ext .ts",
|
||||
"test:prettier": "prettier \"src/**/*.ts\" --list-different",
|
||||
"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,
|
||||
"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. */,
|
||||
"noUnusedLocals": true /* Report errors on unused locals. */,
|
||||
"noUnusedLocals": false /* Report errors on unused locals. */,
|
||||
"noUnusedParameters": false /* Report errors on unused parameters. */,
|
||||
"noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
|
||||
"noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */,
|
||||
|
||||
Reference in New Issue
Block a user