Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
fix: add new APIs and close dependabot conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
schabibi1 committed May 24, 2022
1 parent 138c9a3 commit 9865358
Show file tree
Hide file tree
Showing 56 changed files with 61,165 additions and 11,816 deletions.
399 changes: 320 additions & 79 deletions README.md

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions lib/__tests__/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"env": {
"jest": true
}
}
49 changes: 49 additions & 0 deletions lib/__tests__/get-story-params.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const getStoryParams = require('../src/getStoryParams')

describe('getStoryParams() function', () => {
test('without any argument should be return a empty object', () => {
expect(getStoryParams()).toEqual({})
})

test('with a language and story as resolveLinks option', () => {
const options = {
resolveLinks: 'story'
}
expect(getStoryParams('en', options)).toEqual({
language: 'en',
resolve_links: 'story'
})
})

test('with a language and url as resolveLinks option', () => {
const options = {
resolveLinks: 'url'
}
expect(getStoryParams('en', options)).toEqual({
language: 'en',
resolve_links: 'url'
})
})

test('with a language and version option', () => {
const options = {
version: 'draft'
}
expect(getStoryParams('en', options)).toEqual({
language: 'en',
version: 'draft'
})
})

test('with a language and version and resolve_relations options', () => {
const options = {
version: 'draft',
resolveRelations: ['page.author', 'page.categories']
}
expect(getStoryParams('en', options)).toEqual({
language: 'en',
version: 'draft',
resolve_relations: 'page.author,page.categories'
})
})
})
15 changes: 15 additions & 0 deletions lib/__tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// import { mount } from "@vue/test-utils";
// import Component from "../index";

describe("gatsby-source-storyblok", () => {
beforeEach(() => { });

test("empty test", () => {
// const wrapper = mount(Component, {
// propsData: {
// src: "http://lorempixel.com/400/200/",
// },
// });
// expect(wrapper.element).toMatchSnapshot();
});
});
19 changes: 19 additions & 0 deletions lib/__tests__/sync.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const StoryblokClient = require('storyblok-js-client')
const Sync = require('../src/sync')

test('horizontal_rule to generate hr tag', () => {
const createNode = function (node) {
expect(node.internalId).toBe(123)
expect(node.id).toBe(`item-123-default`)
}
const setPluginStatus = function () { }
const client = new StoryblokClient({})

Sync.init({
createNode,
setPluginStatus,
client
})

Sync.createNode('Item', { id: 123 })
})
5 changes: 5 additions & 0 deletions lib/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"component": {
"testFiles": "**/*.spec.jsx"
}
}
3 changes: 3 additions & 0 deletions lib/cypress/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["plugin:cypress/recommended"]
}
144 changes: 144 additions & 0 deletions lib/cypress/component/index.spec.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import React from "react";
import Test from "../../testing-components/Test";
import TestUseStoryblok from "../../testing-components/TestUseStoryblok";
import { mount } from "@cypress/react";
import Teaser from "gatsby-source-storyblok-playground/components/teaser";
import Grid from "gatsby-source-storyblok-playground/components/grid";
import Feature from "gatsby-source-storyblok-playground/components/feature";
import Page from "gatsby-source-storyblok-playground/components/page";

describe("gatsby-source-storyblok", () => {
beforeEach(() => {
cy.spy(window.console, "log").as("log");
cy.spy(window.console, "error").as("error");
delete window.storyblokRegisterEvent;
document.getElementById("storyblok-javascript-bridge")?.remove();
});

describe("JS Bridge", () => {
it("loads by default", () => {
mount(<Test />);
cy.get("#storyblok-javascript-bridge").should("exist");
});

it("doesn't load if the bridge is disabled", () => {
mount(<Test bridge={false} />);
cy.get("#storyblok-javascript-bridge").should("not.exist");
cy.get("@error").should(
"be.calledWithMatch",
"Storyblok Bridge is disabled"
);
});
});

describe("getStoryblokApi", () => {
it("should return an instance of the API if we use the API Plugin", () => {
mount(<Test accessToken="OurklwV5XsDJTIE1NJaD2wtt" />);
cy.get('[data-test="api"]').should("have.text", "true");
});

it("shouldn't return an instance of the API if no access token is provided", () => {
mount(<Test />);
cy.get('[data-test="api"]').should("have.text", "false");
});

it("should return an error message when no access token is provided", () => {
mount(<Test />);
cy.get("@error").should(
"be.calledWithMatch",
"You can't use getStoryblokApi"
);
});
});

describe("StoryblokComponent", () => {
it("Should render the StoryblokComponent if the blok is passed", () => {
const blok = {
component: "teaser",
headline: "Hello React",
_editable: `<!--#storyblok#{ "id": 12345, "uid": "fc34-uad1"}-->`,
};

const components = {
teaser: Teaser,
};

mount(
<Test
blok={blok}
accessToken="OurklwV5XsDJTIE1NJaD2wtt"
components={components}
/>
);

cy.get('[data-test="teaser"]').should("exist");
cy.get("[data-test=teaser]")
.should("have.attr", "data-blok-c")
.and("equals", '{"id":12345,"uid":"fc34-uad1"}');

cy.get("[data-test=teaser]")
.should("have.attr", "data-blok-uid")
.and("equals", "12345-fc34-uad1");
});

it("Should log an error if the blok is not loaded", () => {
const components = {
teaser: Teaser,
};

mount(
<Test accessToken="OurklwV5XsDJTIE1NJaD2wtt" components={components} />
);

cy.get('[data-test="teaser"]').should("not.exist");
cy.get("@error").should("be.calledWithMatch", "Please provide a 'blok'");
});

it("Should log an error if the component is not loaded", () => {
const blok = {
component: "teaser",
headline: "Hello React",
_editable: `<!--#storyblok#{ "id": 12345, "uid": "fc34-uad1"}-->`,
};

mount(<Test blok={blok} components={[]} />);

cy.get('[data-test="teaser"]').should("not.exist");
cy.get("@error").should(
"be.calledWithMatch",
"Component teaser doesn't exist."
);
});
});

describe("useStoryblok", () => {
it("Should render the StoryblokComponent", () => {
const components = {
teaser: Teaser,
grid: Grid,
feature: Feature,
page: Page,
};

mount(
<TestUseStoryblok
accessToken="OurklwV5XsDJTIE1NJaD2wtt"
components={components}
/>
);

cy.get('[data-test="page"]').should("exist");
cy.get('[data-test="grid"]').should("exist");
cy.get('[data-test="feature"]').should("have.length", 3);
});

it("Should log an error if no using the apiPlugin", () => {
mount(<TestUseStoryblok />);

cy.get("@error").should(
"be.calledWithMatch",
"You can't use useStoryblok"
);
});
});
});
5 changes: 5 additions & 0 deletions lib/cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
9 changes: 9 additions & 0 deletions lib/cypress/integration/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
describe("gatsby-source-storyblok", () => {
it("Is loaded by default", () => {
cy.visit("http://localhost:8000/");

cy.get('[data-test="grid"]').should("exist");
cy.get('[data-test="teaser"]').should("exist");
cy.get('[data-test="feature"]').should("have.length", 2);
});
});
20 changes: 20 additions & 0 deletions lib/cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const path = require("path");
const { startDevServer } = require("@cypress/vite-dev-server");

module.exports = (on) => {
on("dev-server:start", (options) => {
return startDevServer({
options,
viteConfig: {
configFile: path.resolve(
__dirname,
"..",
"..",
"..",
"playground",
"vite.config.js"
),
},
});
});
};
25 changes: 25 additions & 0 deletions lib/cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
20 changes: 20 additions & 0 deletions lib/cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
Loading

0 comments on commit 9865358

Please sign in to comment.