|
| 1 | +const chai = require('chai'); |
| 2 | +const chaiAsPromised = require('chai-as-promised'); |
| 3 | +const chaiArrays = require('chai-arrays'); |
| 4 | + |
| 5 | +const utils = require('./utils.js'); |
| 6 | + |
| 7 | +const isVisible = utils.isVisible; |
| 8 | + |
| 9 | +chai.use(chaiAsPromised); |
| 10 | +chai.use(chaiArrays); |
| 11 | +const expect = chai.expect; |
| 12 | + |
| 13 | +describe('Editor', function() { |
| 14 | + before(utils.launchBrowser); |
| 15 | + |
| 16 | + after(utils.closeBrowser); |
| 17 | + |
| 18 | + it('Displays editor when clicking on navbar', async function() { |
| 19 | + await this.page.click('a[href="#debugger-io"]'); |
| 20 | + // Wait for scroll |
| 21 | + await this.page.waitFor(3000); |
| 22 | + expect(await this.page.$eval('#debugger-io', isVisible)).to.be.true; |
| 23 | + }); |
| 24 | + |
| 25 | + it('HS256 should be selected by default', async function() { |
| 26 | + const selected = await this.page.$eval('#algorithm-select', select => { |
| 27 | + return select.options[select.selectedIndex].value; |
| 28 | + }); |
| 29 | + |
| 30 | + expect(selected).to.equal('HS256'); |
| 31 | + }); |
| 32 | + |
| 33 | + it('Should display a tooltip with a human readable ' + |
| 34 | + 'date on claim hover', async function() { |
| 35 | + await this.page.mouse.move(0, 0); |
| 36 | + |
| 37 | + expect(await this.page.$eval('#js-payload-tooltip', isVisible)).to.be.false; |
| 38 | + |
| 39 | + const iatPos = await this.page.evaluate(() => { |
| 40 | + return window.test.payloadEditor.charCoords({ |
| 41 | + line: 4, |
| 42 | + pos: 3 |
| 43 | + }, 'window'); |
| 44 | + }); |
| 45 | + |
| 46 | + await this.page.mouse.move(iatPos.left, iatPos.top); |
| 47 | + |
| 48 | + expect(await this.page.$eval('#js-payload-tooltip', isVisible)).to.be.true; |
| 49 | + }); |
| 50 | + |
| 51 | + it('Displays a valid token by default', async function() { |
| 52 | + const valid = await this.page.$eval('.validation-status', status => { |
| 53 | + return status.classList.contains('valid-token') && |
| 54 | + status.textContent.indexOf('verified') !== -1; |
| 55 | + }); |
| 56 | + |
| 57 | + expect(valid).to.be.true; |
| 58 | + }); |
| 59 | + |
| 60 | + it('Shows invalid token when a valid token is edited ' + |
| 61 | + 'in the left pane', async function() { |
| 62 | + await this.page.evaluate(() => { |
| 63 | + let token = window.test.tokenEditor.getValue(); |
| 64 | + token += 'asdf23'; |
| 65 | + window.test.tokenEditor.setValue(token); |
| 66 | + }); |
| 67 | + |
| 68 | + const invalid = await this.page.$eval('.validation-status', status => { |
| 69 | + return status.classList.contains('invalid-token') && |
| 70 | + status.textContent.indexOf('invalid') !== -1; |
| 71 | + }); |
| 72 | + |
| 73 | + expect(invalid).to.be.true; |
| 74 | + }); |
| 75 | + |
| 76 | + it('Updates the token when the secret changes', async function() { |
| 77 | + const oldToken = await this.page.evaluate(() => { |
| 78 | + return window.test.tokenEditor.getValue() |
| 79 | + }); |
| 80 | + |
| 81 | + const secretInput = await this.page.$('input[name="secret"]'); |
| 82 | + |
| 83 | + await secretInput.type('asdfasdf'); |
| 84 | + |
| 85 | + const newToken = await this.page.evaluate(() => { |
| 86 | + return window.test.tokenEditor.getValue() |
| 87 | + }); |
| 88 | + |
| 89 | + expect(oldToken).to.not.equal(newToken); |
| 90 | + }); |
| 91 | + |
| 92 | + it('Updates the token when the Base64 checkbox changes', async function() { |
| 93 | + const oldToken = await this.page.evaluate(() => { |
| 94 | + return window.test.tokenEditor.getValue() |
| 95 | + }); |
| 96 | + |
| 97 | + await this.page.click('#is-base64-encoded'); |
| 98 | + |
| 99 | + let newToken = await this.page.evaluate(() => { |
| 100 | + return window.test.tokenEditor.getValue() |
| 101 | + }); |
| 102 | + |
| 103 | + expect(oldToken).to.not.equal(newToken); |
| 104 | + |
| 105 | + await this.page.click('#is-base64-encoded'); |
| 106 | + |
| 107 | + newToken = await this.page.evaluate(() => { |
| 108 | + return window.test.tokenEditor.getValue() |
| 109 | + }); |
| 110 | + |
| 111 | + expect(oldToken).to.equal(newToken); |
| 112 | + }); |
| 113 | +}); |
0 commit comments