* tidy up mocked data
This commit is contained in:
Judith de la Fuente 2021-05-24 14:25:22 +02:00
Родитель 367ba458a8
Коммит fb388d6e1a
5 изменённых файлов: 640 добавлений и 1176 удалений

Просмотреть файл

@ -70,13 +70,9 @@
], ],
"devDependencies": { "devDependencies": {
"@testing-library/jest-dom": "^5.5.0", "@testing-library/jest-dom": "^5.5.0",
"@types/enzyme": "^3.10.5",
"@types/enzyme-adapter-react-16": "^1.0.6",
"@types/redux-mock-store": "^1.0.2", "@types/redux-mock-store": "^1.0.2",
"@typescript-eslint/eslint-plugin": "^4.15.1", "@typescript-eslint/eslint-plugin": "^4.15.1",
"@typescript-eslint/parser": "^4.15.1", "@typescript-eslint/parser": "^4.15.1",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.2",
"eslint": "^7.20.0", "eslint": "^7.20.0",
"eslint-config-prettier": "^8.0.0", "eslint-config-prettier": "^8.0.0",
"eslint-plugin-prettier": "^3.3.1", "eslint-plugin-prettier": "^3.3.1",

Просмотреть файл

@ -1,14 +1,12 @@
import * as React from "react"; import * as React from "react";
import { Provider } from "react-redux";
import configureMockStore from "redux-mock-store"; import configureMockStore from "redux-mock-store";
import { getInitialState } from "../../../mockData/mockStore"; import { getInitialState } from "../../../mockData/mockStore";
import AppServiceSelection from "./AppServiceSelection"; import { renderWithStore } from "../../../testUtils";
import CosmosDBSelection from "./CosmosDBSelection"; import appServiceMessages from "./AppServiceSelection/messages";
import cosmosDBMessages from "./CosmosDBSelection/messages";
import ServicesList from "./index"; import ServicesList from "./index";
const mockStore = configureMockStore();
const emptyCosmosDB = null; const emptyCosmosDB = null;
const emptyAppService = null; const emptyAppService = null;
@ -20,22 +18,22 @@ const mockVsCode = {
describe("ServicesList", () => { describe("ServicesList", () => {
let props: any; let props: any;
let store: any;
let wrapper: any; let wrapper: any;
let initialState: any; let initialState: any;
const mockStore = configureMockStore();
describe("When has not selected AppService in store", () => { describe("When has not selected AppService in store", () => {
beforeEach(() => { beforeEach(() => {
initialState = getInitialState(); initialState = getInitialState();
store = mockStore(initialState);
initialState.userSelection.services = { initialState.userSelection.services = {
appService: emptyAppService, appService: emptyAppService,
}; };
initialState.vscode = mockVsCode; initialState.vscode = mockVsCode;
wrapper = mountWithIntl( wrapper = renderWithStore(<ServicesList {...props} />, store);
<Provider store={mockStore(initialState)}>
<ServicesList {...props} />
</Provider>
).children();
}); });
it("renders without crashing", () => { it("renders without crashing", () => {
@ -43,13 +41,13 @@ describe("ServicesList", () => {
}); });
it("Should not have a rendered AppServiceSelection component", () => { it("Should not have a rendered AppServiceSelection component", () => {
const appServiceComponent = wrapper.find(AppServiceSelection); expect(wrapper.queryByText(intl.formatMessage(appServiceMessages.title))).not.toBeInTheDocument();
expect(appServiceComponent).toHaveLength(0);
}); });
}); });
describe("When has selected AppService in store", () => { describe("When has selected AppService in store", () => {
beforeEach(() => { beforeEach(() => {
store = mockStore(initialState);
const appService = { ...emptyAppService, selection: {} }; const appService = { ...emptyAppService, selection: {} };
initialState = getInitialState(); initialState = getInitialState();
initialState.userSelection.services = { initialState.userSelection.services = {
@ -57,11 +55,7 @@ describe("ServicesList", () => {
}; };
initialState.vscode = mockVsCode; initialState.vscode = mockVsCode;
wrapper = mountWithIntl( wrapper = renderWithStore(<ServicesList {...props} />, store);
<Provider store={mockStore(initialState)}>
<ServicesList {...props} />
</Provider>
).children();
}); });
it("renders without crashing", () => { it("renders without crashing", () => {
@ -69,24 +63,21 @@ describe("ServicesList", () => {
}); });
it("Should have a rendered AppServiceSelection component", () => { it("Should have a rendered AppServiceSelection component", () => {
const appServiceComponent = wrapper.find(AppServiceSelection); const appServiceComponent = wrapper.getByText(intl.formatMessage(appServiceMessages.title));
expect(appServiceComponent).toHaveLength(1); expect(appServiceComponent).toBeDefined();
}); });
}); });
describe("When hasn not selected CosmosDB service in store", () => { describe("When has not selected CosmosDB service in store", () => {
beforeEach(() => { beforeEach(() => {
initialState = getInitialState(); initialState = getInitialState();
store = mockStore(initialState);
initialState.userSelection.services = { initialState.userSelection.services = {
cosmosDB: emptyCosmosDB, cosmosDB: emptyCosmosDB,
}; };
initialState.vscode = mockVsCode; initialState.vscode = mockVsCode;
wrapper = mountWithIntl( wrapper = renderWithStore(<ServicesList {...props} />, store);
<Provider store={mockStore(initialState)}>
<ServicesList {...props} />
</Provider>
).children();
}); });
it("renders without crashing", () => { it("renders without crashing", () => {
@ -94,8 +85,7 @@ describe("ServicesList", () => {
}); });
it("Should not have a rendered CosmosDBSelection component", () => { it("Should not have a rendered CosmosDBSelection component", () => {
const cosmosDBComponent = wrapper.find(CosmosDBSelection); expect(wrapper.queryByText(intl.formatMessage(cosmosDBMessages.title))).not.toBeInTheDocument();
expect(cosmosDBComponent).toHaveLength(0);
}); });
}); });
@ -104,14 +94,11 @@ describe("ServicesList", () => {
const cosmosDB = { ...emptyCosmosDB, selection: ["any"] }; const cosmosDB = { ...emptyCosmosDB, selection: ["any"] };
initialState = getInitialState(); initialState = getInitialState();
store = mockStore(initialState);
initialState.userSelection.services = { cosmosDB }; initialState.userSelection.services = { cosmosDB };
initialState.vscode = mockVsCode; initialState.vscode = mockVsCode;
wrapper = mountWithIntl( wrapper = renderWithStore(<ServicesList {...props} />, store);
<Provider store={mockStore(initialState)}>
<ServicesList {...props} />
</Provider>
).children();
}); });
it("renders without crashing", () => { it("renders without crashing", () => {
@ -119,8 +106,8 @@ describe("ServicesList", () => {
}); });
it("Should have a rendered CosmosDBSelection component", () => { it("Should have a rendered CosmosDBSelection component", () => {
const cosmosDBComponent = wrapper.find(CosmosDBSelection); const cosmosDBComponent = wrapper.getByText(intl.formatMessage(cosmosDBMessages.title));
expect(cosmosDBComponent).toHaveLength(1); expect(cosmosDBComponent).toBeDefined();
}); });
}); });
}); });

Просмотреть файл

@ -53,9 +53,9 @@ const projectTypes = [
{ {
name: "Tabbed", name: "Tabbed",
displayName: "Tabbed", displayName: "Tabbed",
summary: "Tabbed summary ***", summary: "Tabbed summary",
body: "Tabbed description***", body: "Tabbed description",
description: "Tabbed rich description***", description: "Tabbed rich description",
licenses: licenses:
"[React Native](https://github.com/facebook/react-native/blob/master/LICENSE)\n [React Navigation](https://github.com/react-navigation/react-navigation/blob/main/packages/core/LICENSE)", "[React Native](https://github.com/facebook/react-native/blob/master/LICENSE)\n [React Navigation](https://github.com/react-navigation/react-navigation/blob/main/packages/core/LICENSE)",
icon: projectTypeImage, icon: projectTypeImage,
@ -64,9 +64,9 @@ const projectTypes = [
{ {
name: "Drawer", name: "Drawer",
displayName: "Drawer", displayName: "Drawer",
summary: "Drawer summary ***", summary: "Drawer summary",
body: "Drawer description***", body: "Drawer description",
description: "Drawer rich description***", description: "Drawer rich description",
licenses: licenses:
"[React Native](https://github.com/facebook/react-native/blob/master/LICENSE)\n [React Navigation](https://github.com/react-navigation/react-navigation/blob/main/packages/core/LICENSE)", "[React Native](https://github.com/facebook/react-native/blob/master/LICENSE)\n [React Navigation](https://github.com/react-navigation/react-navigation/blob/main/packages/core/LICENSE)",
icon: noImage, icon: noImage,
@ -76,12 +76,12 @@ const projectTypes = [
const frameworks = [ const frameworks = [
{ {
name: "React Native MOCK", name: "React Native",
displayName: "React Native MOCK", displayName: "React Native",
icon: frontendImage, icon: frontendImage,
summary: "JavaScript framework by Facebook", summary: "JavaScript framework by Facebook",
description: description:
"MOCKED DESCRIPTION React is a component-based open source JavaScript library for building interfaces for single page applications. It is used for handling view layer for web and mobile apps. React allows you to design simple views for each state in your application, and React will efficiently update and render just the right components when your data changes. \r\n\r\n \r\nMore information about React can be found [here](https://reactjs.org).\r\n", "React is a component-based open source JavaScript library for building interfaces for single page applications. It is used for handling view layer for web and mobile apps. React allows you to design simple views for each state in your application, and React will efficiently update and render just the right components when your data changes. \r\n\r\n \r\nMore information about React can be found [here](https://reactjs.org).\r\n",
author: "Facebook", author: "Facebook",
order: 1, order: 1,
metadataType: "Framework", metadataType: "Framework",

Просмотреть файл

@ -1,46 +1,11 @@
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import "@testing-library/jest-dom"; import "@testing-library/jest-dom";
import { configure, mount, shallow } from "enzyme"; import { IntlProvider } from "react-intl";
import Adapter from "enzyme-adapter-react-16";
import React from "react";
import { IntlProvider, intlShape } from "react-intl";
/**
* This setup file configures the Enzyme Adapter and is executed before running the tests
* https://facebook.github.io/create-react-app/docs/running-tests#initializing-test-environment
*/
configure({ adapter: new Adapter() });
const intlProvider = new IntlProvider({ locale: "en" }, {}); const intlProvider = new IntlProvider({ locale: "en" }, {});
const { intl } = intlProvider.getChildContext(); const { intl } = intlProvider.getChildContext();
global.intl = intl; global.intl = intl;
//https://medium.com/@sapegin/testing-react-intl-components-with-jest-and-enzyme-f9d43d9c923e
// `intl` prop is required when using injectIntl HOC
const nodeWithIntlProp = (node) => React.cloneElement(node, { intl });
// shallow() with React Intl context
global.shallowWithIntl = (node, { context, ...options } = {}) => {
return shallow(nodeWithIntlProp(node), {
...options,
context: {
...context,
intl,
},
});
};
// mount() with React Intl context
global.mountWithIntl = (node, { context, childContextTypes, ...options } = {}) => {
return mount(nodeWithIntlProp(node), {
...options,
context: {
...context,
intl,
},
childContextTypes: {
intl: intlShape,
...childContextTypes,
},
});
};

Разница между файлами не показана из-за своего большого размера Загрузить разницу