Skip to content

Commit

Permalink
fix: rename text story to generic story (#223)
Browse files Browse the repository at this point in the history
Co-authored-by: Amogh Sahasrabhojanee <amogh@quintype.com>
  • Loading branch information
ags1773 and Amogh Sahasrabhojanee authored Jul 3, 2020
1 parent eada348 commit f2210f4
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/helpers/ampify-story/ampify-story.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AmpifyStoryTypes } from "./types";
import renderToString from "../render-to-string";
import { TextStory } from "../../templates/text-story/text-story";
import { GenericStory } from "../../templates";
import get from "lodash.get";
import React from "react";

Expand Down Expand Up @@ -31,6 +31,6 @@ const getTemplate = ({ story, config, relatedStories, infiniteScrollInlineConfig

switch (storyType) {
default:
return <TextStory {...propsForTemplate} />;
return <GenericStory {...propsForTemplate} />;
}
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`TextStory Template should render 1`] = `
exports[`GenericStory Template should render 1`] = `
<Layout
config={
Object {
Expand Down
15 changes: 15 additions & 0 deletions src/templates/generic-story/generic-story.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as React from "react";
import { storiesOf } from "@storybook/react";
import { GenericStory } from "./generic-story";
import { storyWithManyJsEmbeds, config, textStory, relatedStories } from "../../__fixtures__";
import { allElementsStory } from "../../__fixtures__/all-element-story.fixture";

storiesOf("Generic Story", module)
.addDecorator((story) => <div>{story()}</div>)
.add("Story with JS Embeds", () => (
<GenericStory relatedStories={relatedStories} story={storyWithManyJsEmbeds} config={config} />
))
.add("Generic Text Story", () => <GenericStory relatedStories={relatedStories} story={textStory} config={config} />)
.add("All Elements Story", () => (
<GenericStory relatedStories={relatedStories} story={allElementsStory} config={config} />
));
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import React from "react";
import { shallow } from "enzyme";
import { TextStory } from "./text-story";
import { GenericStory } from "./generic-story";
import { RelatedStories } from "../../molecules";
import { InfiniteScroll } from "../../atoms";
import { textStory, config, relatedStories } from "../../__fixtures__";
import cloneDeep from "lodash.clonedeep";

describe("TextStory Template", () => {
describe("GenericStory Template", () => {
it("should render", () => {
const wrapper = shallow(<TextStory story={textStory} config={config} relatedStories={relatedStories} />);
const wrapper = shallow(<GenericStory story={textStory} config={config} relatedStories={relatedStories} />);
expect(wrapper).toMatchSnapshot();
});
it("should render related stories component", () => {
const wrapper = shallow(<TextStory story={textStory} config={config} relatedStories={relatedStories} />);
const wrapper = shallow(<GenericStory story={textStory} config={config} relatedStories={relatedStories} />);
expect(wrapper.find(RelatedStories).length).toBe(1);
});
it("should render infinite scroll component if exists", () => {
const modifiedConfig = cloneDeep(config);
const wrapper = shallow(
<TextStory
<GenericStory
story={textStory}
config={modifiedConfig}
relatedStories={relatedStories}
Expand All @@ -29,21 +29,21 @@ describe("TextStory Template", () => {
});
it("should not render infinite scroll component if infinite-scroll-collection-id not passed in ampconfig", () => {
const modifiedConfig = cloneDeep(config);
const wrapper = shallow(<TextStory story={textStory} config={modifiedConfig} relatedStories={relatedStories} />);
const wrapper = shallow(<GenericStory story={textStory} config={modifiedConfig} relatedStories={relatedStories} />);
expect(wrapper.find(InfiniteScroll).length).toBe(0);
});
it("should call relatedStoriesRender prop when passed to opts", () => {
const relatedStoriesRender = jest.fn();
const modifiedConfig = { ...config, opts: { ...config.opts, relatedStoriesRender } };
const wrapper = shallow(<TextStory story={textStory} config={modifiedConfig} relatedStories={relatedStories} />);
const wrapper = shallow(<GenericStory story={textStory} config={modifiedConfig} relatedStories={relatedStories} />);
expect(relatedStoriesRender.mock.calls.length).toBe(1);
expect(wrapper.find(RelatedStories).length).toBe(0);
});
it("should call infiniteScrollRender prop when passed to opts", () => {
const infiniteScrollRender = jest.fn();
const modifiedConfig = { ...config, opts: { ...config.opts, infiniteScrollRender } };
const wrapper = shallow(
<TextStory
<GenericStory
story={textStory}
config={modifiedConfig}
relatedStories={relatedStories}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
InfiniteScroll
} from "../../atoms";
import styled from "styled-components";
import { TextStoryTypes } from "./types";
import { GenericStoryTypes } from "./types";
import get from "lodash.get";

const { TopAd, BodyAd, BottomAd } = AmpAds;
Expand All @@ -28,7 +28,8 @@ const Wrapper = styled.div`
padding: 0 ${(props) => props.theme.spacing.s};
`;
const canDisplayBodyAd = (cardIdx) => cardIdx === 0;
const TextStory = ({ story, config, relatedStories, infiniteScrollInlineConfig }: TextStoryTypes) => {

export const GenericStory = ({ story, config, relatedStories, infiniteScrollInlineConfig }: GenericStoryTypes) => {
const footerText = get(config, ["publisherConfig", "publisher-settings", "copyright"], null);
const infiniteScrollExists = infiniteScrollInlineConfig && infiniteScrollInlineConfig.length; // should also check if infinite scroll collection exists here
let lastComponent = <Footer text={footerText} />;
Expand Down Expand Up @@ -93,5 +94,3 @@ const TextStory = ({ story, config, relatedStories, infiniteScrollInlineConfig }
</Layout>
);
};

export { TextStory };
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Story } from "../../types/story";
import { Config } from "../../types/config";

export interface TextStoryTypes {
export interface GenericStoryTypes {
story: Story;
config: Config;
relatedStories: Story[];
Expand Down
4 changes: 2 additions & 2 deletions src/templates/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { TextStory } from "./text-story/text-story";
export { TextStory };
import { GenericStory } from "./generic-story/generic-story";
export { GenericStory };
15 changes: 0 additions & 15 deletions src/templates/text-story/text-story.stories.tsx

This file was deleted.

0 comments on commit f2210f4

Please sign in to comment.