This repository has been archived by the owner on Dec 4, 2024. It is now read-only.
forked from storyblok/gatsby-source-storyblok
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add new APIs and close dependabot conflicts
- Loading branch information
Showing
56 changed files
with
61,165 additions
and
11,816 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"env": { | ||
"jest": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"component": { | ||
"testFiles": "**/*.spec.jsx" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": ["plugin:cypress/recommended"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
), | ||
}, | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) => { ... }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
Oops, something went wrong.