Skip to content

Commit

Permalink
Refactor SEO keywords test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
gflores-jahia committed Jan 9, 2025
1 parent d771412 commit 85bc8ec
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 72 deletions.
92 changes: 92 additions & 0 deletions tests/cypress/e2e/fields/seoKeywords.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { addNode, createSite, deleteSite, getNodeByPath } from '@jahia/cypress'
import { JContent } from '@jahia/jcontent-cypress/dist/page-object/jcontent'
import { Field } from '@jahia/jcontent-cypress/dist/page-object/fields/field'

describe('SEO keywords tests', () => {

Check failure on line 6 in tests/cypress/e2e/fields/seoKeywords.cy.ts

View workflow job for this annotation

GitHub Actions / Static Analysis (linting, vulns)

Delete `⏎`
const siteKey = 'seoKeywordsTest'
const pageName_addTest = 'pagetest_addTag'
const pageName_removeTest = 'pagetest_removeTag'
const searchTag = {en: 'test1en', fr: 'test1fr'}

Check failure on line 10 in tests/cypress/e2e/fields/seoKeywords.cy.ts

View workflow job for this annotation

GitHub Actions / Static Analysis (linting, vulns)

Replace `en:·'test1en',·fr:·'test1fr'` with `·en:·'test1en',·fr:·'test1fr'·`

const createPageWithSEOKeyword = (pageName: string) => {
return addNode({
parentPathOrId: `/sites/${siteKey}/home`,
name: pageName,
primaryNodeType: 'jnt:page',
mixins: ['jmix:seoHtmlHead'],
properties: [
{name: 'j:templateName', value: 'simple'},

Check failure on line 19 in tests/cypress/e2e/fields/seoKeywords.cy.ts

View workflow job for this annotation

GitHub Actions / Static Analysis (linting, vulns)

Replace `name:·'j:templateName',·value:·'simple'` with `·name:·'j:templateName',·value:·'simple'·`
{name: 'jcr:title', language: 'en', value: pageName},

Check failure on line 20 in tests/cypress/e2e/fields/seoKeywords.cy.ts

View workflow job for this annotation

GitHub Actions / Static Analysis (linting, vulns)

Replace `name:·'jcr:title',·language:·'en',·value:·pageName` with `·name:·'jcr:title',·language:·'en',·value:·pageName·`
{name: 'jcr:title', language: 'fr', value: pageName},

Check failure on line 21 in tests/cypress/e2e/fields/seoKeywords.cy.ts

View workflow job for this annotation

GitHub Actions / Static Analysis (linting, vulns)

Replace `name:·'jcr:title',·language:·'fr',·value:·pageName` with `·name:·'jcr:title',·language:·'fr',·value:·pageName·`
{name: 'seoKeywords', language: 'en', values: [searchTag.en, 'test2en']},

Check failure on line 22 in tests/cypress/e2e/fields/seoKeywords.cy.ts

View workflow job for this annotation

GitHub Actions / Static Analysis (linting, vulns)

Replace `name:·'seoKeywords',·language:·'en',·values:·[searchTag.en,·'test2en']` with `·name:·'seoKeywords',·language:·'en',·values:·[searchTag.en,·'test2en']·`
{name: 'seoKeywords', language: 'fr', values: [searchTag.fr, 'test2fr']}

Check failure on line 23 in tests/cypress/e2e/fields/seoKeywords.cy.ts

View workflow job for this annotation

GitHub Actions / Static Analysis (linting, vulns)

Replace `name:·'seoKeywords',·language:·'fr',·values:·[searchTag.fr,·'test2fr']}` with `·name:·'seoKeywords',·language:·'fr',·values:·[searchTag.fr,·'test2fr']·},`
]

Check failure on line 24 in tests/cypress/e2e/fields/seoKeywords.cy.ts

View workflow job for this annotation

GitHub Actions / Static Analysis (linting, vulns)

Insert `,`
})
}

before(function () {
createSite(siteKey, {templateSet: 'dx-base-demo-templates', serverName: 'localhost', locale: 'en,fr'})

Check failure on line 29 in tests/cypress/e2e/fields/seoKeywords.cy.ts

View workflow job for this annotation

GitHub Actions / Static Analysis (linting, vulns)

Replace `templateSet:·'dx-base-demo-templates',·serverName:·'localhost',·locale:·'en,fr'` with `·templateSet:·'dx-base-demo-templates',·serverName:·'localhost',·locale:·'en,fr'·`
createPageWithSEOKeyword(pageName_addTest)
createPageWithSEOKeyword(pageName_removeTest)
})

after(function () {
deleteSite(siteKey)
cy.logout()
})

beforeEach(function () {
cy.loginAndStoreSession()
})

it('should be able to search for seo keywords tag', function () {
const searchTagInLang = (lang) => {
cy.log(`Search for ${searchTag[lang]} in ${lang} site`)
cy.visit(`cms/render/default/${lang}/sites/${siteKey}/home/search-results.html`)
cy.get('.search-block input[type="text"]').type(`${searchTag[lang]}{enter}`)
cy.get('.s-results').contains(searchTag[lang]).should('be.visible')
}
searchTagInLang('en')
searchTagInLang('fr')
})

it('should be possible to edit SEO fields : adding a new value', function () {
const ce = JContent.visit(siteKey, 'en', `pages/home/${pageName_addTest}`).editPage()

ce.openSection('seo')

const tagField = ce.getField(Field, 'htmlHead_seoKeywords')
tagField.get().find('#htmlHead_seoKeywords').type('newtag{enter}', { delay: 500 })
tagField
.should('exist')
.and('be.visible')
.and('contain', 'test1en')
.and('contain', 'test2en')
.and('contain', 'newtag')
ce.save()

getNodeByPath(`/sites/${siteKey}/home/${pageName_addTest}`, ['seoKeywords']).then(({ data }) => {
expect(data.jcr.nodeByPath.properties.length).to.eq(1)
expect(data.jcr.nodeByPath.properties[0].values.length).to.eq(3)
expect(data.jcr.nodeByPath.properties[0].values).to.contains('newtag')
})
})

it('should be possible to edit SEO fields : removing a value', function () {
const ce = JContent.visit(siteKey, 'en', `pages/home/${pageName_removeTest}`).editPage()

ce.openSection('seo')

const tagField = ce.getField(Field, 'htmlHead_seoKeywords')
tagField.get().find('#htmlHead_seoKeywords').find('span:contains("test1en")').siblings('svg').click()
tagField.should('exist').and('be.visible').and('contain', 'test2en')
ce.save()

getNodeByPath(`/sites/${siteKey}/home/${pageName_removeTest}`, ['seoKeywords']).then(({ data }) => {
expect(data.jcr.nodeByPath.properties.length).to.eq(1)
expect(data.jcr.nodeByPath.properties[0].values.length).to.eq(1)
expect(data.jcr.nodeByPath.properties[0].values[0]).to.eq('test2en')
})
})
})
73 changes: 1 addition & 72 deletions tests/cypress/e2e/seoOverrides/definitions.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,9 @@ import { Field } from '@jahia/jcontent-cypress/dist/page-object/fields/field'

describe('New SEO field definition tests', () => {
const siteKey = 'seoFieldsTest'
const pageName_addTest = 'pagetest_addTag'
const pageName_removeTest = 'pagetest_removeTag'
const searchTag = {en: 'test1en', fr: 'test1fr'}

const createPageWithSEOKeyword = (pageName: string) => {
return addNode({
parentPathOrId: `/sites/${siteKey}/home`,
name: pageName,
primaryNodeType: 'jnt:page',
mixins: ['jmix:seoHtmlHead'],
properties: [
{name: 'j:templateName', value: 'simple'},
{name: 'jcr:title', language: 'en', value: pageName},
{name: 'jcr:title', language: 'fr', value: pageName},
{name: 'seoKeywords', language: 'en', values: [searchTag.en, 'test2en']},
{name: 'seoKeywords', language: 'fr', values: [searchTag.fr, 'test2fr']}
]
})
}

before(function () {
createSite(siteKey, {templateSet: 'dx-base-demo-templates', serverName: 'localhost', locale: 'en,fr'})
createPageWithSEOKeyword(pageName_addTest)
createPageWithSEOKeyword(pageName_removeTest)
createSite(siteKey)
})

after(function () {
Expand Down Expand Up @@ -77,54 +56,4 @@ describe('New SEO field definition tests', () => {
assertFieldNotExist('htmlHead_seoKeywords')
assertFieldNotExist('htmlHead_openGraphImage')
})

it('should be able to search for seo keywords tag', function () {
const searchTagInLang = (lang) => {
cy.log(`Search for ${searchTag[lang]} in ${lang} site`)
cy.visit(`cms/render/default/${lang}/sites/${siteKey}/home/search-results.html`)
cy.get('.search-block input[type="text"]').type(`${searchTag[lang]}{enter}`)
cy.get('.s-results').contains(searchTag[lang]).should('be.visible')
}
searchTagInLang('en')
searchTagInLang('fr')
})

it('should be possible to edit SEO fields : adding a new value', function () {
const ce = JContent.visit(siteKey, 'en', `pages/home/${pageName_addTest}`).editPage()

ce.openSection('seo')

const tagField = ce.getField(Field, 'htmlHead_seoKeywords')
tagField.get().find('#htmlHead_seoKeywords').type('newtag{enter}', { delay: 500 })
tagField
.should('exist')
.and('be.visible')
.and('contain', 'test1en')
.and('contain', 'test2en')
.and('contain', 'newtag')
ce.save()

getNodeByPath(`/sites/${siteKey}/home/${pageName_addTest}`, ['seoKeywords']).then(({ data }) => {
expect(data.jcr.nodeByPath.properties.length).to.eq(1)
expect(data.jcr.nodeByPath.properties[0].values.length).to.eq(3)
expect(data.jcr.nodeByPath.properties[0].values).to.contains('newtag')
})
})

it('should be possible to edit SEO fields : removing a value', function () {
const ce = JContent.visit(siteKey, 'en', `pages/home/${pageName_removeTest}`).editPage()

ce.openSection('seo')

const tagField = ce.getField(Field, 'htmlHead_seoKeywords')
tagField.get().find('#htmlHead_seoKeywords').find('span:contains("test1en")').siblings('svg').click()
tagField.should('exist').and('be.visible').and('contain', 'test2en')
ce.save()

getNodeByPath(`/sites/${siteKey}/home/${pageName_removeTest}`, ['seoKeywords']).then(({ data }) => {
expect(data.jcr.nodeByPath.properties.length).to.eq(1)
expect(data.jcr.nodeByPath.properties[0].values.length).to.eq(1)
expect(data.jcr.nodeByPath.properties[0].values[0]).to.eq('test2en')
})
})
})

0 comments on commit 85bc8ec

Please sign in to comment.