From b551e4821a7bd284a4cbee12d63fd9d7ce0a1426 Mon Sep 17 00:00:00 2001 From: Jordan GAZEAU Date: Mon, 2 Jan 2023 19:43:19 +0100 Subject: [PATCH] fix: tests --- cypress/e2e/global/contentTests.cy.js | 2 +- cypress/e2e/global/mermaidTests.cy.js | 8 ++--- cypress/e2e/global/multilingualTests.cy.js | 8 ++--- cypress/e2e/global/navbarTests.cy.js | 2 +- cypress/e2e/global/searchTests.cy.js | 16 +++++----- cypress/e2e/global/shortcutsTests.cy.js | 32 +++++++++---------- cypress/e2e/global/sidebarTests.cy.js | 8 ++--- cypress/e2e/shortcodes/asyncapiTests.cy.js | 2 +- cypress/e2e/shortcodes/collapsibleTests.cy.js | 2 +- cypress/e2e/shortcodes/highchartsTests.cy.js | 2 +- cypress/e2e/shortcodes/introTests.cy.js | 4 +-- cypress/e2e/shortcodes/openapiTests.cy.js | 8 ++--- cypress/e2e/shortcodes/treeviewTests.cy.js | 20 ++++++------ cypress/support/e2e.js | 4 +-- cypress/support/globalCommands.js | 6 ++-- 15 files changed, 62 insertions(+), 62 deletions(-) diff --git a/cypress/e2e/global/contentTests.cy.js b/cypress/e2e/global/contentTests.cy.js index a339289d..ca8115a2 100644 --- a/cypress/e2e/global/contentTests.cy.js +++ b/cypress/e2e/global/contentTests.cy.js @@ -18,7 +18,7 @@ describe('for: content', () => { cy.get($title[0]) .children('a[href="#' + encodeURI($title[0].id).toLowerCase() + '"]') .should('have.class', 'anchor') - .click({force:true}) + .click({ force: true }) cy.location('href') .should('eq', Cypress.env('HOMEPAGE_URL') + Cypress.env('FUNC_TOC_PATH') + '#' + encodeURI($title[0].id).toLowerCase()) }) diff --git a/cypress/e2e/global/mermaidTests.cy.js b/cypress/e2e/global/mermaidTests.cy.js index 3d3a8d95..b6f85224 100644 --- a/cypress/e2e/global/mermaidTests.cy.js +++ b/cypress/e2e/global/mermaidTests.cy.js @@ -40,15 +40,15 @@ describe('for: mermaid', () => { let elId = $elem[0].id; cy.get('#' + elId + '-svg') .scrollIntoView() - .click({force:true}) + .click({ force: true }) cy.get('#modalContainer #modal #' + elId + '-svg') .should('be.visible') }) }) - // For now local download is not fully supported in firefox browser. + // For now local download is not fully supported in firefox browser. // Cypress doesn't seems to accept browser preferences in headless mode. // https://github.com/cypress-io/cypress/issues/8814 - it('export button should export mermaid', {browser:'!firefox'}, () => { + it('export button should export mermaid', { browser: '!firefox' }, () => { const path = require('path'); cy.get('#content .sc-mermaid-wrapper.helper-loading-container') .each(($elem) => { @@ -58,7 +58,7 @@ describe('for: mermaid', () => { $svg[0].removeAttribute('class'); cy.get('#' + elId + '-export-svg') .scrollIntoView() - .click({force:true}) + .click({ force: true }) cy.readFile(path.join(Cypress.config('downloadsFolder'), elId + '.svg')) .should('be.equal', $svg[0].outerHTML) }) diff --git a/cypress/e2e/global/multilingualTests.cy.js b/cypress/e2e/global/multilingualTests.cy.js index c976d2ab..f2a7af15 100644 --- a/cypress/e2e/global/multilingualTests.cy.js +++ b/cypress/e2e/global/multilingualTests.cy.js @@ -7,7 +7,7 @@ describe('for: multilingual', () => { .its('body') .then((sitemapindex) => { const parser = new DOMParser(); - const xmlSitemapindex = parser.parseFromString(sitemapindex,"text/xml"); + const xmlSitemapindex = parser.parseFromString(sitemapindex, "text/xml"); expect(xmlSitemapindex.getElementsByTagName('sitemap')).to.have.length(2) }) }) @@ -16,15 +16,15 @@ describe('for: multilingual', () => { .its('body') .then((sitemapindex) => { const parser = new DOMParser(); - const sitemaps = parser.parseFromString(sitemapindex,"text/xml").getElementsByTagName('sitemap'); + const sitemaps = parser.parseFromString(sitemapindex, "text/xml").getElementsByTagName('sitemap'); cy.request(sitemaps[0].getElementsByTagName('loc')[0].childNodes[0].nodeValue) .its('body') - .then((urlset) => parser.parseFromString(urlset,"text/xml").getElementsByTagName('url').length) + .then((urlset) => parser.parseFromString(urlset, "text/xml").getElementsByTagName('url').length) .then((urlCount) => { for (let sitemap of sitemaps) { cy.request(sitemap.getElementsByTagName('loc')[0].childNodes[0].nodeValue) .its('body') - .then((urlset) => parser.parseFromString(urlset,"text/xml").getElementsByTagName('url')) + .then((urlset) => parser.parseFromString(urlset, "text/xml").getElementsByTagName('url')) .should((urlset) => { expect(urlset.length).to.equal(urlCount) }) diff --git a/cypress/e2e/global/navbarTests.cy.js b/cypress/e2e/global/navbarTests.cy.js index e2d34786..66193278 100644 --- a/cypress/e2e/global/navbarTests.cy.js +++ b/cypress/e2e/global/navbarTests.cy.js @@ -1,4 +1,4 @@ -const testCases = ['default','mobile'] +const testCases = ['default', 'mobile'] for (const testCase of testCases) { describe('for: navbar' + ' on ' + testCase, () => { const extendId = (testCase == 'mobile') ? 'Extend' : ''; diff --git a/cypress/e2e/global/searchTests.cy.js b/cypress/e2e/global/searchTests.cy.js index f60cc3c0..b47deab9 100644 --- a/cypress/e2e/global/searchTests.cy.js +++ b/cypress/e2e/global/searchTests.cy.js @@ -12,12 +12,12 @@ describe('for: search', () => { }) it('search should not modify user input', () => { cy.get('#search') - .type(Cypress.env('SEARCH_TEST_INPUT'), {delay:0}) + .type(Cypress.env('SEARCH_TEST_INPUT'), { delay: 0 }) .should('have.value', Cypress.env('SEARCH_TEST_INPUT')) }) it('search should display elements', () => { cy.get('#search') - .type(Cypress.env('SEARCH_TEST_INPUT'), {delay:0}) + .type(Cypress.env('SEARCH_TEST_INPUT'), { delay: 0 }) cy.get('#searchList') .children() .should('be.visible') @@ -25,7 +25,7 @@ describe('for: search', () => { }) it('search should display elements when focused', () => { cy.get('#search') - .type(Cypress.env('SEARCH_TEST_INPUT'), {delay:0}) + .type(Cypress.env('SEARCH_TEST_INPUT'), { delay: 0 }) cy.window() .trigger('blur') cy.get('#search') @@ -36,34 +36,34 @@ describe('for: search', () => { }) it('search should empty', () => { cy.get('#search') - .type('xxx', {delay:0}) + .type('xxx', { delay: 0 }) .clear() .should('have.value', '') }) it('search should display one element when no results', () => { cy.get('#search') - .type(Cypress.env('NULL_STRING'), {delay:0}) + .type(Cypress.env('NULL_STRING'), { delay: 0 }) cy.get('#searchList') .children() .should('have.length', 1) }) it('search should not display elements when search for 1 char', () => { cy.get('#search') - .type('x', {delay:0}) + .type('x', { delay: 0 }) cy.get('#searchList') .children() .should('have.length', 0) }) it('search should display elements when search for 2 char', () => { cy.get('#search') - .type('xx', {delay:0}) + .type('xx', { delay: 0 }) cy.get('#searchList') .children() .should('have.length.greaterThan', 0) }) it('search should not display elements after resize', () => { cy.get('#search') - .type(Cypress.env('SEARCH_TEST_INPUT'), {delay:0}) + .type(Cypress.env('SEARCH_TEST_INPUT'), { delay: 0 }) cy.viewportMobile() cy.get('#searchList') .children() diff --git a/cypress/e2e/global/shortcutsTests.cy.js b/cypress/e2e/global/shortcutsTests.cy.js index d1f44865..49ab5796 100644 --- a/cypress/e2e/global/shortcutsTests.cy.js +++ b/cypress/e2e/global/shortcutsTests.cy.js @@ -5,19 +5,19 @@ describe('for: shortcuts', () => { it('[shift+i] should open website information panel', () => { cy.window().its('scShowInfo') cy.get('body') - .type('{shift+i}', {delay:0}) + .type('{shift+i}', { delay: 0 }) cy.scShowInfoResults() }) it('[shift+k] should open shortcuts panel', () => { cy.window().its('scShowShortcuts') cy.get('body') - .type('{shift+k}', {delay:0}) + .type('{shift+k}', { delay: 0 }) cy.scShowShortcutsResults() }) it('[shift+h] should redirect to homepage', () => { cy.window().its('scGoHome') cy.get('body') - .type('{shift+h}', {delay:0}) + .type('{shift+h}', { delay: 0 }) cy.location() .should((loc) => { expect(loc.toString()).to.eq(Cypress.env('HOMEPAGE_URL')) @@ -26,7 +26,7 @@ describe('for: shortcuts', () => { it('[shift+f] should focus on search', () => { cy.window().its('scGoSearch') cy.get('body') - .type('{shift+f}', {delay:0}) + .type('{shift+f}', { delay: 0 }) cy.get('#search') .should('be.focused') }) @@ -35,7 +35,7 @@ describe('for: shortcuts', () => { .wait(Cypress.env('WAIT_FOR_ANIMATION')) cy.toggleSidebar(true, true) cy.get('body') - .type('{shift+m}', {delay:0}) + .type('{shift+m}', { delay: 0 }) cy.get('#sidebarContainer') .should('have.class', 'is-sidebar-collapsed') }) @@ -44,7 +44,7 @@ describe('for: shortcuts', () => { .wait(Cypress.env('WAIT_FOR_ANIMATION')) cy.toggleSidebar(false, true) cy.get('body') - .type('{shift+m}', {delay:0}) + .type('{shift+m}', { delay: 0 }) cy.get('#sidebarContainer') .should('have.class', 'is-sidebar-uncollapsed') }) @@ -53,7 +53,7 @@ describe('for: shortcuts', () => { .wait(Cypress.env('WAIT_FOR_ANIMATION')) cy.toggleToc(true) cy.get('body') - .type('{shift+t}', {delay:0}) + .type('{shift+t}', { delay: 0 }) cy.get('#contentContainer') .should('have.class', 'is-toc-collapsed') }) @@ -62,7 +62,7 @@ describe('for: shortcuts', () => { .wait(Cypress.env('WAIT_FOR_ANIMATION')) cy.toggleToc(false) cy.get('body') - .type('{shift+t}', {delay:0}) + .type('{shift+t}', { delay: 0 }) cy.get('#contentContainer') .should('have.class', 'is-toc-uncollapsed') }) @@ -72,7 +72,7 @@ describe('for: shortcuts', () => { cy.get('#contentContainer') .scrollTo('bottom') cy.get('body') - .type('{shift+uparrow}', {delay:0}) + .type('{shift+uparrow}', { delay: 0 }) cy.get('#contentContainer') .should('have.prop', 'scrollTop', 0) }) @@ -82,18 +82,18 @@ describe('for: shortcuts', () => { cy.get('#contentContainer') .scrollTo('top') cy.get('body') - .type('{shift+downarrow}', {delay:0}) + .type('{shift+downarrow}', { delay: 0 }) cy.get('#contentContainer').then(($elem) => { - let calcScrollHeight = $elem[0].clientHeight + $elem[0].scrollTop; - let elScrollHeight = $elem[0].scrollHeight; - expect(elScrollHeight).to.equal(calcScrollHeight); - }) + let calcScrollHeight = $elem[0].clientHeight + $elem[0].scrollTop; + let elScrollHeight = $elem[0].scrollHeight; + expect(elScrollHeight).to.equal(calcScrollHeight); + }) }) it('[shift+p] should open print preview', () => { cy.window().its('scPrint') cy.scPrintStub() cy.get('body') - .type('{shift+p}', {delay:0}) + .type('{shift+p}', { delay: 0 }) cy.scPrintResults() }) it('[escape] should close modal', () => { @@ -107,7 +107,7 @@ describe('for: shortcuts', () => { it('[shift+q] should open QR code panel', () => { cy.window().its('scQrCode') cy.get('body') - .type('{shift+q}', {delay:0}) + .type('{shift+q}', { delay: 0 }) cy.scQrCodeResults() }) it('[shift+1] should open the example panel', () => { diff --git a/cypress/e2e/global/sidebarTests.cy.js b/cypress/e2e/global/sidebarTests.cy.js index afe2424f..7188b872 100644 --- a/cypress/e2e/global/sidebarTests.cy.js +++ b/cypress/e2e/global/sidebarTests.cy.js @@ -1,8 +1,8 @@ describe('for: sidebar', () => { + beforeEach(() => { + cy.visit(Cypress.env('HOMEPAGE_URL')) + }) describe('when onload', () => { - beforeEach(() => { - cy.visit(Cypress.env('HOMEPAGE_URL')) - }) it('sidebar should be uncollapsed by default on desktop', () => { cy.viewportDesktop('min') cy.get('#sidebarContainer') @@ -44,7 +44,7 @@ describe('for: sidebar', () => { .click() cy.get('#sidebarContainer') .should('have.class', 'is-sidebar-collapsed') - }) + }) it('expandable entries should expand', () => { cy.toggleSidebarEntries(false) cy.get('.is-icon-expandable') diff --git a/cypress/e2e/shortcodes/asyncapiTests.cy.js b/cypress/e2e/shortcodes/asyncapiTests.cy.js index fe6639c2..34f1442a 100644 --- a/cypress/e2e/shortcodes/asyncapiTests.cy.js +++ b/cypress/e2e/shortcodes/asyncapiTests.cy.js @@ -10,7 +10,7 @@ describe('for: asyncapi shortcode', () => { cy.get('#content .sc-asyncapi-wrapper') .should('have.class', 'helper-loading-container') }) - it('asyncapi should not have a loading helper once loaded', {defaultCommandTimeout: 10000}, () => { + it('asyncapi should not have a loading helper once loaded', { defaultCommandTimeout: 10000 }, () => { cy.get('#content .sc-asyncapi-wrapper.helper-loading-container') .should('not.have.class', 'is-loading') }) diff --git a/cypress/e2e/shortcodes/collapsibleTests.cy.js b/cypress/e2e/shortcodes/collapsibleTests.cy.js index 687f574b..60d76ec2 100644 --- a/cypress/e2e/shortcodes/collapsibleTests.cy.js +++ b/cypress/e2e/shortcodes/collapsibleTests.cy.js @@ -32,7 +32,7 @@ describe('for: collapsible shortcode', () => { .scrollIntoView() .children('.sc-collapsible-header') .wait(Cypress.env('WAIT_FOR_ANIMATION')) - .click({force:true}) + .click({ force: true }) .should('have.class', 'sc-uncollapsed') cy.get($elem) .children('.sc-collapsible-content') diff --git a/cypress/e2e/shortcodes/highchartsTests.cy.js b/cypress/e2e/shortcodes/highchartsTests.cy.js index 7ec42304..ac3e17cc 100644 --- a/cypress/e2e/shortcodes/highchartsTests.cy.js +++ b/cypress/e2e/shortcodes/highchartsTests.cy.js @@ -13,7 +13,7 @@ describe('for: highcharts shortcode', () => { cy.get('#content .sc-highcharts-wrapper') .should('have.class', 'helper-loading-container') }) - it('highcharts should not have a loading helper once loaded', {defaultCommandTimeout: 10000}, () => { + it('highcharts should not have a loading helper once loaded', { defaultCommandTimeout: 30000 }, () => { cy.get('#content .sc-highcharts-wrapper.helper-loading-container') .should('not.have.class', 'is-loading') }) diff --git a/cypress/e2e/shortcodes/introTests.cy.js b/cypress/e2e/shortcodes/introTests.cy.js index 0e568e83..eda452ad 100644 --- a/cypress/e2e/shortcodes/introTests.cy.js +++ b/cypress/e2e/shortcodes/introTests.cy.js @@ -38,7 +38,7 @@ describe('for: intro shortcode', () => { .each(($elem) => { cy.scrollAndClickElem($elem) cy.get('.introjs-overlay') - .click({force:true}) + .click({ force: true }) cy.get('.introjs-tooltipReferenceLayer .introjs-tooltip') .should('not.exist') }) @@ -48,7 +48,7 @@ describe('for: intro shortcode', () => { .each(($elem) => { cy.scrollAndClickElem($elem) cy.get('.introjs-tooltipReferenceLayer .introjs-tooltip .introjs-skipbutton') - .click({force:true}) + .click({ force: true }) cy.get('.introjs-tooltipReferenceLayer .introjs-tooltip') .should('not.exist') }) diff --git a/cypress/e2e/shortcodes/openapiTests.cy.js b/cypress/e2e/shortcodes/openapiTests.cy.js index 5cebe279..58e21883 100644 --- a/cypress/e2e/shortcodes/openapiTests.cy.js +++ b/cypress/e2e/shortcodes/openapiTests.cy.js @@ -10,25 +10,25 @@ describe('for: openapi shortcode', () => { cy.get('#content .sc-openapi-wrapper') .should('have.class', 'helper-loading-container') }) - it('openapi should not have a loading helper once loaded', {defaultCommandTimeout: 10000}, () => { + it('openapi should not have a loading helper once loaded', { defaultCommandTimeout: 10000 }, () => { cy.get('#content .sc-openapi-wrapper.helper-loading-container') .should('not.have.class', 'is-loading') }) // For now local download is not fully supported in firefox browser. // Cypress doesn't seems to accept browser preferences in headless mode. // https://github.com/cypress-io/cypress/issues/8814 - it('export link should export openapi', {browser:'!firefox', defaultCommandTimeout: 10000}, () => { + it('export link should export openapi', { browser: '!firefox', defaultCommandTimeout: 10000 }, () => { const path = require('path'); cy.get('.sc-openapi-iframe').first() .its('0.contentDocument') .its('body') .find('.information-container .link').first() - .click({force:true}) + .click({ force: true }) .then(($openapiLink) => { const fileName = $openapiLink[0].href.substring($openapiLink[0].href.lastIndexOf('/') + 1) cy.readFile(path.join(Cypress.config('downloadsFolder'), fileName)).then((fileContent) => { cy.fixture('openapi/example.yaml', 'utf8').should('be.equal', fileContent) }) - }) + }) }) }) \ No newline at end of file diff --git a/cypress/e2e/shortcodes/treeviewTests.cy.js b/cypress/e2e/shortcodes/treeviewTests.cy.js index 1428a571..74f63718 100644 --- a/cypress/e2e/shortcodes/treeviewTests.cy.js +++ b/cypress/e2e/shortcodes/treeviewTests.cy.js @@ -32,18 +32,18 @@ describe('for: treeview shortcode', () => { }) it('uncollapsed treeview colls should collapse', () => { cy.get('#content .sc-treeview > .sc-treeview-tree > .sc-treeview-coll:not(.is-collapsed) .sc-treeview-coll-trigger') - .as('triggers') - .click({multiple:true,force:true}) - cy.get('@triggers') - .closest('.sc-treeview-coll') - .should('have.class', 'is-collapsed') + .each(($elem) => { + cy.scrollAndClickElem($elem) + .closest('.sc-treeview-coll') + .should('have.class', 'is-collapsed') + }) }) it('collapsed treeview colls should uncollapse', () => { cy.get('#content .sc-treeview > .sc-treeview-tree > .sc-treeview-coll.is-collapsed .sc-treeview-coll-trigger') - .as('triggers') - .click({multiple:true,force:true}) - cy.get('@triggers') - .closest('.sc-treeview-coll') - .should('not.have.class', 'is-collapsed') + .each(($elem) => { + cy.scrollAndClickElem($elem) + .closest('.sc-treeview-coll') + .should('not.have.class', 'is-collapsed') + }) }) }) \ No newline at end of file diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js index 7cae242d..4b9e49e9 100644 --- a/cypress/support/e2e.js +++ b/cypress/support/e2e.js @@ -1,7 +1,7 @@ // *********************************************************** // https://on.cypress.io/configuration // *********************************************************** -import './globalCommands' -import './global/navbarCommands' +import './global/navbarCommands'; +import './globalCommands'; // See: https://github.com/cypress-io/cypress/issues/20341 Cypress.on("uncaught:exception", err => !err.message.includes("ResizeObserver")); diff --git a/cypress/support/globalCommands.js b/cypress/support/globalCommands.js index a67acbc6..39fd8254 100644 --- a/cypress/support/globalCommands.js +++ b/cypress/support/globalCommands.js @@ -44,10 +44,10 @@ Cypress.Commands.add('disableSmoothScroll', () => { Cypress.Commands.add('scrollAndClickElem', ($elem) => { cy.get($elem) .scrollIntoView() - .click({force:true}) + .click({ force: true }) }) -Cypress.Commands.add('scrollAndClick', {prevSubject:true}, ($elem) => { +Cypress.Commands.add('scrollAndClick', { prevSubject: true }, ($elem) => { cy.wrap($elem) .scrollIntoView() - .click({force:true}) + .click({ force: true }) }) \ No newline at end of file