Skip to content

Commit

Permalink
test: improve covers
Browse files Browse the repository at this point in the history
  • Loading branch information
2fd committed Dec 21, 2020
1 parent e098cd0 commit 5de3ffe
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -74,8 +74,8 @@
"request": "^2.88.0",
"slug": "^4.0.2",
"striptags": "^3.1.1",
"ts-node": "^9.1.1",
"ts-jest": "^26.4.4",
"ts-node": "^9.1.1",
"word-wrap": "^1.2.1"
},
"graphdoc": {
Expand Down
59 changes: 59 additions & 0 deletions plugins/navigation.object.test.ts
@@ -0,0 +1,59 @@
import projectPackage from "../test/empty.package.json";
import NavigationObject from "./navigation.object";
import schema from "../test/empty.schema.json";

describe("pĺugins/navigation.directive#NavigationDirectives", () => {
test("plugin return empty", () => {
const plugin = new NavigationObject(
{
...schema.data.__schema,
types: [],
},
projectPackage,
{}
);

expect(plugin.getNavigations("Query")).toEqual([])
})

test("plugin return navigation", () => {
const plugin = new NavigationObject(schema.data.__schema, projectPackage, {});
expect(plugin.getNavigations("Query")).toEqual([
{
title: "Objects",
items: [
{
"href": "/directive.spec.html",
"isActive": false,
"text": "__Directive",
},
{
"href": "/enumvalue.spec.html",
"isActive": false,
"text": "__EnumValue",
},
{
"href": "/field.spec.html",
"isActive": false,
"text": "__Field",
},
{
"href": "/inputvalue.spec.html",
"isActive": false,
"text": "__InputValue",
},
{
"href": "/schema.spec.html",
"isActive": false,
"text": "__Schema",
},
{
"href": "/type.spec.html",
"isActive": false,
"text": "__Type",
},
]
}
]);
});
});
59 changes: 59 additions & 0 deletions plugins/navigation.scalar.test.ts
@@ -0,0 +1,59 @@
import projectPackage from "../test/empty.package.json";
import NavigationScalar from "./navigation.object";
import schema from "../test/empty.schema.json";

describe("pĺugins/navigation.directive#NavigationDirectives", () => {
test("plugin return empty", () => {
const plugin = new NavigationScalar(
{
...schema.data.__schema,
types: [],
},
projectPackage,
{}
);

expect(plugin.getNavigations("Query")).toEqual([])
})

test("plugin return navigation", () => {
const plugin = new NavigationScalar(schema.data.__schema, projectPackage, {});
expect(plugin.getNavigations("Query")).toEqual([
{
title: "Objects",
items: [
{
"href": "/directive.spec.html",
"isActive": false,
"text": "__Directive",
},
{
"href": "/enumvalue.spec.html",
"isActive": false,
"text": "__EnumValue",
},
{
"href": "/field.spec.html",
"isActive": false,
"text": "__Field",
},
{
"href": "/inputvalue.spec.html",
"isActive": false,
"text": "__InputValue",
},
{
"href": "/schema.spec.html",
"isActive": false,
"text": "__Schema",
},
{
"href": "/type.spec.html",
"isActive": false,
"text": "__Type",
},
]
}
]);
});
});
36 changes: 36 additions & 0 deletions plugins/navigation.schema.test.ts
@@ -0,0 +1,36 @@
import projectPackage from "../test/empty.package.json";
import NavigationSchema from "./navigation.schema";
import schema from "../test/empty.schema.json";

describe("pĺugins/navigation.directive#NavigationDirectives", () => {
test("plugin return empty", () => {
const plugin = new NavigationSchema(
{
...schema.data.__schema,
mutationType: null,
queryType: null,
subscriptionType: null
},
projectPackage,
{}
);

expect(plugin.getNavigations("Query")).toEqual([])
})

test("plugin return navigation", () => {
const plugin = new NavigationSchema(schema.data.__schema, projectPackage, {});
expect(plugin.getNavigations("Query")).toEqual([
{
title: "Schema",
items: [
{
"href": "/query.doc.html",
"isActive": true,
"text": "Query"
}
]
}
]);
});
});
9 changes: 9 additions & 0 deletions plugins/navigation.schema.ts
Expand Up @@ -4,6 +4,15 @@ import { NavigationItem, NavigationSection, Plugin } from "../lib/utility";
export default class NavigationSchema extends Plugin
implements PluginInterface {
getNavigations(buildFrom?: string): NavigationSectionInterface[] {

if (
!this.document.queryType &&
!this.document.mutationType &&
!this.document.subscriptionType
) {
return []
}

const section = new NavigationSection("Schema", []);

// Query
Expand Down
49 changes: 49 additions & 0 deletions plugins/navigation.union.test.ts
@@ -0,0 +1,49 @@
import projectPackage from "../test/empty.package.json";
import NavigationUnion from "./navigation.union";
import schema from "../test/github.json";

describe("pĺugins/navigation.directive#NavigationDirectives", () => {
test("plugin return empty", () => {
const plugin = new NavigationUnion(
{
...schema.data.__schema,
types: [],
},
projectPackage,
{}
);

expect(plugin.getNavigations("Query")).toEqual([])
})

test("plugin return navigation", () => {
const plugin = new NavigationUnion(schema.data.__schema, projectPackage, {});
expect(plugin.getNavigations("Query")).toEqual([
{
title: "Unions",
items: [
{
"href": "/issuetimelineitem.doc.html",
"isActive": false,
"text": "IssueTimelineItem",
},
{
"href": "/projectcarditem.doc.html",
"isActive": false,
"text": "ProjectCardItem",
},
{
"href": "/reviewdismissalallowanceactor.doc.html",
"isActive": false,
"text": "ReviewDismissalAllowanceActor",
},
{
"href": "/searchresultitem.doc.html",
"isActive": false,
"text": "SearchResultItem",
},
]
}
]);
});
});

0 comments on commit 5de3ffe

Please sign in to comment.