Skip to content

Commit 7d57149

Browse files
authored
Migrate tests from Codeception to Cypress (#563)
* Create Weblinks.cy.js * site weblink test + submit link * msg * test hits * hits not incremented based on configuration * check category tabs * check new web link tabs * smart search weblink plugin * Update provider.php * Update Weblinks.php * cs * cs * add plugins tests * delete items test * check the correct extension installation * restore clean-up * Check package installation * check package too * back to 4.4 * back to 4.4
1 parent 9c38f84 commit 7d57149

File tree

6 files changed

+348
-1
lines changed

6 files changed

+348
-1
lines changed

cypress.config.dist.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ export default defineConfig({
1515
specPattern: [
1616
'tests/cypress/integration/install/*.cy.{js,jsx,ts,tsx}',
1717
'tests/cypress/integration/administrator/**/*.cy.{js,jsx,ts,tsx}',
18-
'tests/cypress/integration/site/**/*.cy.{js,jsx,ts,tsx}'
18+
'tests/cypress/integration/site/**/*.cy.{js,jsx,ts,tsx}',
19+
'tests/cypress/integration/plugins/**/*.cy.{js,jsx,ts,tsx}',
1920
],
2021
supportFile: 'tests/cypress/support/index.js',
2122
scrollBehavior: 'center',

tests/cypress/integration/administrator/components/com_weblinks/Categories.cy.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,61 @@ describe('Test in backend that the categories list', () => {
8585

8686
cy.checkForSystemMessage('Category deleted.');
8787
});
88+
89+
it('Verifies all category tabs are present and functional', () => {
90+
// Visit the category edit page
91+
cy.visit('/administrator/index.php?option=com_categories&task=category.add&extension=com_weblinks');
92+
93+
// Define the expected tabs
94+
const expectedTabs = [
95+
'Category',
96+
'Options',
97+
'Publishing',
98+
//'Associations',
99+
'Permissions'
100+
];
101+
102+
// Verify tab structure and visibility
103+
cy.get('#myTab div[role="tablist"] > button[role="tab"]:visible')
104+
.should('have.length', expectedTabs.length)
105+
.each(($tab, index) => {
106+
// Check tab text and visibility
107+
cy.wrap($tab)
108+
.should('be.visible')
109+
.and('contain.text', expectedTabs[index])
110+
.and('have.attr', 'role', 'tab');
111+
});
112+
113+
// Verify initial active tab (Category)
114+
cy.get('#myTab div[role="tablist"] > button[role="tab"]:visible:nth-child(1)')
115+
.should('have.attr', 'aria-expanded', 'true')
116+
.and('contain.text', 'Category');
117+
118+
// Verify tab panels exist
119+
const tabPanels = [
120+
'general',
121+
'attrib-options',
122+
'publishing',
123+
// 'associations',
124+
'rules'
125+
];
126+
127+
tabPanels.forEach(panelId => {
128+
cy.get(`#${panelId}`)
129+
.should('exist')
130+
.and('have.attr', 'role', 'tabpanel');
131+
});
132+
133+
// Optional: Test tab switching
134+
expectedTabs.forEach((tabText, index) => {
135+
if (index > 0) { // Skip first tab (already active)
136+
cy.contains('#myTab div[role="tablist"] > button[role="tab"]:visible', tabText)
137+
.click()
138+
.should('have.attr', 'aria-expanded', 'true');
139+
140+
cy.get(`#${tabPanels[index]}`)
141+
.should('be.visible');
142+
}
143+
});
144+
});
88145
});
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
describe('Test that the weblinks extension package', () => {
2+
beforeEach(() => {
3+
cy.doAdministratorLogin();
4+
cy.visit('/administrator/index.php?option=com_installer&view=manage&filter=');
5+
cy.setFilter('core', 'Non-core Extensions');
6+
cy.searchForItem('Web Links');
7+
});
8+
9+
it('has Smart search plugin installed', () => {
10+
// Check if the row with "Smart Search - Web Links" exists
11+
cy.get('#manageList tbody tr') // Target the table rows
12+
.contains('th', 'Smart Search - Web Links') // Check the <th> in the row
13+
.parents('tr') // Navigate to the parent row
14+
.should('exist') // Confirm the row exists
15+
// Verify other cells in the same row
16+
.within(() => {
17+
cy.log(cy.get('td').eq(2))
18+
cy.get('td').eq(2).should('contain', 'Site'); // Location column
19+
cy.get('td').eq(3).should('contain', 'Plugin'); // Type column
20+
cy.get('td').eq(7).should('contain', 'finder'); // Folder column
21+
});
22+
});
23+
24+
it('has Web links module installed', () => {
25+
// Check if the row with "Module - Web Links" exists
26+
cy.get('#manageList tbody tr') // Target the table rows
27+
.contains('div', 'This modules displays Web Links') // Check the <div> in the row
28+
.parents('tr') // Navigate to the parent row
29+
.should('exist') // Confirm the row exists
30+
// Verify other cells in the same row
31+
.within(() => {
32+
cy.log(cy.get('td').eq(2))
33+
cy.get('td').eq(2).should('contain', 'Site'); // Location column
34+
cy.get('td').eq(3).should('contain', 'Module'); // Type column
35+
cy.get('td').eq(7).should('contain', 'N/A'); // Folder column
36+
});
37+
});
38+
39+
it('has System plugin installed', () => {
40+
// Check if the row with "System - Web Links" exists
41+
cy.get('#manageList tbody tr') // Target the table rows
42+
.contains('th', 'System - Web Links') // Check the <th> in the row
43+
.parents('tr') // Navigate to the parent row
44+
.should('exist') // Confirm the row exists
45+
// Verify other cells in the same row
46+
.within(() => {
47+
cy.log(cy.get('td').eq(2))
48+
cy.get('td').eq(2).should('contain', 'Site'); // Location column
49+
cy.get('td').eq(3).should('contain', 'Plugin'); // Type column
50+
cy.get('td').eq(7).should('contain', 'system'); // Folder column
51+
});
52+
});
53+
54+
it('has Web links component installed', () => {
55+
// Check if the row with "Web Links Component" exists
56+
cy.get('#manageList tbody tr') // Target the table rows
57+
.contains('div', 'Component for web links management') // Check the <div> in the row
58+
.parents('tr') // Navigate to the parent row
59+
.should('exist') // Confirm the row exists
60+
// Verify other cells in the same row
61+
.within(() => {
62+
cy.log(cy.get('td').eq(2))
63+
cy.get('td').eq(2).should('contain', 'Administrator'); // Location column
64+
cy.get('td').eq(3).should('contain', 'Component'); // Type column
65+
cy.get('td').eq(7).should('contain', 'N/A'); // Folder column
66+
});
67+
});
68+
69+
it('has Web Links Package installed', () => {
70+
// Check if the row with "Web Links Package" exists
71+
cy.get('#manageList tbody tr') // Target the table rows
72+
.contains('th', 'Web Links Extension Package') // Check the <th> in the row
73+
.parents('tr') // Navigate to the parent row
74+
.should('exist') // Confirm the row exists
75+
// Verify other cells in the same row
76+
.within(() => {
77+
cy.log(cy.get('td').eq(2))
78+
cy.get('td').eq(2).should('contain', 'Site'); // Location column
79+
cy.get('td').eq(3).should('contain', 'Package'); // Type column
80+
cy.get('td').eq(7).should('contain', 'N/A'); // Folder column
81+
});
82+
});
83+
})

tests/cypress/integration/administrator/components/com_weblinks/Weblinks.cy.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,59 @@ describe('Test in backend that the weblinks component', () => {
8989
cy.checkForSystemMessage('Web Link deleted');
9090
});
9191
});
92+
93+
it('Verifies all web link tabs are present and functional', () => {
94+
// Visit the category edit page
95+
cy.visit('/administrator/index.php?option=com_weblinks&view=weblink&layout=edit');
96+
97+
// Define the expected tabs
98+
const expectedTabs = [
99+
'New Web Link',
100+
'Images',
101+
'Publishing',
102+
'Options'
103+
];
104+
105+
// Verify tab structure and visibility
106+
cy.get('#myTab div[role="tablist"] > button[role="tab"]:visible')
107+
.should('have.length', expectedTabs.length)
108+
.each(($tab, index) => {
109+
// Check tab text and visibility
110+
cy.wrap($tab)
111+
.should('be.visible')
112+
.and('contain.text', expectedTabs[index])
113+
.and('have.attr', 'role', 'tab');
114+
});
115+
116+
// Verify initial active tab (New Web Link)
117+
cy.get('#myTab div[role="tablist"] > button[role="tab"]:visible:nth-child(1)')
118+
.should('have.attr', 'aria-expanded', 'true')
119+
.and('contain.text', 'New Web Link');
120+
121+
// Verify tab panels exist
122+
const tabPanels = [
123+
'details',
124+
'images',
125+
'publishing',
126+
'attrib-jbasic'
127+
];
128+
129+
tabPanels.forEach(panelId => {
130+
cy.get(`#${panelId}`)
131+
.should('exist')
132+
.and('have.attr', 'role', 'tabpanel');
133+
});
134+
135+
// Optional: Test tab switching
136+
expectedTabs.forEach((tabText, index) => {
137+
if (index > 0) { // Skip first tab (already active)
138+
cy.contains('#myTab div[role="tablist"] > button[role="tab"]:visible', tabText)
139+
.click()
140+
.should('have.attr', 'aria-expanded', 'true');
141+
142+
cy.get(`#${tabPanels[index]}`)
143+
.should('be.visible');
144+
}
145+
});
146+
});
92147
});
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
describe('Test in backend that the Smart Search', () => {
2+
beforeEach(() => {
3+
cy.doAdministratorLogin();
4+
});
5+
6+
afterEach(() => {
7+
cy.task('queryDB', "DELETE FROM #__weblinks WHERE title = 'Test weblink'");
8+
cy.task('queryDB', "DELETE FROM #__categories WHERE title = 'Test weblink category'")
9+
});
10+
11+
it('can index a new weblink', () => {
12+
// Enable the smart search weblinks plugin
13+
cy.db_enableExtension('1', 'plg_finder_weblinks');
14+
cy.visit('/administrator/index.php?option=com_weblinks&view=weblink&layout=edit');
15+
cy.get('#jform_title').clear().type('Test weblink');
16+
cy.get('#jform_url').clear().type('www.example.com');
17+
cy.clickToolbarButton('Save & Close');
18+
// Visit the smart search page
19+
cy.visit('/administrator/index.php?option=com_finder&view=index');
20+
cy.contains('Test weblink').should('exist');
21+
22+
cy.db_enableExtension('0', 'plg_finder_weblinks');
23+
});
24+
25+
it('can index a new weblink category', () => {
26+
// Enable the smart search weblinks plugin
27+
cy.db_enableExtension('1', 'plg_finder_weblinks');
28+
cy.visit('/administrator/index.php?option=com_categories&task=category.add&extension=com_weblinks');
29+
cy.get('#jform_title').type('Test weblink category');
30+
cy.clickToolbarButton('Save & Close');
31+
// Visit the smart search page
32+
cy.visit('/administrator/index.php?option=com_finder&view=index');
33+
cy.contains('Test weblink category').should('exist');
34+
35+
cy.db_enableExtension('0', 'plg_finder_weblinks');
36+
});
37+
38+
it('can delete the indexed weblink items', () => {
39+
// Visit the smart search page
40+
cy.visit('/administrator/index.php?option=com_finder&view=index');
41+
cy.searchForItem('Test weblink');
42+
cy.checkAllResults();
43+
cy.clickToolbarButton('Action');
44+
cy.contains('Delete').click();
45+
cy.clickDialogConfirm(true);
46+
cy.checkForSystemMessage('items deleted.');
47+
cy.contains('Test weblink').should('not.exist');
48+
cy.contains('Test weblink category').should('not.exist');
49+
});
50+
});
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
describe('Test in frontend that the weblinks', () => {
2+
beforeEach(() => cy.task('queryDB', "DELETE FROM #__weblinks WHERE title like '%test weblink%'"));
3+
4+
it('can display a list of weblinks in a category', () => {
5+
cy.db_createWeblink({ title: 'automated test weblink 1' })
6+
.then((weblink) => cy.db_createWeblink({ title: 'automated test weblink 2', catid: weblink.catid }))
7+
.then((weblink) => cy.db_createWeblink({ title: 'automated test weblink 3', catid: weblink.catid }))
8+
.then((weblink) => cy.db_createWeblink({ title: 'automated test weblink 4', catid: weblink.catid }))
9+
.then((weblink) => {
10+
cy.visit(`/index.php?option=com_weblinks&view=category&id=${weblink.catid}`);
11+
12+
cy.contains('automated test weblink 1');
13+
cy.contains('automated test weblink 2');
14+
cy.contains('automated test weblink 3');
15+
cy.contains('automated test weblink 4');
16+
});
17+
});
18+
19+
it('can display a single weblink', () => {
20+
// Create a single weblink
21+
cy.db_createWeblink({ title: 'Single test weblink', url: 'http://example.com' })
22+
.then((weblink) => {
23+
// Visit the weblink view page
24+
cy.visit(`/index.php?option=com_weblinks&view=weblink&id=${weblink.id}`);
25+
26+
// Check if the weblink is displayed
27+
cy.contains('Single test weblink');
28+
cy.get('a[href="http://example.com"]').should('exist');
29+
});
30+
});
31+
32+
it('can create a weblink through the form', () => {
33+
cy.doFrontendLogin();
34+
// Visit the weblink creation form
35+
cy.visit('/index.php?option=com_weblinks&view=form&layout=edit');
36+
37+
// Fill out the form
38+
cy.get('#jform_title').type('Form test weblink');
39+
cy.get('#jform_url').type('http://example.com');
40+
// Click the save button
41+
cy.get('button.btn.btn-primary[onclick="Joomla.submitbutton(\'weblink.save\')"]').click();
42+
43+
// Check if the weblink is successfully saved
44+
cy.checkForSystemMessage('Web Link successfully submitted.')
45+
});
46+
47+
it('Visit a weblink and check the hits is incremented by one', () => {
48+
cy.db_updateExtensionParameter('count_clicks', '1', 'com_weblinks');
49+
cy.db_createWeblink({ title: 'automated test weblink', url: Cypress.config('baseUrl') })
50+
.then((weblink) => {
51+
cy.visit(`/index.php?option=com_weblinks&view=category&id=${weblink.catid}`);
52+
53+
// Get the hits before clicking the link
54+
cy.get('div.list-hits.badge.bg-info.float-end').invoke('text').then((text) => {
55+
const hitsBefore = parseInt(text.match(/\d+/)[0], 10);
56+
57+
// Click the link with the specific text
58+
cy.contains('a', 'automated test weblink').invoke('removeAttr', 'target').click();
59+
60+
// Go back to the list page
61+
cy.go('back');
62+
63+
// Get the hits after clicking the link
64+
cy.get('div.list-hits.badge.bg-info.float-end').invoke('text').then((text) => {
65+
const hitsAfter = parseInt(text.match(/\d+/)[0], 10);
66+
67+
// Verify that the hits have increased by 1
68+
expect(hitsAfter).to.equal(hitsBefore + 1);
69+
});
70+
});
71+
});
72+
});
73+
74+
it('Visit a weblink and check the hits is not incremented', () => {
75+
cy.db_updateExtensionParameter('count_clicks', '0', 'com_weblinks');
76+
cy.db_createWeblink({ title: 'automated test weblink', url: Cypress.config('baseUrl') })
77+
.then((weblink) => {
78+
cy.visit(`/index.php?option=com_weblinks&view=category&id=${weblink.catid}`);
79+
80+
// Get the hits before clicking the link
81+
cy.get('div.list-hits.badge.bg-info.float-end').invoke('text').then((text) => {
82+
const hitsBefore = parseInt(text.match(/\d+/)[0], 10);
83+
84+
// Click the link with the specific text
85+
cy.contains('a', 'automated test weblink').invoke('removeAttr', 'target').click();
86+
87+
// Go back to the list page
88+
cy.go('back');
89+
90+
// Get the hits after clicking the link
91+
cy.get('div.list-hits.badge.bg-info.float-end').invoke('text').then((text) => {
92+
const hitsAfter = parseInt(text.match(/\d+/)[0], 10);
93+
94+
// Verify that the hits have not increased
95+
expect(hitsAfter).to.equal(hitsBefore);
96+
});
97+
});
98+
});
99+
});
100+
});
101+

0 commit comments

Comments
 (0)