docbrown/app/javascript/article-form/components/__tests__/Preview.test.jsx
ludwiczakpawel 16f4d7d46a
[deploy] Article Design update (#8234)
* flare tag line height

* .

* init

* widgets

* widgets lists

* new tabs on home

* instantclick

* .

* rethinking css

* .

* .

* empty space

* init

* campaign widget

* .

* merge

* .

* update layout

* fix sidebars on home page

* .

* fix onboarding x

* test

* spec

* test

* toolbar fix

* more

* test

* better handling ads

* .

* spec

* card border

* .

* .

* actions bar

* cleanup

* animation

* test

* button width

* .

* better responsiveness and author boxes

* meta info

* padding

* better animation

* optimize videos

* fixes

* spec

* .

* codeblocks in comments

* whoops

* Use .present? correctly as it preloads items

* sticky nav

* Update app/views/articles/_sticky_nav.html.erb

I don't know what I'm doing but @benhalpern says so! e8c0f337a5 (r440248874)

Co-authored-by: Ben Halpern <bendhalpern@gmail.com>

* Update app/views/articles/show.html.erb

I don't know what I'm doing but @benhalpern says so! e8c0f337a5 (r440247802)

Co-authored-by: Ben Halpern <bendhalpern@gmail.com>

* little fixes

* Update app/assets/stylesheets/article-show.scss

Co-authored-by: Ben Halpern <bendhalpern@gmail.com>

* pawel updating ruby code......

* actually better merge

* semantic updates

* .

Co-authored-by: rhymes <rhymesete@gmail.com>
Co-authored-by: Ben Halpern <bendhalpern@gmail.com>
2020-06-17 09:57:57 -04:00

137 lines
3.4 KiB
JavaScript

import { h } from 'preact';
import render from 'preact-render-to-json';
import { JSDOM } from 'jsdom';
import { shallow } from 'preact-render-spy';
import { Preview } from '../Preview';
const doc = new JSDOM('<!doctype html><html><body></body></html>');
global.document = doc;
global.window = doc.defaultView;
global.window.currentUser = {
id: 1,
name: 'Guy Fieri',
username: 'guyfieri',
profile_image_90:
'/uploads/user/profile_image/41/0841dbe2-208c-4daa-b498-b2f01f3d37b2.png',
};
let previewResponse;
let articleState;
let errors;
describe('<Preview />', () => {
beforeEach(() => {
previewResponse = {
processed_html:
'<p>My Awesome Post! Not very long, but still very awesome.</p>↵↵',
title: 'My Awesome Post',
tags: null,
cover_image: 'http://lorempixel.com/400/200/',
};
articleState = {
id: null,
title: 'My Awesome Post',
tagList: 'javascript, career, ',
description: 'Some description',
canonicalUrl: '',
series: '',
allSeries: ['Learn Something new a day'],
bodyMarkdown:
'---↵title: My Awesome Post↵published: false↵description: ↵tags: ↵---↵↵My Awesome Post Not very long, but still very awesome! ↵',
submitting: false,
editing: false,
mainImage: '/i/9ca8kb1cu34mobypm5yx.png',
organizations: [
{
id: 4,
bg_color_hex: '',
name: 'DEV',
text_color_hex: '',
profile_image_90:
'/uploads/organization/profile_image/4/1689e7ae-6306-43cd-acba-8bde7ed80a17.JPG',
},
],
organizationId: null,
errors: null,
edited: true,
updatedAt: null,
version: 'v2',
helpFor: null,
helpPosition: null,
};
errors = null;
});
it('renders properly', () => {
const tree = render(
<Preview
previewResponse={previewResponse}
articleState={articleState}
errors={errors}
/>,
);
expect(tree).toMatchSnapshot();
});
it('shows the correct title', () => {
const container = shallow(
<Preview
previewResponse={previewResponse}
articleState={articleState}
errors={errors}
/>,
);
expect(container.find('.spec-article__title').text()).toEqual(
previewResponse.title,
);
});
it('shows the correct tags', () => {
const container = shallow(
<Preview
previewResponse={previewResponse}
articleState={articleState}
errors={errors}
/>,
);
expect(container.find('.spec-article__tags').text()).toEqual(
'#javascript#career',
);
});
it('shows a cover image in the preview if one exists', () => {
const container = shallow(
<Preview
previewResponse={previewResponse}
articleState={articleState}
errors={errors}
/>,
);
expect(container.find('.crayons-article__cover__image').exists()).toEqual(
true,
);
});
it('does not show a cover image in the preview if one does not exists', () => {
previewResponse.cover_image = null;
articleState.mainImage = null;
const container = shallow(
<Preview
previewResponse={previewResponse}
articleState={articleState}
errors={errors}
/>,
);
expect(container.find('.crayons-article__cover__image').exists()).toEqual(
false,
);
});
// TODO: need to write a test for the cover image for v1
});