This repository has been archived by the owner on Aug 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6ecdc63
commit 6a7f524
Showing
3 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"env": { | ||
"mocha": true | ||
}, | ||
"globals": { | ||
"$": true, | ||
"expect": true | ||
}, | ||
"rules": { | ||
"no-unused-expressions": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
describe('viewer', () => { | ||
const createImage = () => { | ||
const container = document.createElement('div'); | ||
const image = document.createElement('img'); | ||
|
||
image.src = '/base/docs/images/tibet-1.jpg'; | ||
container.appendChild(image); | ||
document.body.appendChild(container); | ||
|
||
return image; | ||
}; | ||
|
||
it('should register as a plugin correctly', () => { | ||
expect($.fn.viewer).to.be.a('function'); | ||
expect($.fn.viewer.Constructor).to.be.a('function'); | ||
expect($.fn.viewer.noConflict).to.be.a('function'); | ||
expect($.fn.viewer.setDefaults).to.be.a('function'); | ||
}); | ||
|
||
it('should remove data after destroyed', () => { | ||
const $image = $(createImage()); | ||
|
||
$image.viewer(); | ||
expect($image.data('viewer')).to.be.an.instanceof($.fn.viewer.Constructor); | ||
$image.viewer('destroy'); | ||
expect($image.data('viewer')).to.be.undefined; | ||
}); | ||
|
||
it('should apply the given option', (done) => { | ||
$(createImage()).viewer({ | ||
inline: true, | ||
|
||
ready() { | ||
done(); | ||
}, | ||
}); | ||
}); | ||
|
||
it('should execute the given method', (done) => { | ||
$(createImage()).viewer({ | ||
shown() { | ||
done(); | ||
}, | ||
}).viewer('show'); | ||
}); | ||
|
||
it('should trigger the binding event', (done) => { | ||
$(createImage()).one('ready', (event) => { | ||
expect(event.type).to.equal('ready'); | ||
done(); | ||
}).viewer('show'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const puppeteer = require('puppeteer'); | ||
const rollupConfig = require('../rollup.config'); | ||
|
||
process.env.CHROME_BIN = puppeteer.executablePath(); | ||
|
||
module.exports = (config) => { | ||
config.set({ | ||
autoWatch: false, | ||
basePath: '..', | ||
browsers: ['ChromeHeadlessWithoutSandbox'], | ||
customLaunchers: { | ||
ChromeHeadlessWithoutSandbox: { | ||
base: 'ChromeHeadless', | ||
flags: ['--no-sandbox'], | ||
}, | ||
}, | ||
files: [ | ||
'node_modules/jquery/dist/jquery.js', | ||
'dist/viewer.css', | ||
'dist/viewer.js', | ||
'test/index.js', | ||
{ | ||
pattern: 'docs/images/*', | ||
included: false, | ||
}, | ||
], | ||
frameworks: ['mocha', 'chai'], | ||
preprocessors: { | ||
'test/index.js': ['rollup'], | ||
}, | ||
reporters: ['mocha'], | ||
rollupPreprocessor: { | ||
plugins: rollupConfig.plugins, | ||
output: { | ||
format: 'iife', | ||
name: 'Viewer', | ||
sourcemap: 'inline', | ||
}, | ||
}, | ||
singleRun: true, | ||
}); | ||
}; |