implement the beginnings of mockApis
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
@@ -15,15 +15,17 @@
|
||||
*/
|
||||
|
||||
import { readFilterConfig, createFilterByQueryParamFromConfig } from './config';
|
||||
import { MockConfigApi } from '@backstage/test-utils';
|
||||
import { mockApis } from '@backstage/test-utils';
|
||||
|
||||
describe('config', () => {
|
||||
describe('readFilterConfig', () => {
|
||||
it('returns filter data', async () => {
|
||||
const mockConfig = new MockConfigApi({
|
||||
field: 'pathname',
|
||||
operator: '==',
|
||||
value: '/home',
|
||||
const mockConfig = mockApis.config({
|
||||
data: {
|
||||
field: 'pathname',
|
||||
operator: '==',
|
||||
value: '/home',
|
||||
},
|
||||
});
|
||||
const res = readFilterConfig(mockConfig);
|
||||
expect(res).toEqual({
|
||||
@@ -34,10 +36,12 @@ describe('config', () => {
|
||||
});
|
||||
|
||||
it('returns undefined for invalid filter', async () => {
|
||||
const mockInvalidConfig = new MockConfigApi({
|
||||
myField: 'pathname',
|
||||
operator: '==',
|
||||
value: '3',
|
||||
const mockInvalidConfig = mockApis.config({
|
||||
data: {
|
||||
myField: 'pathname',
|
||||
operator: '==',
|
||||
value: '3',
|
||||
},
|
||||
});
|
||||
const res = readFilterConfig(mockInvalidConfig);
|
||||
expect(res).toEqual(undefined);
|
||||
@@ -46,15 +50,19 @@ describe('config', () => {
|
||||
|
||||
describe('createFilterByQueryParamFromConfig', () => {
|
||||
it('returns filter data', async () => {
|
||||
const mockConfig1 = new MockConfigApi({
|
||||
field: 'id',
|
||||
operator: '==',
|
||||
value: '3',
|
||||
const mockConfig1 = mockApis.config({
|
||||
data: {
|
||||
field: 'id',
|
||||
operator: '==',
|
||||
value: '3',
|
||||
},
|
||||
});
|
||||
const mockConfig2 = new MockConfigApi({
|
||||
field: 'pathname',
|
||||
operator: '==',
|
||||
value: 'path',
|
||||
const mockConfig2 = mockApis.config({
|
||||
data: {
|
||||
field: 'pathname',
|
||||
operator: '==',
|
||||
value: 'path',
|
||||
},
|
||||
});
|
||||
const res = createFilterByQueryParamFromConfig([
|
||||
mockConfig1,
|
||||
@@ -67,15 +75,19 @@ describe('config', () => {
|
||||
});
|
||||
|
||||
it('returns only valid filters', async () => {
|
||||
const mockValidConfig = new MockConfigApi({
|
||||
field: 'id',
|
||||
operator: '==',
|
||||
value: 3,
|
||||
const mockValidConfig = mockApis.config({
|
||||
data: {
|
||||
field: 'id',
|
||||
operator: '==',
|
||||
value: 3,
|
||||
},
|
||||
});
|
||||
const mockInvalidConfig = new MockConfigApi({
|
||||
myField: 'pathname',
|
||||
operator: '==',
|
||||
value: 'path',
|
||||
const mockInvalidConfig = mockApis.config({
|
||||
data: {
|
||||
myField: 'pathname',
|
||||
operator: '==',
|
||||
value: 'path',
|
||||
},
|
||||
});
|
||||
const res = createFilterByQueryParamFromConfig([
|
||||
mockValidConfig,
|
||||
|
||||
@@ -19,7 +19,7 @@ import { Content } from './Content';
|
||||
import {
|
||||
TestApiProvider,
|
||||
renderInTestApp,
|
||||
MockConfigApi,
|
||||
mockApis,
|
||||
} from '@backstage/test-utils';
|
||||
import { visitsApiRef } from '../../api';
|
||||
import { ContextProvider } from './Context';
|
||||
@@ -138,16 +138,18 @@ describe('<Content kind="recent"/>', () => {
|
||||
});
|
||||
|
||||
it('allows recent items to be filtered using config', async () => {
|
||||
const configApiMock = new MockConfigApi({
|
||||
home: {
|
||||
recentVisits: {
|
||||
filterBy: [
|
||||
{
|
||||
field: 'pathname',
|
||||
operator: '==',
|
||||
value: '/tech-radar',
|
||||
},
|
||||
],
|
||||
const configApiMock = mockApis.config({
|
||||
data: {
|
||||
home: {
|
||||
recentVisits: {
|
||||
filterBy: [
|
||||
{
|
||||
field: 'pathname',
|
||||
operator: '==',
|
||||
value: '/tech-radar',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -206,20 +208,22 @@ describe('<Content kind="recent"/>', () => {
|
||||
});
|
||||
|
||||
it('allows recent items to have no filter if the filter config is not valid', async () => {
|
||||
const configApiMock = new MockConfigApi({
|
||||
home: {
|
||||
recentVisits: {
|
||||
filterBy: [
|
||||
{
|
||||
operator: '==',
|
||||
value: '/tech-radar',
|
||||
},
|
||||
{
|
||||
field: 'pathname',
|
||||
operator: '==',
|
||||
value: '/explore',
|
||||
},
|
||||
],
|
||||
const configApiMock = mockApis.config({
|
||||
data: {
|
||||
home: {
|
||||
recentVisits: {
|
||||
filterBy: [
|
||||
{
|
||||
operator: '==',
|
||||
value: '/tech-radar',
|
||||
},
|
||||
{
|
||||
field: 'pathname',
|
||||
operator: '==',
|
||||
value: '/explore',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -283,16 +287,18 @@ describe('<Content kind="top"/>', () => {
|
||||
});
|
||||
|
||||
it('allows top items to be filtered using config', async () => {
|
||||
const configApiMock = new MockConfigApi({
|
||||
home: {
|
||||
topVisits: {
|
||||
filterBy: [
|
||||
{
|
||||
field: 'pathname',
|
||||
operator: '==',
|
||||
value: '/explore',
|
||||
},
|
||||
],
|
||||
const configApiMock = mockApis.config({
|
||||
data: {
|
||||
home: {
|
||||
topVisits: {
|
||||
filterBy: [
|
||||
{
|
||||
field: 'pathname',
|
||||
operator: '==',
|
||||
value: '/explore',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user