|
| 1 | +import * as path from 'path'; |
| 2 | +import * as Util from '../src/helpers/util.js'; |
| 3 | + |
| 4 | +const ONE_MINUTE = 5000 * 12; |
| 5 | +jest.setTimeout(ONE_MINUTE * 2); |
| 6 | + |
| 7 | +const TEST_WAIT_TIME = Util.WAIT_TIME + 100; |
| 8 | +const TEST_PAGE = path.join(__dirname, '..', 'public', 'jns-test.html'); |
| 9 | + |
| 10 | +async function assertWarnings(expected, options) { |
| 11 | + if (expected > 0) { |
| 12 | + await page.waitForSelector('.jns-highlight', options); |
| 13 | + } |
| 14 | + const numWarnings = await page.$$('.jns-highlight'); |
| 15 | + //longer phrases can wrap lines and create multiple tooltips |
| 16 | + await expect(numWarnings.length).toBeGreaterThanOrEqual(expected); |
| 17 | +} |
| 18 | + |
| 19 | +describe('Just Not Sorry', () => { |
| 20 | + beforeEach(async () => { |
| 21 | + await page.goto(`file://${TEST_PAGE}`); |
| 22 | + await page.waitForTimeout(500); |
| 23 | + await page.click('#email'); |
| 24 | + await assertWarnings(0, { visible: false, timeout: TEST_WAIT_TIME }); |
| 25 | + }); |
| 26 | + |
| 27 | + it('should work', async () => { |
| 28 | + await page.keyboard.type(`just not sorry.`); |
| 29 | + await page.keyboard.press('Enter'); |
| 30 | + await page.keyboard.press('Enter'); |
| 31 | + |
| 32 | + //blur |
| 33 | + await page.keyboard.down('Shift'); |
| 34 | + await page.keyboard.press('Tab'); |
| 35 | + await page.keyboard.up('Shift'); |
| 36 | + await assertWarnings(2, { visible: false, timeout: TEST_WAIT_TIME }); |
| 37 | + |
| 38 | + //focus |
| 39 | + await page.keyboard.press('Tab'); |
| 40 | + await assertWarnings(2, { visible: true, timeout: TEST_WAIT_TIME }); |
| 41 | + }); |
| 42 | + |
| 43 | + it('should display 500 words with 200 warnings', async () => { |
| 44 | + const fiftyWords = `Just actually sorry. Apologize. I think I'm no expert. Yes, um, literally, very, sort of, If that's okay, um, I should feel, we believe, in my opinion, This might be a silly idea. This might be a stupid question. I may be wrong. If I'm being honest. I guess. Maybe!!!`; |
| 45 | + expect(fiftyWords.split(' ').length).toBe(50); |
| 46 | + |
| 47 | + for (let i = 0; i < 500 / 50; i++) { |
| 48 | + await page.keyboard.type(fiftyWords); |
| 49 | + await page.keyboard.press('Enter'); |
| 50 | + await page.keyboard.press('Enter'); |
| 51 | + |
| 52 | + //blur |
| 53 | + await page.keyboard.down('Shift'); |
| 54 | + await page.keyboard.press('Tab', { delay: 500 }); |
| 55 | + await page.keyboard.up('Shift'); |
| 56 | + const numExpected = 20 * (i + 1); |
| 57 | + await assertWarnings(numExpected, { |
| 58 | + visible: false, |
| 59 | + timeout: TEST_WAIT_TIME, |
| 60 | + }); |
| 61 | + |
| 62 | + //focus |
| 63 | + await page.keyboard.press('Tab', { delay: 500 }); |
| 64 | + await assertWarnings(numExpected, { |
| 65 | + visible: true, |
| 66 | + timeout: TEST_WAIT_TIME, |
| 67 | + }); |
| 68 | + } |
| 69 | + }); |
| 70 | + |
| 71 | + it('should display 1000 words with 400 warnings with blur', async () => { |
| 72 | + const fiftyWords = `Just actually sorry. Apologize. I think I'm no expert. Yes, um, literally, very, sort of, If that's okay, um, I should feel, we believe, in my opinion, This might be a silly idea. This might be a stupid question. I may be wrong. If I'm being honest. I guess. Maybe!!!`; |
| 73 | + expect(fiftyWords.split(' ').length).toBe(50); |
| 74 | + |
| 75 | + for (let i = 0; i < 1000 / 50; i++) { |
| 76 | + await page.keyboard.type(fiftyWords); |
| 77 | + await page.keyboard.press('Enter'); |
| 78 | + await page.keyboard.press('Enter'); |
| 79 | + |
| 80 | + //blur |
| 81 | + await page.keyboard.down('Shift'); |
| 82 | + await page.keyboard.press('Tab', { delay: 500 }); |
| 83 | + await page.keyboard.up('Shift'); |
| 84 | + const numExpected = 20 * (i + 1); |
| 85 | + await assertWarnings(numExpected, { |
| 86 | + visible: false, |
| 87 | + timeout: TEST_WAIT_TIME, |
| 88 | + }); |
| 89 | + |
| 90 | + //focus |
| 91 | + await page.keyboard.press('Tab', { delay: 500 }); |
| 92 | + await assertWarnings(numExpected, { |
| 93 | + visible: true, |
| 94 | + timeout: TEST_WAIT_TIME, |
| 95 | + }); |
| 96 | + } |
| 97 | + }); |
| 98 | + |
| 99 | + it('should display 1000 words with 400 warnings with delay', async () => { |
| 100 | + const fiftyWords = `Just actually sorry. Apologize. I think I'm no expert. Yes, um, literally, very, sort of, If that's okay, um, I should feel, we believe, in my opinion, This might be a silly idea. This might be a stupid question. I may be wrong. If I'm being honest. I guess. Maybe!!!`; |
| 101 | + expect(fiftyWords.split(' ').length).toBe(50); |
| 102 | + |
| 103 | + for (let i = 0; i < 1000 / 50; i++) { |
| 104 | + await page.keyboard.type(fiftyWords); |
| 105 | + await page.keyboard.press('Enter'); |
| 106 | + await page.keyboard.press('Enter'); |
| 107 | + |
| 108 | + await page.waitForTimeout(500); |
| 109 | + await assertWarnings(20 * (i + 1), { |
| 110 | + visible: true, |
| 111 | + timeout: TEST_WAIT_TIME, |
| 112 | + }); |
| 113 | + } |
| 114 | + }); |
| 115 | +}); |
0 commit comments