Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

closes #398 - "Previous/Next Surah" when reading first/last surah #412

Merged
merged 3 commits into from
Jul 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"version": "1.0.0",
"private": false,
"scripts": {
"test": "./node_modules/karma/bin/karma start",
"test:ci:unit": "./node_modules/karma/bin/karma start --browsers PhantomJS --single-run; npm run test:ci:lint",
"test:dev:unit": "./node_modules/karma/bin/karma start",
"test": "npm run test:dev:unit",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just an FYI, npm makes anything within node_modules/.bin usable as a global within npm scripts.

"test:ci:unit": "karma start --browsers PhantomJS --single-run; npm run test:ci:lint",
"test:ci:functional": "node ./nightwatch.js -c ./nightwatch.json -e production",
"test:dev:unit": "karma start",
"test:dev:functional": "node ./nightwatch.js -c ./nightwatch.json",
"test:ci:lint": "eslint ./src/**/*.js",
"test:dev:lint": "eslint ./src/scripts/**/*.js",
Expand Down
5 changes: 2 additions & 3 deletions src/containers/Surah/Title/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const zeroPad = (num, places) => {

const Title = ({ surah }) => {
const title = require(`../../../../static/images/titles/${zeroPad(surah.id, 3)}.svg`); // eslint-disable-line global-require,max-len

return (
<div className={`row ${styles.container}`}>
<div className="col-md-3 col-xs-1 surah-title">
Expand All @@ -23,7 +22,7 @@ const Title = ({ surah }) => {
alt="Ornament left"
/>
{
surah.id >= 1 &&
surah.id > 1 &&
<Link
data-metrics-event-name="Title:PreviousSurah"
className="navbar-text previous-chapter"
Expand Down Expand Up @@ -56,7 +55,7 @@ const Title = ({ surah }) => {
</div>
<div className="col-md-3 col-xs-1 surah-title text-right">
{
surah.id <= 114 &&
surah.id < 114 &&
<Link
data-metrics-event-name="Title:NextSurah"
className="navbar-text next-chapter"
Expand Down
62 changes: 62 additions & 0 deletions src/containers/Surah/Title/spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { shallow } from 'enzyme';

import Title from './index';
import getSurahs from '../../../../tests/fixtures/getSurahs.js';

let wrapper;
let surah = {
"id": 1,
"name": {
"arabic": "الفاتحة",
"simple": "Al-Fatihah",
"complex": "Al-Fātiĥah",
"english": "The Opener"
}
};


describe('<Title />', () => {

it('should render', () => {
wrapper = renderComponent(surah);
expect(wrapper).to.be.ok;
});

it('should not show previous surah if on the first surah', () => {
wrapper = renderComponent(surah);

const previous = wrapper.find('.previous-chapter').length;
const next = wrapper.find('.next-chapter').length;

expect(previous).to.equal(0);
expect(next).to.equal(1);
});

it('should not show next surah if on the last surah', () => {
surah.id = 114;
wrapper = renderComponent(surah);

const previous = wrapper.find('.previous-chapter').length;
const next = wrapper.find('.next-chapter').length;

expect(previous).to.equal(1);
expect(next).to.equal(0);
});

it('should show both next and previous if surah is neither last or first', () => {
surah.id = 14;
wrapper = renderComponent(surah);

const previous = wrapper.find('.previous-chapter').length;
const next = wrapper.find('.next-chapter').length;

expect(previous).to.equal(1);
expect(next).to.equal(1);
});
});

function renderComponent(data) {
return shallow(<Title surah={data}/>);
}