mirror of
https://github.com/StarCitizenTools/mediawiki-extensions-TabberNeue.git
synced 2024-11-27 09:42:48 +00:00
Write tests for tabber
This commit is contained in:
parent
82379c9619
commit
604bf0e4cb
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,3 +3,4 @@
|
|||
*.kate-swp
|
||||
.*.swp
|
||||
.DS_Store
|
||||
node_modules/
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
showContent(tabContent.first().attr('title'));
|
||||
}
|
||||
|
||||
// Repond to clicks on the nav tabs
|
||||
// Respond to clicks on the nav tabs
|
||||
nav.on('click', 'a', function(e) {
|
||||
var title = $(this).attr('title');
|
||||
e.preventDefault();
|
||||
|
|
27
karma.conf.js
Normal file
27
karma.conf.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
module.exports = function(config) {
|
||||
config.set({
|
||||
basePath: '../../',
|
||||
frameworks: ['jasmine'],
|
||||
files: [
|
||||
'resources/lib/jquery/jquery.js',
|
||||
|
||||
'extensions/Tabber/js/**/*.js',
|
||||
'extensions/Tabber/spec/**/*.js'
|
||||
],
|
||||
reporters: ['progress', 'coverage'],
|
||||
coverageReporter: {
|
||||
reporters: [
|
||||
{ type: 'text-summary' }
|
||||
]
|
||||
},
|
||||
preprocessors: {
|
||||
'extensions/Tabber/js/**/*.js': ['coverage']
|
||||
},
|
||||
port: 9876, // karma web server port
|
||||
colors: true,
|
||||
logLevel: config.LOG_INFO,
|
||||
browsers: ['ChromeHeadless'],
|
||||
autoWatch: false,
|
||||
concurrency: Infinity
|
||||
})
|
||||
};
|
4144
package-lock.json
generated
Normal file
4144
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
30
package.json
Normal file
30
package.json
Normal file
|
@ -0,0 +1,30 @@
|
|||
{
|
||||
"name": "tabber",
|
||||
"version": "2.4.0",
|
||||
"description": "Allows to create tabs within a page",
|
||||
"main": "js/tabber.js",
|
||||
"scripts": {
|
||||
"lint": "eslint js/**/*",
|
||||
"test": "karma start --single-run --browsers ChromeHeadless karma.conf.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/HydraWiki/Tabber.git"
|
||||
},
|
||||
"author": "Eric Fortin, Alexia E. Smith",
|
||||
"license": "GPL-3.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/HydraWiki/Tabber/issues"
|
||||
},
|
||||
"homepage": "https://github.com/HydraWiki/Tabber#readme",
|
||||
"devDependencies": {
|
||||
"eslint": "^4.9.0",
|
||||
"eslint-config-wikimedia": "^0.5.0",
|
||||
"istanbul": "^0.4.5",
|
||||
"jasmine": "^2.8.0",
|
||||
"karma": "^1.7.1",
|
||||
"karma-chrome-launcher": "^2.2.0",
|
||||
"karma-coverage": "^1.1.1",
|
||||
"karma-jasmine": "^1.1.0"
|
||||
}
|
||||
}
|
60
spec/tabber.spec.js
Normal file
60
spec/tabber.spec.js
Normal file
|
@ -0,0 +1,60 @@
|
|||
describe('Tabber', function () {
|
||||
var $tabber;
|
||||
|
||||
beforeEach(function() {
|
||||
var tabber = '<div class="tabber">' +
|
||||
'<div class="tabbertab" title="Tab1"></div>' +
|
||||
'<div class="tabbertab" title="Tab2"></div>' +
|
||||
'<div class="tabbertab" title="Tab3"></div>' +
|
||||
'</div>';
|
||||
|
||||
$tabber = $(tabber).tabber();
|
||||
});
|
||||
|
||||
it('creates navigation tabs from provided tab titles', function () {
|
||||
var $tabs = $tabber.find('ul.tabbernav li');
|
||||
|
||||
expect($tabber.find('ul.tabbernav:first-child').length).toBeTruthy();
|
||||
expect($tabs.length).toBe(3);
|
||||
|
||||
$tabs.each(function (i) {
|
||||
var $tab = $(this);
|
||||
expect($tab.text()).toBe('Tab' + (i+1));
|
||||
});
|
||||
});
|
||||
|
||||
it('inserts manual word break after each tab', function () {
|
||||
expect($tabber.find('ul.tabbernav li+wbr').length).toBe(3);
|
||||
});
|
||||
|
||||
it('displays contents of first tab initially', function () {
|
||||
var $firstTab = $tabber.find('ul.tabbernav li:first');
|
||||
|
||||
expect($firstTab.hasClass('tabberactive')).toBe(true);
|
||||
});
|
||||
|
||||
it('displays contents of tab specified in URL hash', function () {
|
||||
window.location.hash = '#Tab3';
|
||||
|
||||
var otherTabber = '<div class="tabber">' +
|
||||
'<div class="tabbertab" title="Tab1"></div>' +
|
||||
'<div class="tabbertab" title="Tab2"></div>' +
|
||||
'<div class="tabbertab" title="Tab3"></div>' +
|
||||
'</div>';
|
||||
|
||||
var $otherTabber = $(otherTabber).tabber(),
|
||||
$lastTab = $otherTabber.find('ul.tabbernav a:last');;
|
||||
|
||||
expect(window.location.hash).toBe('#Tab3');
|
||||
expect($lastTab.parent().hasClass('tabberactive')).toBe(true);
|
||||
});
|
||||
|
||||
it('responds to clicks on navigation tabs', function () {
|
||||
var $lastTab = $tabber.find('ul.tabbernav a:last');
|
||||
|
||||
$lastTab.click();
|
||||
|
||||
expect(window.location.hash).toBe('#Tab3');
|
||||
expect($lastTab.parent().hasClass('tabberactive')).toBe(true);
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue