Browse files

Added unit and functional tests for data-at2x attributes support

  • Loading branch information...
1 parent 9081a92 commit 71778f3d4d305e3d01e9a6af955a12a7a5b08577 @ronny ronny committed Jan 12, 2013
Showing with 22 additions and 9 deletions.
  1. +9 −8 test/functional/public/index.html
  2. +13 −1 test/retina_image_path.test.js
View
17 test/functional/public/index.html
@@ -6,33 +6,34 @@
width: 80%;
margin: auto;
}
-
+
.responsive img {
display: block;
width: auto;
height: auto;
max-width: 100%;
}
</style>
-
+
<script type="text/javascript">
// Spoof the browser into thinking it is Retina
// comment the next line out to make sure it works without retina
- window.devicePixelRatio = 2;
+ window.devicePixelRatio = 2;
</script>
</head>
<body>
<img src="google.png" />
<img src="google.png" /> <!-- It will find the @2x version of this in the confirmed_paths cache because it is a duplicate -->
<img src="google@1x.png" /> <!-- This will not be replaced with a retina version-->
- <img src="https://www.google.com/logos/2012/doisneau12-hp.jpg" />
-
+ <img src="https://www.google.com/logos/2012/doisneau12-hp.jpg" />
+
<div class="responsive">
<img src="ipad_hero.jpeg" />
- <img src="ipad_hero@1x.jpeg" /> <!-- This will not be replaced with a retina version-->
+ <img src="ipad_hero@1x.jpeg" /> <!-- This will not be replaced with a retina version-->
</div>
-
-
+
+ <img src="google.png" data-at2x="ipad_hero@2x.jpeg" />
+
<script type="text/javascript" charset="utf-8" src="retina.js"></script>
</body>
</html>
View
14 test/retina_image_path.test.js
@@ -18,7 +18,6 @@ var Retina = require('../').Retina;
var RetinaImage = require('../').RetinaImage;
var RetinaImagePath = require('../').RetinaImagePath;
-
describe('RetinaImagePath', function() {
var path = null;
@@ -31,6 +30,11 @@ describe('RetinaImagePath', function() {
path = new RetinaImagePath("/path/to/image.png");
path.at_2x_path.should.equal("/path/to/image@2x.png");
});
+
+ it('uses data-@2x when supplied', function(){
+ path = new RetinaImagePath("/path/to/image-hash1.png", "/path/to/image@2x-hash2.png");
+ path.at_2x_path.should.equal("/path/to/image@2x-hash2.png");
+ });
});
describe('#is_external()', function() {
@@ -111,6 +115,14 @@ describe('RetinaImagePath', function() {
});
});
+ it('should callback with true when at2x is supplied', function(done) {
+ path = new RetinaImagePath("/images/some_image.png", "/images/some_image@100x.png");
+ path.check_2x_variant(function(hasVariant) {
+ hasVariant.should.equal(true);
+ done();
+ });
+ });
+
it('should callback with false when remote at2x image does not exist', function(done) {
XMLHttpRequest.status = 404; // simulate a failing request
XMLHttpRequest.contentType = 'image/png'; // simulate a proper content type

0 comments on commit 71778f3

Please sign in to comment.