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

Feature/jsdom (WIP) #391

Closed
wants to merge 3 commits into from
Closed
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
8 changes: 2 additions & 6 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
{
"presets": ["react", "es2015", "stage-0"],
"plugins": [
"react-require",
"transform-runtime",
"add-module-exports",
"transform-decorators-legacy",
"transform-react-display-name"
"transform-react-display-name",
],
"env": {
"test": {
"plugins": [
"rewire"
]
},
"development": {
"plugins": [
"typecheck"
Expand Down
146 changes: 0 additions & 146 deletions karma.conf.js

This file was deleted.

23 changes: 8 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"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": "NODE_ENV=test jasmine JASMINE_CONFIG_PATH='./tests/jasmine.json'",
"test:ci:unit": "npm test && npm run test:ci:lint",
"test:ci:functional": "node ./nightwatch.js -c ./nightwatch.json -e production",
"test:ci:lint": "eslint ./src/**/*.js",
"test:dev:unit": "./node_modules/karma/bin/karma start",
"test:dev:unit": "npm test",
"test:dev:functional": "node ./nightwatch.js -c ./nightwatch.json",
"test:dev:lint": "eslint ./src/scripts/**/*.js",
"dev": "node webpack/dev-server.js & PORT=8000 node start.js",
Expand Down Expand Up @@ -109,6 +109,7 @@
"devDependencies": {
"babel-core": "^6.7.7",
"babel-eslint": "^6.0.4",
"babel-plugin-react-require": "^2.1.0",
"babel-plugin-react-transform": "^2.0.2",
"babel-preset-react-hmre": "^1.1.1",
"chai": "^3.0.0",
Expand All @@ -121,18 +122,10 @@
"eslint-plugin-import": "^1.8.1",
"eslint-plugin-jsx-a11y": "^1.5.3",
"eslint-plugin-react": "^5.2.2",
"jasmine": "^2.4.1",
"jasmine-spec-reporter": "^2.5.0",
"jscs": "^2.1.1",
"karma": "^0.13.9",
"karma-chai": "^0.1.0",
"karma-chai-sinon": "^0.1.5",
"karma-chrome-launcher": "^0.2.0",
"karma-junit-reporter": "^0.3.4",
"karma-mocha": "^0.2.0",
"karma-phantomjs-launcher": "~0.2.1",
"karma-script-launcher": "~0.1.0",
"karma-sinon": "^1.0.4",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^1.6.0",
"jsdom": "^8.0.2",
"mocha": "^2.2.5",
"nightwatch": "^0.8.6",
"nodemon": "^1.7.1",
Expand All @@ -147,7 +140,7 @@
"redux-devtools-dock-monitor": "^1.1.0",
"redux-devtools-log-monitor": "^1.0.5",
"selenium-server": "^2.48.2",
"sinon": "^1.15.3",
"sinon": "^1.17.4",
"sinon-chai": "^2.8.0",
"webpack-dev-server": "^1.6.5"
},
Expand Down
19 changes: 10 additions & 9 deletions src/components/Ayah/spec.js → src/components/Ayah/ayah.test.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { shallow } from 'enzyme';

import Ayah from './index';

import Ayah from './index.js';
import ayah from '../../../tests/fixtures/ayah';

let wrapper;

describe('<Ayah />', () => {
describe("Ayah", () => {

beforeEach(() => {
wrapper = shallow(<Ayah ayah={ayah} />);
});

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

it('should have correct ayah number', () => {
expect(wrapper.find('.label').text()).to.eql(ayah.ayahKey);
expect(wrapper.find('.label').text()).toBe(ayah.ayahKey);
});

it('should contain translations', () => {
expect(wrapper.find('.translation').text()).to.eql(ayah.content[0].resource.name);
expect(wrapper.find('.translation').text()).toBe(ayah.content[0].resource.name);
});



});
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,35 @@ describe('<ContentDropdown />', () => {
});

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

it('should contain all the content options', () => {
slugs.filter(slug => slug.language !== 'ar').forEach(slug => {
expect(wrapper.text()).to.contain(slug.name);
expect(wrapper.text()).toContain(slug.name);
});
});

it('should show chosen content option', () => {
expect(wrapper.find(`#${defaultOption}en`).prop('checked')).to.equal(defaultOption);
expect(wrapper.find(`#${defaultOption}en`).prop('checked')).toBe(defaultOption);
});

it('should add option when clicked', () => {
fit('should add option when clicked', () => {
const id = 18;
wrapper.find(`#${id}en`).simulate('change');

expect(onOptionChange).to.have.been.called;
expect(onOptionChange).to.have.been.calledWith({content: [defaultOption, id]});
expect(onOptionChange).toHaveBeenCalled();
//expect(onOptionChange).toHaveBeenCalledWith({content: [defaultOption, id]});
});

it('should remove option when clicked', () => {
xit('should remove option when clicked', () => {
wrapper.find(`#${defaultOption}en`).simulate('change');

expect(onOptionChange).to.have.been.called;
expect(onOptionChange).to.have.been.calledWith({content: []});
});

it('should remove all content', () => {
xit('should remove all content', () => {
const removeAll = wrapper.find({eventKey: 1})
expect(removeAll.html()).to.contain('Remove all');

Expand Down
2 changes: 1 addition & 1 deletion src/containers/Surah/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ class Surah extends Component {
}
}

const AsyncSurah = asyncConnect([ { promise: surahsConnect }, { promise: ayahsConnect } ])(Surah);
const AsyncSurah = asyncConnect([{ promise: surahsConnect }, { promise: ayahsConnect }])(Surah);

function mapStateToProps(state, ownProps) {
const surahId = parseInt(ownProps.params.surahId, 10);
Expand Down
38 changes: 38 additions & 0 deletions tests/jasmine-boot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';
require.extensions['.scss'] = function () {
return null;
};

// es6 and jsx support
require("babel-core/register");
require("babel-polyfill");
//settings
var SpecReporter = require('jasmine-spec-reporter');
jasmine.DEFAULT_TIMEOUT_INTERVAL = 120000;
jasmine.getEnv().addReporter(new SpecReporter({
displayStacktrace: true
}));
// for client side testing
var jsdom = require('jsdom');
global.document = jsdom.jsdom('<!doctype html><html><body><div id="quran"></div></body></html>');
global.window = document.defaultView;
global.sinon = require('sinon');
propagateToGlobal(global.window);

// from mocha-jsdom https://github.com/rstacruz/mocha-jsdom/blob/master/index.js#L80
function propagateToGlobal (window) {
for (let key in window) {
if (!window.hasOwnProperty(key)) continue;
if (key in global) continue;

global[key] = window[key]
}
}

beforeAll(function () {
//any tasks to run before all tests
});

beforeEach(function () {
process.env.NODE_ENV = "";
});
7 changes: 7 additions & 0 deletions tests/jasmine.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"spec_dir": "./",
"spec_files": [
"./tests/jasmine-boot.js",
"./src/**/*.test.js"
]
}
3 changes: 1 addition & 2 deletions webpack/dev.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ require('dotenv').load();
var fs = require('fs');
var path = require('path');
var webpack = require('webpack');
var path = require('path');
var IsomorphicPlugin = require('webpack-isomorphic-tools/plugin');
var webpackIsomorphicToolsPlugin = new IsomorphicPlugin(require('./isomorphic-tools-configuration'));

Expand Down Expand Up @@ -37,7 +36,7 @@ module.exports = {
'add-module-exports',
'transform-decorators-legacy',
'transform-react-display-name',
'typecheck',
'typecheck'
],
presets: ['react', 'es2015-webpack', 'stage-0', 'react-hmre'],
cacheDirectory: true
Expand Down