Skip to content

Commit

Permalink
Bump up the test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
osteele committed May 19, 2018
1 parent 73381d8 commit 550a3fa
Show file tree
Hide file tree
Showing 9 changed files with 991 additions and 114 deletions.
706 changes: 706 additions & 0 deletions src/__test__/__snapshots__/add-edit-page.test.jsx.snap

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/__test__/__snapshots__/event-details-page.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ exports[`EventDetailsPage multi-day all-day event 1`] = `
<span
className="event-start"
>
Tue, May 8, 2018
Wed, May 9, 2018
</span>
</span>
<p
Expand Down Expand Up @@ -86,14 +86,14 @@ exports[`EventDetailsPage regular event 1`] = `
<span
className="event-start"
>
Mon, May 7, 2018 9:00 AM
Mon, May 7, 2018 10:00 AM
</span>
<span>
 to
<span
className="event-start"
>
10:00 AM
11:00 AM
</span>
</span>
<p
Expand Down
206 changes: 148 additions & 58 deletions src/__test__/__snapshots__/label-pane.test.jsx.snap
Original file line number Diff line number Diff line change
@@ -1,8 +1,98 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`LabelPane matches snapshot 1`] = `
exports[`LabelPane disables protected labels 1`] = `
<div
className="css-class"
className=""
>
<style
type="text/css"
>
.label.label-label-1.selected{background-color:red}
.label.label-label-1.selected:not(.disabled):not(.no-hover):hover,
.label.label-label-1:not(.selected)
{background-color:white;border-color:red;color:red}
.label.label-label-1:not(.disabled):not(.no-hover):hover
{background-color:red;color:white}
.label.label-label-2.selected{background-color:green}
.label.label-label-2.selected:not(.disabled):not(.no-hover):hover,
.label.label-label-2:not(.selected)
{background-color:white;border-color:green;color:green}
.label.label-label-2:not(.disabled):not(.no-hover):hover
{background-color:green;color:white}
</style>
<div
className="label-selector-list"
>
<button
className="button label label-label-1 "
id="label-1"
onClick={[Function]}
title="first label"
type="button"
>
<span
className="ion-pricetag"
>
 
</span>
first
</button>
<button
className="button label label-label-2 disabled"
id="label-2"
onClick={[Function]}
title="second label"
type="button"
>
<span
className="ion-android-lock"
>
 
</span>
second
</button>
</div>
</div>
`;

exports[`LabelPane hides unselected labels 1`] = `
<div
className=""
>
<style
type="text/css"
>
.label.label-label-1.selected{background-color:red}
.label.label-label-1.selected:not(.disabled):not(.no-hover):hover,
.label.label-label-1:not(.selected)
{background-color:white;border-color:red;color:red}
.label.label-label-1:not(.disabled):not(.no-hover):hover
{background-color:red;color:white}
</style>
<div
className="label-selector-list"
>
<button
className="button label label-label-1 selected "
id="label-1"
onClick={[Function]}
title="first label"
type="button"
>
<span
className="ion-pricetag"
>
 
</span>
first
</button>
</div>
</div>
`;

exports[`LabelPane matches baseline 1`] = `
<div
className=""
>
<style
type="text/css"
Expand Down Expand Up @@ -57,7 +147,7 @@ exports[`LabelPane matches snapshot 1`] = `

exports[`LabelPane not editable 1`] = `
<div
className="css-class"
className=""
>
<style
type="text/css"
Expand Down Expand Up @@ -106,6 +196,61 @@ exports[`LabelPane not editable 1`] = `
</div>
`;

exports[`LabelPane shows selected labels 1`] = `
<div
className=""
>
<style
type="text/css"
>
.label.label-label-1.selected{background-color:red}
.label.label-label-1.selected:not(.disabled):not(.no-hover):hover,
.label.label-label-1:not(.selected)
{background-color:white;border-color:red;color:red}
.label.label-label-1:not(.disabled):not(.no-hover):hover
{background-color:red;color:white}
.label.label-label-2.selected{background-color:green}
.label.label-label-2.selected:not(.disabled):not(.no-hover):hover,
.label.label-label-2:not(.selected)
{background-color:white;border-color:green;color:green}
.label.label-label-2:not(.disabled):not(.no-hover):hover
{background-color:green;color:white}
</style>
<div
className="label-selector-list"
>
<button
className="button label label-label-1 selected "
id="label-1"
onClick={[Function]}
title="first label"
type="button"
>
<span
className="ion-pricetag"
>
 
</span>
first
</button>
<button
className="button label label-label-2 "
id="label-2"
onClick={[Function]}
title="second label"
type="button"
>
<span
className="ion-pricetag"
>
 
</span>
second
</button>
</div>
</div>
`;

exports[`LabelPane sorts labels 1`] = `
<div
className=""
Expand Down Expand Up @@ -220,58 +365,3 @@ exports[`LabelPane sorts labels 1`] = `
</div>
</div>
`;

exports[`LabelPane with selected labels 1`] = `
<div
className="css-class"
>
<style
type="text/css"
>
.label.label-label-1.selected{background-color:red}
.label.label-label-1.selected:not(.disabled):not(.no-hover):hover,
.label.label-label-1:not(.selected)
{background-color:white;border-color:red;color:red}
.label.label-label-1:not(.disabled):not(.no-hover):hover
{background-color:red;color:white}
.label.label-label-2.selected{background-color:green}
.label.label-label-2.selected:not(.disabled):not(.no-hover):hover,
.label.label-label-2:not(.selected)
{background-color:white;border-color:green;color:green}
.label.label-label-2:not(.disabled):not(.no-hover):hover
{background-color:green;color:white}
</style>
<div
className="label-selector-list"
>
<button
className="button label label-label-1 selected "
id="label-1"
onClick={[Function]}
title="first label"
type="button"
>
<span
className="ion-pricetag"
>
 
</span>
first
</button>
<button
className="button label label-label-2 "
id="label-2"
onClick={[Function]}
title="second label"
type="button"
>
<span
className="ion-pricetag"
>
 
</span>
second
</button>
</div>
</div>
`;
81 changes: 52 additions & 29 deletions src/__test__/add-edit-page.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,68 @@ import moment from 'moment';
import AddEditEventPage from '../pages/add-edit/add-edit-page';

describe('AddEditEventPage', () => {
// TODO: test the snapshot. This requires mocking moment or
// EventDateTimeSelector, or modifying the latter to accept the datetime as
// a property.
test.skip('matches snapshot', () => {
const event = {
title: 'An event title',
labels: ['label'],
start: moment('2018-05-04T09:00:00Z'),
end: moment('2018-05-04T10:00:00Z'),
};
const userAccount = {
scope: new Map(),
};
const adminAccount = {
scope: new Map(),
};
const event = {
title: 'An event title',
description: 'some *markdown*',
labels: ['label'],
start: moment('2018-05-04T09:00:00Z'),
end: moment('2018-05-04T10:00:00Z'),
};
const sidebarFunctions = {
setPageTitlePrefix: () => undefined,
setSidebarMode: () => undefined,
toggleSidebarCollapsed: () => undefined,
};

test('new event', () => {
const component = renderer.create(<AddEditEventPage
account={userAccount}
eventData={null}
match={{ params: {} }}
{...sidebarFunctions}
/>);
const tree = component.toJSON();
expect(tree).toMatchSnapshot();
});
test('signed-in user', () => {
const component = renderer.create(<AddEditEventPage
account={userAccount}
eventData={event}
match={{ params: { id: 1 } }}
{...sidebarFunctions}
/>);
const tree = component.toJSON();
expect(tree).toMatchSnapshot();
});
test('admin', () => {
const component = renderer.create(<AddEditEventPage
account={userAccount}
eventData={event}
match={{ params: { id: 1 } }}
setPageTitlePrefix={() => undefined}
setSidebarMode={() => undefined}
toggleSidebarCollapsed={() => undefined}
{...sidebarFunctions}
/>);
const tree = component.toJSON();
expect(tree).toMatchSnapshot();
});
test('validateInput', () => {
const event = {
title: 'An event title',
labels: [''],
start: moment('2018-05-04T09:00:00Z'),
end: moment('2018-05-04T10:00:00Z'),
};
const wrapper = shallow(<AddEditEventPage
const instance = shallow(<AddEditEventPage
account={adminAccount}
eventData={event}
match={{ params: { id: 1 } }}
possibleLabels={{}}
setPageTitlePrefix={() => undefined}
setSidebarMode={() => undefined}
toggleSidebarCollapsed={() => undefined}
/>);
expect(wrapper.instance().validateInput()).toBe(false);
wrapper.instance().titleChanged({ currentTarget: { value: 'Title' } });
expect(wrapper.instance().validateInput()).toBe(false);
wrapper.instance().labelToggled('label-1');
expect(wrapper.instance().validateInput()).toBe(true);
{...sidebarFunctions}
/>).instance();
expect(instance.validateInput()).toBe(false);
instance.titleChanged({ currentTarget: { value: 'Title' } });
expect(instance.validateInput()).toBe(false);
instance.labelToggled('label-1');
expect(instance.validateInput()).toBe(true);
instance.saveButtonClicked();
});
});
17 changes: 16 additions & 1 deletion src/__test__/auth.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
import { removeOauthParams } from '../data/auth';
import {
canSignOut,
initializeAccessToken,
clearAccessToken,
removeOauthParams,
} from '../data/auth';

describe('access tokens', () => {
test('sequence', () => {
localStorage.abeAccessToken = 'token';
initializeAccessToken();
expect(canSignOut()).toEqual(true);
clearAccessToken();
expect(canSignOut()).toEqual(true);
});
});

/* eslint-disable max-len */
describe('removeOauthParams', () => {
Expand Down
1 change: 0 additions & 1 deletion src/__test__/event-details-page.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import renderer from 'react-test-renderer';
import EventDetailsPage from '../pages/details/event-details-page';

describe('EventDetailsPage', () => {
moment.tz.setDefault('EST');
test('loading', () => {
const jsx = <EventDetailsPage eventData={null} setSidebarMode={() => undefined} />;
const component = renderer.create(jsx);
Expand Down

0 comments on commit 550a3fa

Please sign in to comment.