|
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"; |
5 | 7 |
|
6 | 8 | 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 | + }); |
12 | 37 |
|
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 | + }); |
20 | 42 |
|
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'); |
23 | 49 | });
|
24 | 50 |
|
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); |
30 | 81 | });
|
31 | 82 |
|
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}`); |
37 | 88 | });
|
38 | 89 |
|
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'); |
42 | 103 | });
|
43 | 104 | });
|
0 commit comments