Skip to content

Commit

Permalink
fix(ga): issue #606 - update unit test and code
Browse files Browse the repository at this point in the history
  • Loading branch information
eouin committed Sep 3, 2024
1 parent b83cc1a commit e1b3f22
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 29 deletions.
2 changes: 1 addition & 1 deletion packages/webapp/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = {
'.+\\.(css|sass|scss)$': 'jest-css-modules-transform'
},
moduleNameMapper: {
'.+\\.(svg)$': '<rootDir>/test/__mocks__/svgMock.ts',
'.+\\.(svg)$': '<rootDir>/test/__mocks__/svg.mock.ts',
uuid: require.resolve('uuid')
},
transformIgnorePatterns: ['<rootDir>/node_modules/'],
Expand Down
2 changes: 1 addition & 1 deletion packages/webapp/test/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { initI18n } from '../src/webview/i18n';
import { Provider } from 'react-redux';
import configureMockStore from 'redux-mock-store';
import { getInitialState, reducer } from '../src/webview/state/reducers';
import { treeMock } from './__mocks__/treeMock';
import { treeMock } from './__mocks__/tree.mock';

jest.mock('../src/webview/state', () => {
return {
Expand Down
24 changes: 13 additions & 11 deletions packages/webapp/test/FeedbackSection/FeedbackSection.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@ import configureMockStore from 'redux-mock-store';
import { getInitialState, reducer } from '../../src/webview/state/reducers';
import { AppState } from '../../src/webview/types';
import { useSelector } from 'react-redux';
import { treeMock } from '../__mocks__/treeMock';
import { treeMock } from '../__mocks__/tree.mock';

const initialState = {
...getInitialState(),
activeGuidedAnswer: treeMock,
activeGuidedAnswerNode: [{
BODY: '<p>SAP Fiori Tools is a set of extensions for SAP Business Application Studio and Visual Studio Code</p>',
EDGES: [
{ LABEL: 'Deployment', TARGET_NODE: 45996, ORD: 1 },
{ LABEL: 'Fiori Generator', TARGET_NODE: 48363, ORD: 2 }
],
NODE_ID: 45995,
QUESTION: 'I have a problem with',
TITLE: 'SAP Fiori Tools'
}]
activeGuidedAnswerNode: [
{
BODY: '<p>SAP Fiori Tools is a set of extensions for SAP Business Application Studio and Visual Studio Code</p>',
EDGES: [
{ LABEL: 'Deployment', TARGET_NODE: 45996, ORD: 1 },
{ LABEL: 'Fiori Generator', TARGET_NODE: 48363, ORD: 2 }
],
NODE_ID: 45995,
QUESTION: 'I have a problem with',
TITLE: 'SAP Fiori Tools'
}
]
};

jest.mock('../../src/webview/state', () => {
Expand Down
4 changes: 3 additions & 1 deletion packages/webapp/test/GuidedAnswerNode/Middle.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { treeMock } from '../__mocks__/treeMock';
import React, { ReactElement } from 'react';
import { useSelector } from 'react-redux';
import { render, fireEvent, cleanup } from '@testing-library/react';
import { screen } from '@testing-library/dom';

import { Middle } from '../../src/webview/ui/components/GuidedAnswerNode/Middle';
import { actions } from '../../src/webview/state';
import { initI18n } from '../../src/webview/i18n';

import { treeMock } from '../__mocks__/tree.mock';

let activeNodeMock = {
BODY: '<p>SAP Fiori Tools is a set of extensions for SAP Business Application Studio and Visual Studio Code</p>',
EDGES: [
Expand Down
3 changes: 2 additions & 1 deletion packages/webapp/test/Header/Filters.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { treeMock } from '../__mocks__/treeMock';
import React from 'react';
import { render, fireEvent, cleanup } from '@testing-library/react';
import { initI18n } from '../../src/webview/i18n';
Expand All @@ -13,6 +12,8 @@ import {
sortComponentFilters
} from '../../src/webview/ui/components/Header/Filters/Filters';

import { treeMock } from '../__mocks__/tree.mock';

const createState = (initialState: AppState) => (actions: any[]) => actions.reduce(reducer, initialState);
const mockStore = configureMockStore();

Expand Down
10 changes: 6 additions & 4 deletions packages/webapp/test/Header/FiltersRibbon.test.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import React from 'react';
import { Provider } from 'react-redux';
import configureMockStore from 'redux-mock-store';
import { screen } from '@testing-library/dom';
import { render, fireEvent, cleanup } from '@testing-library/react';

import { initI18n } from '../../src/webview/i18n';
import { FiltersRibbon } from '../../src/webview/ui/components/Header/Filters/FiltersRibbon';
import { actions } from '../../src/webview/state';
import { Provider } from 'react-redux';
import { getInitialState, reducer } from '../../src/webview/state/reducers';
import { AppState } from '../../src/webview/types';
import configureMockStore from 'redux-mock-store';
import { screen } from '@testing-library/dom';
import { treeMock } from '../__mocks__/treeMock';

import { treeMock } from '../__mocks__/tree.mock';

jest.mock('../../src/webview/state', () => {
return {
Expand Down
8 changes: 5 additions & 3 deletions packages/webapp/test/Header/Header.test.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { treeMock } from '../__mocks__/treeMock';
import React from 'react';
import { Header } from '../../src/webview/ui/components/Header';
import { render, cleanup } from '@testing-library/react';
import { initI18n } from '../../src/webview/i18n';
import { Provider } from 'react-redux';
import configureMockStore from 'redux-mock-store';

import { initI18n } from '../../src/webview/i18n';
import { Header } from '../../src/webview/ui/components/Header';
import { getInitialState, reducer } from '../../src/webview/state/reducers';
import type { AppState } from '../../src/webview/types';

import { treeMock } from '../__mocks__/tree.mock';

const createState = (initialState: AppState) => (actions: any[]) => actions.reduce(reducer, initialState);
const mockStore = configureMockStore();

Expand Down
10 changes: 6 additions & 4 deletions packages/webapp/test/Header/NavigationButtons.test.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { treeMock } from '../__mocks__/treeMock';
import React from 'react';
import { actions } from '../../src/webview/state';
import { Provider } from 'react-redux';
import configureMockStore from 'redux-mock-store';
import { render, fireEvent, cleanup } from '@testing-library/react';
import { screen } from '@testing-library/dom';

import {
HomeButton,
BackButton,
RestartButton,
ShareButton,
BookmarkButton
} from '../../src/webview/ui/components/Header/NavigationButtons';
import { actions } from '../../src/webview/state';
import { initI18n } from '../../src/webview/i18n';
import configureMockStore from 'redux-mock-store';
import { getInitialState, reducer } from '../../src/webview/state/reducers';
import { AppState } from '../../src/webview/types';
import { Provider } from 'react-redux';

import { treeMock } from '../__mocks__/tree.mock';

jest.mock('../../src/webview/state', () => {
return {
Expand Down
2 changes: 1 addition & 1 deletion packages/webapp/test/Header/SearchField.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { SearchField } from '../../src/webview/ui/components/Header/SearchField'

import * as treeUtils from '../../src/webview/features/Trees/Trees.utils';

import { render, appState } from '../__mocks__/storeMock';
import { render, appState } from '../__mocks__/store.mock';

describe('<SearchField />', () => {
initIcons();
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { I18nextProvider } from 'react-i18next';
import type { AppState } from '../../src/webview/types';
import { reducer } from '../../src/webview/state/reducers';

import i18nMock from './i18nMock';
import i18nMock from './i18n.mock';

interface WrapperProps {
children?: React.ReactNode;
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ sonar.inclusions=**/*.ts, **/*.tsx, **/*.scss
sonar.exclusions=**/*.test.ts, **/*.test.tsx
sonar.cpd.exclusions=**/i18n.ts
sonar.tests=.
sonar.test.inclusions=**/*.test.ts, **/*.test.tsx
sonar.test.inclusions=**/*.test.ts, **/*.test.tsx, **/*.mock.ts, **/*.mock.tsx
sonar.javascript.lcov.reportPaths=packages/core/coverage/lcov.info, \
packages/ide-extension/coverage/lcov.info, \
packages/types/coverage/lcov.info, \
Expand Down

0 comments on commit e1b3f22

Please sign in to comment.