Changeset View
Changeset View
Standalone View
Standalone View
cypress/integration/language-select.spec.js
/** | /** | ||||
* Copyright (C) 2019 The Software Heritage developers | * Copyright (C) 2019 The Software Heritage developers | ||||
* See the AUTHORS file at the top-level directory of this distribution | * See the AUTHORS file at the top-level directory of this distribution | ||||
* License: GNU Affero General Public License version 3, or any later version | * License: GNU Affero General Public License version 3, or any later version | ||||
* See top-level LICENSE file for more information | * See top-level LICENSE file for more information | ||||
*/ | */ | ||||
import {random, checkLanguageHighlighting} from '../utils'; | import {random, checkLanguageHighlighting} from '../utils'; | ||||
const origin = { | const $ = Cypress.$; | ||||
url: 'https://github.com/memononen/libtess2', | |||||
content: { | |||||
path: 'premake4.lua' | |||||
} | |||||
}; | |||||
let contentWithLanguageInfo, contentWithoutLanguageInfo; | |||||
let languages = []; | let origin; | ||||
const $ = Cypress.$; | let contentWithLanguageInfo, contentWithoutLanguageInfo; | ||||
const languageSelect = 'python'; | |||||
describe('Test Content Language Select', function() { | describe('Test Content Language Select', function() { | ||||
before(function() { | before(function() { | ||||
contentWithLanguageInfo = this.Urls.browse_origin_content(origin.url, origin.content.path); | origin = this.origin[0]; | ||||
contentWithLanguageInfo = this.Urls.browse_origin_content(origin.url, origin.content[1].path); | |||||
cy.visit(contentWithLanguageInfo); | contentWithoutLanguageInfo = this.Urls.browse_content(`sha1_git:${origin.content[1].sha1git}`); | ||||
cy.window().then(win => { | |||||
const metadata = win.swh.webapp.getBrowsedSwhObjectMetadata(); | |||||
origin.content.name = metadata.filename; | |||||
origin.content.sha1git = metadata.sha1_git; | |||||
contentWithoutLanguageInfo = this.Urls.browse_content(`sha1_git:${origin.content.sha1git}`); | |||||
$('.language-select option').each(function() { | |||||
languages.push(this.value); | |||||
}); | |||||
}); | |||||
}); | }); | ||||
context('When Language is detected', function() { | context('When Language is detected', function() { | ||||
it('should display correct language in dropdown', function() { | it('should display correct language in dropdown', function() { | ||||
cy.visit(contentWithLanguageInfo) | cy.visit(contentWithLanguageInfo) | ||||
.then(() => { | .then(() => { | ||||
cy.get(`code.${$('.language-select').val()}`) | cy.get(`code.${$('.language-select').val()}`) | ||||
.should('exist'); | .should('exist'); | ||||
}); | }); | ||||
}); | }); | ||||
}); | }); | ||||
context('When Language is not detected', function() { | context('When Language is not detected', function() { | ||||
it('should have no selected language in dropdown', function() { | it('should have no selected language in dropdown', function() { | ||||
cy.visit(contentWithoutLanguageInfo).then(() => { | cy.visit(contentWithoutLanguageInfo).then(() => { | ||||
assert.strictEqual($('.language-select').val(), null); | assert.strictEqual($('.language-select').val(), null); | ||||
}); | }); | ||||
}); | }); | ||||
}); | }); | ||||
context('When language is switched from dropdown', function() { | context('When language is switched from dropdown', function() { | ||||
before(function() { | before(function() { | ||||
cy.visit(contentWithLanguageInfo); | cy.visit(contentWithLanguageInfo); | ||||
let languageSelect = languages[random(0, languages.length)]; | |||||
cy.get('.chosen-container') | cy.get('.chosen-container') | ||||
.click() | .click() | ||||
.get('.chosen-results > li') | .get('.chosen-results > li') | ||||
.contains(languageSelect) | .its('length') | ||||
.click() | .then(numOptions => { | ||||
.then(() => { | const languageIndex = random(0, numOptions); | ||||
assert.strictEqual($('.language-select').val(), languageSelect); | cy.get('.chosen-results > li') | ||||
.eq(languageIndex) | |||||
.click(); | |||||
}); | }); | ||||
}); | }); | ||||
it('should contain argument with language in url', function() { | it('should contain argument with language in url', function() { | ||||
cy.location('search') | cy.location('search') | ||||
.should('contain', `language=${$('.language-select').val()}`); | .should('contain', `language=${$('.language-select').val()}`); | ||||
}); | }); | ||||
it('should highlight according to new language', function() { | it('should highlight according to new language', function() { | ||||
checkLanguageHighlighting($('.language-select').val()); | checkLanguageHighlighting($('.language-select').val()); | ||||
}); | }); | ||||
}); | }); | ||||
it('should highlight according to the language passed as argument in url', function() { | it('should highlight according to the language passed as argument in url', function() { | ||||
const languageSelect = languages[random(0, languages.length)]; | |||||
cy.visit(`${contentWithLanguageInfo}?language=${languageSelect}`); | cy.visit(`${contentWithLanguageInfo}?language=${languageSelect}`); | ||||
checkLanguageHighlighting(languageSelect); | checkLanguageHighlighting(languageSelect); | ||||
}); | }); | ||||
}); | }); |