|
| 1 | +describe('widget', |
| 2 | + {baseUrl: Cypress.env('portfolioBaseUrl')}, |
| 3 | + () => { |
| 4 | + beforeEach(() => { |
| 5 | + // Stub the clipboard API to capture copied content |
| 6 | + cy.window().then((win) => { |
| 7 | + cy.stub(win.navigator.clipboard, 'writeText').as('clipboardWrite'); |
| 8 | + }); |
| 9 | + |
| 10 | + }); |
| 11 | + |
| 12 | + it('group link should open the correct group\'s widget', () => { |
| 13 | + cy.get('.summary-charts__title .fa-clipboard') |
| 14 | + .first() |
| 15 | + .click() |
| 16 | + |
| 17 | + // Verify clipboard content includes the iframe tag |
| 18 | + cy.get('@clipboardWrite').should('have.been.called'); |
| 19 | + |
| 20 | + // Verify clipboard content includes the iframe tag |
| 21 | + cy.get('@clipboardWrite').then((clipboardCall) => { |
| 22 | + const copiedText = clipboardCall.args[0][0]; |
| 23 | + expect(copiedText).to.include('<iframe'); |
| 24 | + expect(copiedText).to.include('src="'); |
| 25 | + |
| 26 | + // Extract and visit the iframe src |
| 27 | + const srcMatch = copiedText.match(/src="([^"]+)"/); |
| 28 | + expect(srcMatch).to.not.be.null; |
| 29 | + const iframeSrc = srcMatch[1]; |
| 30 | + cy.visit(iframeSrc); |
| 31 | + |
| 32 | + cy.get('.summary-charts__title--groupname') |
| 33 | + .should('have.length', 1) |
| 34 | + .contains('reposense/publish-RepoSense[master]'); |
| 35 | + |
| 36 | + cy.get('.summary-chart') |
| 37 | + .should('have.length', 1); |
| 38 | + }); |
| 39 | + }); |
| 40 | + |
| 41 | + it('user link should open the correct user\'s widget', () => { |
| 42 | + cy.get('.summary-charts') |
| 43 | + .eq(1) |
| 44 | + .find('.summary-chart__title .fa-clipboard') |
| 45 | + .first() |
| 46 | + .click() |
| 47 | + |
| 48 | + // Verify clipboard content includes the iframe tag |
| 49 | + cy.get('@clipboardWrite').should('have.been.calledOnce'); |
| 50 | + |
| 51 | + // Verify clipboard content includes the iframe tag |
| 52 | + cy.get('@clipboardWrite').then((clipboardCall) => { |
| 53 | + const copiedText = clipboardCall.args[0][0]; |
| 54 | + expect(copiedText).to.include('<iframe'); |
| 55 | + expect(copiedText).to.include('src="'); |
| 56 | + |
| 57 | + // Extract and visit the iframe src |
| 58 | + const srcMatch = copiedText.match(/src="([^"]+)"/); |
| 59 | + expect(srcMatch).to.not.be.null; |
| 60 | + const iframeSrc = srcMatch[1]; |
| 61 | + cy.visit(iframeSrc); |
| 62 | + |
| 63 | + cy.get('.summary-charts__title--groupname') |
| 64 | + .should('have.length', 1) |
| 65 | + .contains('reposense/repoSense-action[main]'); |
| 66 | + |
| 67 | + cy.get('.summary-chart') |
| 68 | + .should('have.length', 1); |
| 69 | + }); |
| 70 | + }); |
| 71 | + }, |
| 72 | +); |
0 commit comments