Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dfrankland committed Aug 10, 2019
1 parent 427d8e0 commit 60ca7c2
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/amphtml/components/__tests__/AmpState.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as React from 'react';
import { mount } from 'enzyme';
import AmpState from '../AmpState';

describe('AmpState', (): void => {
it('returns a directive with `src` attribute set', (): void => {
const src = 'test';
const wrapper = mount(<AmpState src={src} />);
expect(wrapper.find(`amp-state[src="${src}"]`).exists()).toBe(true);
});
});
24 changes: 24 additions & 0 deletions src/amphtml/components/__tests__/Html.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as React from 'react';
import { shallow } from 'enzyme';
import Html from '../Html';

describe('Html', (): void => {
it("doesn't set the `format` attribute if it isn't given", (): void => {
// Use `shallow` here since `html` tags can't really be mounted
const wrapper = shallow(
<Html
// @ts-ignore
format={null}
>
<body>
<h1>Hello, world!</h1>
</body>
</Html>,
);
['amp', 'amp4ads', 'amp4email'].forEach(
(format): void => {
expect(wrapper.find(`html[format="${format}"]`).length).toBe(0);
},
);
});
});
13 changes: 13 additions & 0 deletions src/amphtml/components/__tests__/Script.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as React from 'react';
import { mount } from 'enzyme';
import Script from '../Script';

describe('Script', (): void => {
it('returns `null` if `src` or if both `extension` and `version` are missing', (): void => {
const wrapperSrc = mount(<Script src="" />);
expect(wrapperSrc.find('script').exists()).toBe(false);

const wrapperExtensionVersion = mount(<Script extension="" version="" />);
expect(wrapperExtensionVersion.find('script').exists()).toBe(false);
});
});
21 changes: 21 additions & 0 deletions src/lib/__tests__/getScriptSource.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import getScriptSource from '../getScriptSource';

describe('getScriptSource', (): void => {
it('returns a url', (): void => {
const src = 'test-src';
const extension = 'test-extension';
const version = 'test-version';

expect(getScriptSource({ src, extension, version })).toBe(src);
expect(getScriptSource({ src })).toBe(src);
expect(getScriptSource({ extension, version })).toBe(
`https://cdn.ampproject.org/v0/${extension}-${version}.js`,
);
expect(getScriptSource({ version })).toBe(
`https://cdn.ampproject.org/v0/-${version}.js`,
);
expect(getScriptSource({ extension })).toBe(
`https://cdn.ampproject.org/v0/${extension}-latest.js`,
);
});
});

0 comments on commit 60ca7c2

Please sign in to comment.