Skip to content

Commit 0adb1b8

Browse files
authored
Merge pull request #1592 from GSA/nmb/catalog-next-cypress
Cypress tests for catalog-next
2 parents ad94cd1 + daa886e commit 0adb1b8

16 files changed

+488
-107
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ update-dependencies:
4444

4545
test: build
4646
# docker build -t ghcr.io/gsa/catalog.data.gov:latest ckan/
47-
docker compose -f docker-compose.yml -f docker-compose.test.yml up --abort-on-container-exit test
47+
docker compose --profile test up --force-recreate --abort-on-container-exit test
4848

4949
# everytime you added some new variables, you need to swap it with some test values
5050
# and swap it back after the test. This is because "nginx -t" test cannot read env variables.
@@ -79,7 +79,7 @@ validate-proxy:
7979

8080
quick-bat-test:
8181
# if local environment is already build and running
82-
docker compose -f docker-compose.yml -f docker-compose.test.yml up --abort-on-container-exit test
82+
docker compose --profile test up --abort-on-container-exit test
8383

8484
test-extensions:
8585
# test our extensions

docker-compose.test.yml

-18
This file was deleted.

docker-compose.yml

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: "3"
2-
31
services:
42
ckan:
53
image: ghcr.io/gsa/catalog.data.gov:latest
@@ -46,6 +44,24 @@ services:
4644
redis:
4745
image: redis:alpine
4846

47+
48+
test:
49+
image: cypress/included:12.17.2
50+
entrypoint: []
51+
command: /bin/bash -c "npx wait-on http://ckan:5000/dataset && cypress run"
52+
# To run specific test, use the following syntax:
53+
# command: /bin/bash -c "npx wait-on http://ckan:5000 && cypress run --spec cypress/integration/login.spec.js"
54+
environment:
55+
# Created cypress user and password, setup in 00-setup-cypress-user.sh
56+
- CYPRESS_USER=admin
57+
- CYPRESS_USER_PASSWORD=password
58+
working_dir: /e2e
59+
depends_on:
60+
- ckan
61+
profiles: [test]
62+
volumes:
63+
- ./e2e:/e2e
64+
4965
volumes:
5066
ckan_storage:
5167
pg_data:
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
describe('Collection', () => {
2+
3+
const orgId = "org-" + cy.helpers.randomSlug();
4+
const parentId = "parent-" + orgId;
5+
const childId = "child-" + parentId;
6+
7+
before(() => {
8+
cy.login();
9+
cy.create_token();
10+
cy.create_organization(orgId);
11+
cy.create_dataset({
12+
"name": parentId,
13+
"owner_org": orgId,
14+
"extras": [
15+
{
16+
"key": "Identifier",
17+
"value": parentId
18+
},
19+
{
20+
"key": "harvest_source_id",
21+
"value": "harvest-source"
22+
}
23+
]
24+
});
25+
cy.create_dataset({
26+
"name": childId,
27+
"owner_org": orgId,
28+
"extras": [
29+
{
30+
"key": "isPartOf",
31+
"value": parentId
32+
},
33+
{
34+
"key": "harvest_source_id",
35+
"value": "harvest-source"
36+
}
37+
]
38+
});
39+
});
40+
41+
after(() => {
42+
cy.delete_dataset(childId);
43+
cy.delete_dataset(parentId);
44+
cy.delete_organization(orgId);
45+
cy.revoke_token();
46+
cy.logout();
47+
});
48+
49+
it('Has a UI search button', () => {
50+
cy.visit('/dataset/' + parentId);
51+
cy.hide_debug_toolbar();
52+
// Click on the "Search within this collection" button
53+
cy.contains('Search datasets within this collection').click();
54+
cy.url().should('include', '?collection_info');
55+
});
56+
});

e2e/cypress/integration/dataset.cy.js

+92-31
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,104 @@
1-
describe('Prepare', { testIsolation: false }, () => {
2-
const testOrgName = 'Test Organization';
3-
const testOrgId = 'test-organization';
4-
const testOrgDesc = 'cypress test org description';
1+
describe('Dataset', () => {
2+
// Uses datasets from data.json local harvest to check
3+
4+
const orgId = "org-" + cy.helpers.randomSlug();
5+
const packageId = "dataset-" + orgId;
6+
const title = "Data.gov Statistics Parent";
57

68
before(() => {
7-
/**
8-
* Login as cypress user and create an organization
9-
*/
10-
cy.login();
11-
cy.create_token();
9+
cy.login();
10+
cy.create_token();
11+
cy.create_organization(orgId);
12+
cy.create_dataset({
13+
"name": packageId,
14+
"title": title,
15+
"owner_org": orgId,
16+
"extras": [
17+
{
18+
"key": "publisher",
19+
"value": orgId
20+
},
21+
{
22+
"key": "harvest_object_id",
23+
"value": "object-id"
24+
},
25+
{
26+
"key": "harvest_source_id",
27+
"value": "source-id"
28+
},
29+
{
30+
"key": "harvest_source_title",
31+
"value": "source-title"
32+
}
33+
]
34+
});
35+
cy.create_resource(packageId, "file:///", "resource-name");
36+
});
1237

13-
// Create the Test Organization using UI
14-
// We can use the API to create the organization, but we want to test the UI
15-
// expecially the js part to create the testOrgId from the testOrgName
16-
cy.visit('/organization');
17-
cy.get('a[class="btn btn-primary"]').click();
18-
cy.create_organization_ui(testOrgName, testOrgDesc);
19-
cy.logout();
38+
after(() => {
39+
cy.delete_dataset(packageId);
40+
cy.delete_organization(orgId);
41+
});
2042

21-
// Create the Test Dataset
22-
cy.create_dataset();
43+
it('Has a details page with core metadata', () => {
44+
cy.visit('/dataset/' + packageId);
45+
cy.contains(title);
46+
cy.contains('Metadata Source');
47+
cy.contains('Additional Metadata');
48+
cy.contains('Publisher');
2349
});
2450

25-
after(() => {
26-
cy.delete_dataset();
27-
cy.delete_organization();
28-
cy.revoke_token();
29-
cy.logout();
51+
it('Can see resource page', () => {
52+
cy.visit('/dataset/' + packageId);
53+
cy.hide_debug_toolbar();
54+
// Click on the resource link
55+
cy.contains('resource-name').click();
56+
cy.contains('About this Resource');
57+
cy.contains('Visit page');
58+
});
59+
60+
it('Can get harvest information via API', () => {
61+
cy.request(`/api/action/package_show?id=${packageId}`).should((response) => {
62+
expect(response.body).to.have.property('success', true);
63+
// CKAN extras are complicated to parse, make sure we have
64+
// the necessary harvest info
65+
let harvest_info = {};
66+
for (let extra of response.body.result.extras) {
67+
if (extra.key.includes('harvest_')) {
68+
harvest_info[extra.key] = true;
69+
}
70+
}
71+
expect(harvest_info).to.have.property('harvest_object_id', true);
72+
expect(harvest_info).to.have.property('harvest_source_id', true);
73+
expect(harvest_info).to.have.property('harvest_source_title', true);
74+
});
75+
});
76+
77+
it('Can click on items on the sidebar (e.g. org filter)', () => {
78+
cy.visit('/dataset');
79+
cy.contains(orgId).click();
80+
cy.get('div[class="filter-list"] span[class="filtered pill"]').contains(orgId);
3081
});
3182

32-
it('Test Org is present', () => {
33-
// can visit the org using testOrgId
34-
cy.visit('/organization/' + testOrgId);
35-
cy.contains(testOrgName);
36-
cy.contains(testOrgDesc);
83+
it("Can click on items on the dataset's sidebar (e.g. Publisher )", () => {
84+
cy.visit('/dataset/' + packageId);
85+
cy.get('a[title="publisher"]').contains(orgId).click({force: true}); // Publisher was set to orgId
86+
cy.get('ul[class="dataset-list unstyled"] li').eq(1).click();
87+
cy.url().should('include', `publisher=${orgId}`);
3788
});
3889

39-
it('Test Dataset is present', () => {
40-
cy.visit('/dataset/test-dataset');
41-
cy.contains('Test Dataset');
90+
it("Can click on feedback button", () => {
91+
cy.visit('/dataset/' + packageId);
92+
// sleep for 1 second to allow touchpoint js to load
93+
cy.wait(1000);
94+
cy.hide_debug_toolbar();
95+
// the button is visible
96+
cy.get('#contact-btn').should('be.visible').click();
97+
// the modal is invisible
98+
cy.get('.fba-modal-dialog').should('be.visible');
99+
cy.get('#fba_location_code').should('have.value', packageId);
100+
// can hide the modal
101+
cy.get('.fba-modal-close').click();
102+
cy.get('.fba-modal-dialog').should('not.be.visible');
42103
});
43104
});

e2e/cypress/integration/dcat.cy.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
describe('DCAT Extension', () => {
2+
const orgId = "org-" + cy.helpers.randomSlug();
3+
const packageId = "dataset-" + orgId;
4+
5+
before(() => {
6+
cy.login();
7+
cy.create_token();
8+
cy.create_organization(orgId);
9+
cy.create_dataset({
10+
"name": packageId,
11+
"owner_org": orgId,
12+
});
13+
});
14+
15+
after(() => {
16+
cy.delete_dataset(packageId);
17+
cy.delete_organization(orgId);
18+
});
19+
20+
it('Datasets have an rdf endpoint', () => {
21+
cy.request(`/dataset/${packageId}.rdf`).its('body').should('include', 'dcat:Dataset')
22+
});
23+
});

e2e/cypress/integration/facets.cy.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
describe('Facets', { testIsolation: false }, () => {
2+
before(() => {
3+
cy.login();
4+
});
5+
6+
after(() => {
7+
cy.delete_organization('org-tags');
8+
cy.delete_group('group-facets');
9+
cy.logout();
10+
});
11+
12+
it('Show datagov facet list on dataset page', () => {
13+
cy.visit('/dataset');
14+
cy.get('.filters h2').its('length').should('be.equal', 9);
15+
cy.get('.filters h2').first().contains('Topics');
16+
cy.get('.filters h2').last().contains('Bureaus');
17+
});
18+
19+
it('Show datagov facet list on organization page', () => {
20+
cy.visit('/organization');
21+
cy.get('a[class="btn btn-primary"]').click();
22+
cy.create_organization_ui('org-tags', 'tags for org test');
23+
cy.visit('/organization/org-tags');
24+
cy.get('.module-shallow').its('length').should('be.equal', 11);
25+
cy.get('.module-shallow').contains('Topics');
26+
cy.get('.module-shallow').contains('Harvest Source');
27+
cy.get('.module-shallow').last().contains('Bureaus');
28+
});
29+
30+
it('Show datagov facet list on group page', () => {
31+
cy.create_group('group-facets');
32+
cy.visit('/group/group-facets');
33+
cy.get('.filters h2').its('length').should('be.equal', 6);
34+
cy.get('.filters h2').first().contains('Categories');
35+
cy.get('.filters h2').last().contains('Organizations');
36+
});
37+
38+
// https://github.com/GSA/datagov-deploy/issues/3672
39+
it('Can visit organization and group facet link', () => {
40+
cy.visit('/organization/org-tags?tags=_');
41+
cy.visit('/group/group-facets?tags=_');
42+
});
43+
});

e2e/cypress/integration/group.cy.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const group = {
2+
name: `climate-${cy.helpers.randomSlug()}`,
3+
desc: `Climate Group ${cy.helpers.randomSlug()}`
4+
}
5+
let orgId = `org-${cy.helpers.randomSlug()}`;
6+
let packageId = `package-${orgId}`;
7+
8+
describe('Group', () => {
9+
before(() => {
10+
cy.login();
11+
cy.create_token();
12+
cy.create_organization(orgId);
13+
cy.create_dataset({"name": packageId, "owner_org": orgId});
14+
cy.create_group(group.name, group.desc);
15+
});
16+
17+
after(() => {
18+
cy.delete_group(group.name);
19+
cy.delete_dataset(packageId);
20+
cy.delete_organization(orgId);
21+
cy.revoke_token();
22+
cy.logout();
23+
});
24+
25+
it('Can put a package in a group', () => {
26+
cy.request({
27+
url: '/api/action/package_patch',
28+
method: 'POST',
29+
body: {
30+
id: packageId,
31+
groups: [{ name: group.name }],
32+
},
33+
}).should((response) => {
34+
expect(response.body).to.have.property('success', true);
35+
expect(response.body.result.groups[0]).to.have.property('name', group.name);
36+
});
37+
});
38+
});
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
describe('language', () => {
2+
it("Doesn't have french page", () => {
3+
cy.request({url: '/fr/dataset', failOnStatusCode: false}).its('status').should('equal', 404)
4+
});
5+
})

e2e/cypress/integration/login.cy.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
describe('Login', () => {
2+
it('Invalid user login attempt', () => {
3+
cy.visit('/dataset');
4+
cy.get('a[href="/user/login"]').click();
5+
cy.login('not-user', 'not-password');
6+
cy.get('.flash-messages .alert').should('contain', 'Login failed. Bad username or password.');
7+
});
8+
9+
it('Valid login attempt', () => {
10+
cy.visit('/dataset');
11+
cy.get('a[href="/user/login"]').click();
12+
cy.login();
13+
cy.get('.nav-tabs>li>a').should('contain', 'My Organizations');
14+
});
15+
});

0 commit comments

Comments
 (0)