Skip to content

Commit

Permalink
test: upgrade ui tests to story based
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Apr 2, 2021
1 parent 5f799be commit 6139d5e
Show file tree
Hide file tree
Showing 319 changed files with 70,581 additions and 60,608 deletions.
4 changes: 2 additions & 2 deletions plugins/addon-catalog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"fix": "yarn lint --fix",
"lint": "yarn eslint . --ext mdx,ts,tsx",
"prepare": "yarn build",
"test:create": "cc-cli -c ./.config -o tests -t stories.test.ts -f ts",
"test:create": "cc-cli -g story -c ./.config -w",
"test": "yarn jest"
},
"homepage": "https://github.com/ccontrols/component-controls",
Expand Down Expand Up @@ -61,7 +61,7 @@
"jest": {
"preset": "ts-jest",
"roots": [
"./tests"
"./src"
]
}
}
47 changes: 47 additions & 0 deletions plugins/addon-catalog/src/stories/Catalog.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import path from 'path';
import MatchMediaMock from 'jest-matchmedia-mock';
import { loadConfigurations } from '@component-controls/config';
import { renderExample } from '@component-controls/test-renderers';
import { render as reactRender } from '@component-controls/render/react';
import { render, act } from '@testing-library/react';

const renderErr = () => {
throw new Error('Could not render the story');
};

import doc, { overview } from './Catalog.stories';

describe('Catalog', () => {
let matchMedia: MatchMediaMock;
beforeAll(() => {
jest.mock('rc-util/lib/Portal');
matchMedia = new MatchMediaMock();
});
afterEach(() => {
matchMedia.clear();
});
const configPath = path.resolve(__dirname, '../../.config');
const config = loadConfigurations(configPath);
if (!config.renderFn) {
config.renderFn = reactRender;
}

test('overview', () => {
const example = overview;

let rendered;
act(() => {
rendered = renderExample({
example,
doc,
config,
});
});
if (!rendered) {
renderErr();
return;
}
const { asFragment } = render(rendered);
expect(asFragment()).toMatchSnapshot();
});
});
47 changes: 47 additions & 0 deletions plugins/addon-catalog/src/stories/ComponentCard.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import path from 'path';
import MatchMediaMock from 'jest-matchmedia-mock';
import { loadConfigurations } from '@component-controls/config';
import { renderExample } from '@component-controls/test-renderers';
import { render as reactRender } from '@component-controls/render/react';
import { render, act } from '@testing-library/react';

const renderErr = () => {
throw new Error('Could not render the story');
};

import doc, { overview } from './ComponentCard.stories';

describe('ComponentCard', () => {
let matchMedia: MatchMediaMock;
beforeAll(() => {
jest.mock('rc-util/lib/Portal');
matchMedia = new MatchMediaMock();
});
afterEach(() => {
matchMedia.clear();
});
const configPath = path.resolve(__dirname, '../../.config');
const config = loadConfigurations(configPath);
if (!config.renderFn) {
config.renderFn = reactRender;
}

test('overview', () => {
const example = overview;

let rendered;
act(() => {
rendered = renderExample({
example,
doc,
config,
});
});
if (!rendered) {
renderErr();
return;
}
const { asFragment } = render(rendered);
expect(asFragment()).toMatchSnapshot();
});
});
47 changes: 47 additions & 0 deletions plugins/addon-catalog/src/stories/ComponentFilter.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import path from 'path';
import MatchMediaMock from 'jest-matchmedia-mock';
import { loadConfigurations } from '@component-controls/config';
import { renderExample } from '@component-controls/test-renderers';
import { render as reactRender } from '@component-controls/render/react';
import { render, act } from '@testing-library/react';

const renderErr = () => {
throw new Error('Could not render the story');
};

import doc, { overview } from './ComponentFilter.stories';

describe('ComponentFilter', () => {
let matchMedia: MatchMediaMock;
beforeAll(() => {
jest.mock('rc-util/lib/Portal');
matchMedia = new MatchMediaMock();
});
afterEach(() => {
matchMedia.clear();
});
const configPath = path.resolve(__dirname, '../../.config');
const config = loadConfigurations(configPath);
if (!config.renderFn) {
config.renderFn = reactRender;
}

test('overview', () => {
const example = overview;

let rendered;
act(() => {
rendered = renderExample({
example,
doc,
config,
});
});
if (!rendered) {
renderErr();
return;
}
const { asFragment } = render(rendered);
expect(asFragment()).toMatchSnapshot();
});
});
47 changes: 47 additions & 0 deletions plugins/addon-catalog/src/stories/ComponentList.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import path from 'path';
import MatchMediaMock from 'jest-matchmedia-mock';
import { loadConfigurations } from '@component-controls/config';
import { renderExample } from '@component-controls/test-renderers';
import { render as reactRender } from '@component-controls/render/react';
import { render, act } from '@testing-library/react';

const renderErr = () => {
throw new Error('Could not render the story');
};

import doc, { overview } from './ComponentList.stories';

describe('ComponentList', () => {
let matchMedia: MatchMediaMock;
beforeAll(() => {
jest.mock('rc-util/lib/Portal');
matchMedia = new MatchMediaMock();
});
afterEach(() => {
matchMedia.clear();
});
const configPath = path.resolve(__dirname, '../../.config');
const config = loadConfigurations(configPath);
if (!config.renderFn) {
config.renderFn = reactRender;
}

test('overview', () => {
const example = overview;

let rendered;
act(() => {
rendered = renderExample({
example,
doc,
config,
});
});
if (!rendered) {
renderErr();
return;
}
const { asFragment } = render(rendered);
expect(asFragment()).toMatchSnapshot();
});
});
47 changes: 47 additions & 0 deletions plugins/addon-catalog/src/stories/ComponentsCatalog.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import path from 'path';
import MatchMediaMock from 'jest-matchmedia-mock';
import { loadConfigurations } from '@component-controls/config';
import { renderExample } from '@component-controls/test-renderers';
import { render as reactRender } from '@component-controls/render/react';
import { render, act } from '@testing-library/react';

const renderErr = () => {
throw new Error('Could not render the story');
};

import doc, { overview } from './ComponentsCatalog.stories';

describe('ComponentsCatalog', () => {
let matchMedia: MatchMediaMock;
beforeAll(() => {
jest.mock('rc-util/lib/Portal');
matchMedia = new MatchMediaMock();
});
afterEach(() => {
matchMedia.clear();
});
const configPath = path.resolve(__dirname, '../../.config');
const config = loadConfigurations(configPath);
if (!config.renderFn) {
config.renderFn = reactRender;
}

test('overview', () => {
const example = overview;

let rendered;
act(() => {
rendered = renderExample({
example,
doc,
config,
});
});
if (!rendered) {
renderErr();
return;
}
const { asFragment } = render(rendered);
expect(asFragment()).toMatchSnapshot();
});
});
Loading

0 comments on commit 6139d5e

Please sign in to comment.