Skip to content

Commit

Permalink
test: add tests for export feature
Browse files Browse the repository at this point in the history
  • Loading branch information
braposo committed Jun 4, 2019
1 parent 08200a8 commit b308862
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 8 deletions.
28 changes: 28 additions & 0 deletions src/types/__tests__/__snapshots__/file.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`File can get default file exports 1`] = `
Object {
"data": Object {
"file": Object {
"exports": Array [
Object {
"id": "0:1",
},
],
},
},
}
`;

exports[`File can get file comments 1`] = `
Object {
"data": Object {
Expand All @@ -26,3 +40,17 @@ Object {
},
}
`;

exports[`File can get specific file exports 1`] = `
Object {
"data": Object {
"file": Object {
"exports": Array [
Object {
"id": "1:6",
},
],
},
},
}
`;
9 changes: 9 additions & 0 deletions src/types/__tests__/__snapshots__/node.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Node returns css export 1`] = `"width: 201px; height: 109px;"`;

exports[`Node returns css export 2`] = `"width: 201px; height: 109px;"`;

exports[`Node returns css export 3`] = `"width: 201px; height: 109px;"`;

exports[`Node returns css export 4`] = `"width: 144px; height: 62px;"`;
96 changes: 96 additions & 0 deletions src/types/__tests__/export.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/* eslint-env jest */

import { graphql } from "graphql";
import schema from "../../schema";

const figmaFile = "cLp23bR627jcuNSoBGkhL04E";

jest.setTimeout(10000);

describe("Export", () => {
test("returns default export image", async () => {
const query = `
query {
exports(id: "${figmaFile}") {
id
output
}
}
`;

const response = await graphql(schema, query, null, { fileId: figmaFile });
expect(response.data).toBeDefined();

const fileExports = response.data && response.data.exports;
fileExports.forEach(fileExport => {
const { id, output } = fileExport;
expect(id).toEqual("0:1");
expect(output).not.toBeNull();
});
});

test("returns specific export image", async () => {
const nodeIds = ["1:6", "28:4"];
const query = `
query {
exports(id: "${figmaFile}", params: { ids: ${JSON.stringify(nodeIds)}}) {
id
output
}
}
`;

const response = await graphql(schema, query, null, { fileId: figmaFile });
expect(response.data).toBeDefined();

const fileExports: { id: string; output: string }[] =
response.data && response.data.exports;
fileExports.forEach((fileExport, index) => {
const { id, output } = fileExport;
expect(id).toEqual(nodeIds[index]);
expect(output).not.toBeNull();
});
});

test("returns svg format export", async () => {
const query = `
query {
exports(id: "${figmaFile}", params: { format:svg }) {
id
output
}
}
`;

const response = await graphql(schema, query, null, { fileId: figmaFile });
expect(response.data).toBeDefined();

const fileExports = response.data && response.data.exports;
fileExports.forEach(fileExport => {
const { id, output } = fileExport;
expect(id).toEqual("0:1");
expect(output).not.toBeNull();
});
});

test("returns jpg format export", async () => {
const query = `
query {
exports(id: "${figmaFile}", params: { format:jpg }) {
id
output
}
}
`;

const response = await graphql(schema, query, null, { fileId: figmaFile });
expect(response.data).toBeDefined();

const fileExports = response.data && response.data.exports;
fileExports.forEach(fileExport => {
const { id, output } = fileExport;
expect(id).toEqual("0:1");
expect(output).not.toBeNull();
});
});
});
12 changes: 4 additions & 8 deletions src/types/__tests__/file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("File", () => {
expect(version).not.toBeNull();
});

test("can get default file images", async () => {
test("can get default file exports", async () => {
const query = `
query {
file(id: "${figmaFile}") {
Expand All @@ -42,12 +42,10 @@ describe("File", () => {

const response = await graphql(schema, query, null, { fileId: figmaFile });

expect(response).toEqual({
data: { file: { exports: [{ id: "0:1" }] } },
});
expect(response).toMatchSnapshot();
});

test("can get specific file images", async () => {
test("can get specific file exports", async () => {
const query = `
query {
file(id: "${figmaFile}") {
Expand All @@ -60,9 +58,7 @@ describe("File", () => {

const response = await graphql(schema, query, null, { fileId: figmaFile });

expect(response).toEqual({
data: { file: { exports: [{ id: "1:6" }] } },
});
expect(response).toMatchSnapshot();
});

test("can get file comments", async () => {
Expand Down
73 changes: 73 additions & 0 deletions src/types/__tests__/node.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/* eslint-env jest */

import { graphql } from "graphql";
import schema from "../../schema";

const figmaFile = "cLp23bR627jcuNSoBGkhL04E";

jest.setTimeout(10000);

describe("Node", () => {
test("returns default export image", async () => {
const query = `
query {
file(id: "${figmaFile}") {
rectangles {
export
}
}
}
`;

const response = await graphql(schema, query, null, { fileId: figmaFile });
expect(response.data).not.toBeUndefined();

const rectangles = response.data && response.data.file.rectangles;
rectangles.forEach(rectangle => {
const { export: nodeExport } = rectangle;
expect(nodeExport).not.toBeNull();
});
});

test("returns jpg export", async () => {
const query = `
query {
file(id: "${figmaFile}") {
rectangles {
export(params: { format: jpg })
}
}
}
`;

const response = await graphql(schema, query, null, { fileId: figmaFile });
expect(response.data).not.toBeUndefined();

const rectangles = response.data && response.data.file.rectangles;
rectangles.forEach(rectangle => {
const { export: nodeExport } = rectangle;
expect(nodeExport).not.toBeNull();
});
});

test("returns css export", async () => {
const query = `
query {
file(id: "${figmaFile}") {
rectangles {
export(params: { format: css })
}
}
}
`;

const response = await graphql(schema, query, null, { fileId: figmaFile });
expect(response.data).not.toBeUndefined();

const rectangles = response.data && response.data.file.rectangles;
rectangles.forEach(rectangle => {
const { export: nodeExport } = rectangle;
expect(nodeExport).toMatchSnapshot();
});
});
});

0 comments on commit b308862

Please sign in to comment.