Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jgazeau committed Jan 2, 2023
1 parent de6657a commit b551e48
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 62 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/global/contentTests.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
Expand Down
8 changes: 4 additions & 4 deletions cypress/e2e/global/mermaidTests.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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)
})
Expand Down
8 changes: 4 additions & 4 deletions cypress/e2e/global/multilingualTests.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
Expand All @@ -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)
})
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/global/navbarTests.cy.js
Original file line number Diff line number Diff line change
@@ -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' : '';
Expand Down
16 changes: 8 additions & 8 deletions cypress/e2e/global/searchTests.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ 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')
.should('have.length.greaterThan', 0)
})
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')
Expand All @@ -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()
Expand Down
32 changes: 16 additions & 16 deletions cypress/e2e/global/shortcutsTests.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand All @@ -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')
})
Expand All @@ -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')
})
Expand All @@ -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')
})
Expand All @@ -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')
})
Expand All @@ -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')
})
Expand All @@ -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)
})
Expand All @@ -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', () => {
Expand All @@ -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', () => {
Expand Down
8 changes: 4 additions & 4 deletions cypress/e2e/global/sidebarTests.cy.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/shortcodes/asyncapiTests.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/shortcodes/collapsibleTests.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/shortcodes/highchartsTests.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/shortcodes/introTests.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
Expand All @@ -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')
})
Expand Down
8 changes: 4 additions & 4 deletions cypress/e2e/shortcodes/openapiTests.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
})
})
})
20 changes: 10 additions & 10 deletions cypress/e2e/shortcodes/treeviewTests.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})
})
4 changes: 2 additions & 2 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -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"));
6 changes: 3 additions & 3 deletions cypress/support/globalCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
})

0 comments on commit b551e48

Please sign in to comment.