| <!-- | |
| Copyright (C) 2018 The Android Open Source Project | |
| Licensed under the Apache License, Version 2.0 (the "License"); | |
| you may not use this file except in compliance with the License. | |
| You may obtain a copy of the License at | |
| http://www.apache.org/licenses/LICENSE-2.0 | |
| Unless required by applicable law or agreed to in writing, software | |
| distributed under the License is distributed on an "AS IS" BASIS, | |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| See the License for the specific language governing permissions and | |
| limitations under the License. | |
| --> | |
| <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes"> | |
| <title>resemble-diff-mode</title> | |
| <link rel="import" href="../node_modules/polymer/polymer.html"> | |
| <link rel="import" href="../node_modules/@polymer/test-fixture/test-fixture.html"> | |
| <link rel="import" href="../node_modules/iron-test-helpers/iron-test-helpers.html"> | |
| <link rel="import" href="./gr-resemble-diff-mode.html"> | |
| <script>void(0);</script> | |
| <script src="../node_modules/webcomponents.js/webcomponents-lite.min.js"></script> | |
| <script src="../node_modules/web-component-tester/browser.js"></script> | |
| <script src="../node_modules/@polymer/sinonjs/sinon.js"></script> | |
| <test-fixture id="basicFixture"> | |
| <template> | |
| <gr-resemble-diff-mode> | |
| </gr-resemble-diff-mode> | |
| </template> | |
| </test-fixture> | |
| <script> | |
| suite('gr-resemble-diff-mode tests', () => { | |
| let element; | |
| setup(() => { | |
| element = fixture('basicFixture'); | |
| }); | |
| test('test initialization', () => { | |
| assert.notEqual(element, null); | |
| assert.equal(element.baseImage, null); | |
| assert.equal(element.revisionImage, null); | |
| }); | |
| test('test getDataUrl', () => { | |
| element.baseImage = { | |
| type: 'image/png', | |
| body: 'SGVsbG8=', | |
| }; | |
| const desiredOutput = 'data:image/png;base64,SGVsbG8='; | |
| assert.equal(element.getDataUrl(element.baseImage), desiredOutput); | |
| }); | |
| test('test resemble mode image diff', () => { | |
| const img = element.$.imageDiff; | |
| const expected_result = 'data:image/png;base64,SGVsbG8V29ybGQ=='; | |
| assert.isFalse(img.hasAttribute('src')); | |
| element.baseImage = { | |
| type: 'image/png', | |
| body: 'SGVsbG8=', | |
| }; | |
| assert.isFalse(img.hasAttribute('src')); | |
| element.revisionImage = { | |
| type: 'image/png', | |
| body: 'V29ybGQ=', | |
| }; | |
| flushAsynchronousOperations(); | |
| sinon.stub(element, 'compareImages') | |
| .returns(Promise.resolve(expected_result)); | |
| return element._handleImageDiff(element.baseImage, element.revisionImage) | |
| .then(() => { | |
| assert.equal(img.src, expected_result); | |
| }); | |
| }); | |
| }); | |
| </script> |