Skip to content

Commit

Permalink
[5.2] Add more site router tests (alias included) (#44449)
Browse files Browse the repository at this point in the history
  • Loading branch information
heelc29 authored Nov 14, 2024
1 parent e6173bd commit eedfdaa
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 42 deletions.
86 changes: 65 additions & 21 deletions tests/System/integration/site/components/com_contact/Router.cy.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
describe('Test in frontend that the contact site router', () => {
afterEach(() => cy.db_updateExtensionParameter('sef_ids', '1', 'com_contact'));

it('can process contact without a menu item', () => {
cy.db_createContact({ name: 'Test Contact', alias: 'test-contact-router' }).then((contact) => {
const url = '/index.php/component/contact/contact/test-contact-router';
cy.request({ url: `/index.php?option=com_contact&view=contact&id=${contact.id}`, followRedirect: false }).then((response) => {
expect(response.status).to.eq(301);
expect(response.redirectedToUrl).to.match(/\/index\.php\/component\/contact\/contact\/test-contact-router$/);
expect(response.redirectedToUrl).to.match(new RegExp(`${url}$`));
});
cy.request({ url: `/index.php?option=com_contact&view=contact&id=${contact.id}-${contact.alias}`, followRedirect: false }).then((response) => {
expect(response.status).to.eq(301);
expect(response.redirectedToUrl).to.match(new RegExp(`${url}$`));
});

cy.visit('/index.php/component/contact/contact/test-contact-router');
cy.url().should('match', /\/index\.php\/component\/contact\/contact\/test-contact-router$/);
cy.visit(url);
cy.url().should('match', new RegExp(`${url}$`));
cy.title().should('equal', 'Test Contact');
cy.get('main h1').contains('Home');
cy.get('main h2').contains('Test Contact');
Expand All @@ -20,20 +27,33 @@ describe('Test in frontend that the contact site router', () => {
});

it('can process contact with a single contact menu item', () => {
const url = '/index.php/test-menu-contact-router';
cy.db_createContact({ name: 'Test Contact', alias: 'test-contact-router' }).then((contact) => {
cy.db_createMenuItem({
title: 'Test Menu Single Contact',
alias: 'test-menu-contact-router',
path: 'test-menu-contact-router',
link: `index.php?option=com_contact&view=contact&id=${contact.id}`,
});
cy.request({ url: `/index.php?option=com_contact&view=contact&id=${contact.id}`, followRedirect: false }).then((response) => {
expect(response.status).to.eq(301);
expect(response.redirectedToUrl).to.match(new RegExp(`${url}$`));
});
cy.request({ url: `/index.php?option=com_contact&view=contact&id=${contact.id}-${contact.alias}`, followRedirect: false }).then((response) => {
expect(response.status).to.eq(301);
expect(response.redirectedToUrl).to.match(new RegExp(`${url}$`));
});
cy.request({ url: `/index.php?option=com_contact&view=contact&id=${contact.id}&catid=${contact.catid}`, followRedirect: false }).then((response) => {
expect(response.status).to.eq(301);
expect(response.redirectedToUrl).to.match(/\/index\.php\/test-menu-contact-router$/);
expect(response.redirectedToUrl).to.match(new RegExp(`${url}$`));
});
cy.request({ url: `/index.php?option=com_contact&view=contact&id=${contact.id}-${contact.alias}&catid=${contact.catid}`, followRedirect: false }).then((response) => {
expect(response.status).to.eq(301);
expect(response.redirectedToUrl).to.match(new RegExp(`${url}$`));
});

cy.visit('/index.php/test-menu-contact-router');
cy.url().should('match', /\/index\.php\/test-menu-contact-router$/);
cy.visit(url);
cy.url().should('match', new RegExp(`${url}$`));
cy.title().should('equal', 'Test Menu Single Contact');
cy.get('main h1').contains('Test Contact');
cy.get('main h2').contains('Contact');
Expand All @@ -44,6 +64,7 @@ describe('Test in frontend that the contact site router', () => {
});

it('can process contact with a category list menu item', () => {
const url = '/index.php/test-menu-category-router/test-contact-router';
cy.db_createContact({ name: 'Test Contact', alias: 'test-contact-router' }).then((contact) => {
cy.db_createMenuItem({
title: 'Test Menu Contact Category',
Expand All @@ -53,11 +74,15 @@ describe('Test in frontend that the contact site router', () => {
});
cy.request({ url: `/index.php?option=com_contact&view=contact&id=${contact.id}&catid=${contact.catid}`, followRedirect: false }).then((response) => {
expect(response.status).to.eq(301);
expect(response.redirectedToUrl).to.match(/\/index\.php\/test-menu-category-router\/test-contact-router$/);
expect(response.redirectedToUrl).to.match(new RegExp(`${url}$`));
});
cy.request({ url: `/index.php?option=com_contact&view=contact&id=${contact.id}-${contact.alias}&catid=${contact.catid}`, followRedirect: false }).then((response) => {
expect(response.status).to.eq(301);
expect(response.redirectedToUrl).to.match(new RegExp(`${url}$`));
});

cy.visit('/index.php/test-menu-category-router');
cy.url().should('match', /\/index\.php\/test-menu-category-router$/);
cy.visit(url.split('/').slice(0, -1).join('/'));
cy.url().should('match', new RegExp(`${url.split('/').slice(0, -1).join('/')}$`));
cy.title().should('equal', 'Test Menu Contact Category');
cy.get('main h1').contains('Uncategorised');
cy.get('nav.mod-breadcrumbs__wrapper ol.mod-breadcrumbs').children().as('breadcrumb');
Expand All @@ -66,10 +91,10 @@ describe('Test in frontend that the contact site router', () => {
cy.get('main div.com-contact-category a')
.contains('Test Contact')
.should('have.attr', 'href')
.and('match', /\/index\.php\/test-menu-category-router\/test-contact-router$/);
.and('match', new RegExp(`${url}$`));

cy.visit('/index.php/test-menu-category-router/test-contact-router');
cy.url().should('match', /\/index\.php\/test-menu-category-router\/test-contact-router$/);
cy.visit(url);
cy.url().should('match', new RegExp(`${url}$`));
cy.title().should('equal', 'Test Contact');
cy.get('main h1').contains('Test Contact');
cy.get('main h2').contains('Contact');
Expand All @@ -81,6 +106,7 @@ describe('Test in frontend that the contact site router', () => {
});

it('can process contact with a categories list menu item', () => {
const url = '/index.php/test-menu-categories-router/uncategorised/test-contact-router';
cy.db_createContact({ name: 'Test Contact', alias: 'test-contact-router' }).then((contact) => {
cy.db_createMenuItem({
title: 'Test Menu Contact Categories',
Expand All @@ -90,22 +116,22 @@ describe('Test in frontend that the contact site router', () => {
});
cy.request({ url: `/index.php?option=com_contact&view=contact&id=${contact.id}&catid=${contact.catid}`, followRedirect: false }).then((response) => {
expect(response.status).to.eq(301);
expect(response.redirectedToUrl).to.match(/\/index\.php\/test-menu-categories-router\/uncategorised\/test-contact-router$/);
expect(response.redirectedToUrl).to.match(new RegExp(`${url}$`));
});

cy.visit('/index.php/test-menu-categories-router');
cy.url().should('match', /\/index\.php\/test-menu-categories-router$/);
cy.visit(url.split('/').slice(0, -2).join('/'));
cy.url().should('match', new RegExp(`${url.split('/').slice(0, -2).join('/')}$`));
cy.title().should('equal', 'Test Menu Contact Categories');
cy.get('nav.mod-breadcrumbs__wrapper ol.mod-breadcrumbs').children().as('breadcrumb');
cy.get('@breadcrumb').should('have.length', 3);
cy.get('@breadcrumb').eq(2).should('contain', 'Test Menu Contact Categories');
cy.get('main div.com-contact-categories h3 a')
.contains('Uncategorised')
.should('have.attr', 'href')
.and('match', /\/index\.php\/test-menu-categories-router\/uncategorised$/);
.and('match', new RegExp(`${url.split('/').slice(0, -1).join('/')}$`));

cy.visit('/index.php/test-menu-categories-router/uncategorised');
cy.url().should('match', /\/index\.php\/test-menu-categories-router\/uncategorised$/);
cy.visit(url.split('/').slice(0, -1).join('/'));
cy.url().should('match', new RegExp(`${url.split('/').slice(0, -1).join('/')}$`));
cy.title().should('equal', 'Test Menu Contact Categories');
cy.get('main h1').contains('Uncategorised');
cy.get('nav.mod-breadcrumbs__wrapper ol.mod-breadcrumbs').children().as('breadcrumb');
Expand All @@ -115,10 +141,10 @@ describe('Test in frontend that the contact site router', () => {
cy.get('main div.com-contact-category a')
.contains('Test Contact')
.should('have.attr', 'href')
.and('match', /\/index\.php\/test-menu-categories-router\/uncategorised\/test-contact-router$/);
.and('match', new RegExp(`${url}$`));

cy.visit('/index.php/test-menu-categories-router/uncategorised/test-contact-router');
cy.url().should('match', /\/index\.php\/test-menu-categories-router\/uncategorised\/test-contact-router$/);
cy.visit(url);
cy.url().should('match', new RegExp(`${url}$`));
cy.title().should('equal', 'Test Contact');
cy.get('main h1').contains('Test Contact');
cy.get('main h2').contains('Contact');
Expand All @@ -129,4 +155,22 @@ describe('Test in frontend that the contact site router', () => {
cy.get('@breadcrumb').eq(4).should('contain', 'Test Contact');
});
});

it('can process contact with legacy routing', () => {
cy.db_updateExtensionParameter('sef_ids', '0', 'com_contact');
cy.db_createContact({ name: 'Test Contact', alias: 'test-contact-router' }).then((contact) => {
const url = `/index.php/component/contact/contact/${contact.id}-test-contact-router`;
cy.request({ url, followRedirect: false }).then((response) => {
expect(response.status).to.eq(200);
});
cy.request({ url: `/index.php?option=com_contact&view=contact&id=${contact.id}`, followRedirect: false }).then((response) => {
expect(response.status).to.eq(301);
expect(response.redirectedToUrl).to.match(new RegExp(`${url}$`));
});
cy.request({ url: `/index.php?option=com_contact&view=contact&id=${contact.id}-${contact.alias}`, followRedirect: false }).then((response) => {
expect(response.status).to.eq(301);
expect(response.redirectedToUrl).to.match(new RegExp(`${url}$`));
});
});
});
});
Loading

0 comments on commit eedfdaa

Please sign in to comment.