Skip to content

Commit

Permalink
test: fix and add tests for changes
Browse files Browse the repository at this point in the history
  • Loading branch information
louisewang1 committed Apr 14, 2022
1 parent 7c21d18 commit 316802a
Show file tree
Hide file tree
Showing 12 changed files with 171 additions and 229 deletions.
50 changes: 34 additions & 16 deletions cypress/fixtures/validations.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,47 @@
import { SAMPLE_PUBLIC_ITEMS } from "./items";

export const VALIDATED_ITEM = {
...SAMPLE_PUBLIC_ITEMS.items[0],
updatedAt: new Date('2019-07-27T07:45:00Z')
}

export const SAMPLE_STATUSES = [
{
id: 'status-id1',
name: 'name1',
name: 'success',
},
{
id: 'status-id2',
name: ' name2',
name: 'pending',
},
];

export const ITEM_VALIDATION_AND_REVIEW = [
export const ITEM_VALIDATION_AND_REVIEW = {
itemValidationId: '6cbe87b9-0098-412f-a1ab-93e140ae1659',
reviewStatusId: '',
reviewReason: '',
createdAt: new Date('2023-07-27T07:45:00Z'),
};

export const ITEM_VALIDATION_GROUPS = [
{
validationStatusId: 'id',
reviewStatusId: 'id',
validationResult: 'result',
reviewResult: 'review-result',
validationUpdatedAt: 'ts',
reviewUpdatedAt: 'ts',
id: 'id1',
itemId: 'item-id1',
itemValidationId: '6cbe87b9-0098-412f-a1ab-93e140ae1659',
processId: 'process-id1',
statusId: 'status-id1',
result: '',
updatedAt: '',
createdAt: '',
},
{
validationStatusId: 'id2',
reviewStatusId: 'id',
validationResult: 'result',
reviewResult: 'review-result',
validationUpdatedAt: 'ts',
reviewUpdatedAt: 'ts',
},
id: 'id1',
itemId: 'item-id1',
itemValidationId: '6cbe87b9-0098-412f-a1ab-93e140ae1659',
processId: 'process-id2',
statusId: 'status-id1',
result: '',
updatedAt: '',
createdAt: '',
}
];
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
buildCategoryMenuOptions,
buildShareButtonId,
buildPublishButtonId,
CATEGORIES_SELECTION_VALUE_SELECTOR,
SHARE_ITEM_CATEGORY_DISCIPLINE,
SHARE_ITEM_CATEGORY_LEVEL,
Expand All @@ -14,8 +14,8 @@ import { DEFAULT_TAGS } from '../../../fixtures/itemTags';
import { PUBLISHED_ITEM } from '../../../fixtures/items';
import { MEMBERS, SIGNED_OUT_MEMBER } from '../../../fixtures/members';

const openShareItemTab = (id) => {
cy.get(`#${buildShareButtonId(id)}`).click();
const openPublishItemTab = (id) => {
cy.get(`#${buildPublishButtonId(id)}`).click();
};

const findCategoryNameById = (id) =>
Expand All @@ -38,7 +38,7 @@ describe('Categories', () => {
beforeEach(() => {
cy.setUpApi({ items: [item], tags: DEFAULT_TAGS });
cy.visit(buildItemPath(item.id));
openShareItemTab(item.id);
openPublishItemTab(item.id);
});

it('Display Item Categories', () => {
Expand Down Expand Up @@ -80,6 +80,7 @@ describe('Categories', () => {
});
});

// users without permission will not see the sections
describe('Categories permissions', () => {
it('User signed out cannot edit category level', () => {
const item = PUBLISHED_ITEM;
Expand All @@ -89,9 +90,9 @@ describe('Categories permissions', () => {
tags: DEFAULT_TAGS,
});
cy.visit(buildItemPath(item.id));
openShareItemTab(item.id);
openPublishItemTab(item.id);
const levelValue = cy.get(`#${SHARE_ITEM_CATEGORY_LEVEL}`);
levelValue.should('be.disabled');
levelValue.should('not.exist');
});

it('Read-only user cannot edit category level', () => {
Expand All @@ -102,8 +103,8 @@ describe('Categories permissions', () => {
tags: DEFAULT_TAGS,
});
cy.visit(buildItemPath(item.id));
openShareItemTab(item.id);
openPublishItemTab(item.id);
const levelValue = cy.get(`#${SHARE_ITEM_CATEGORY_LEVEL}`);
levelValue.should('be.disabled');
levelValue.should('not.exist');
});
});
81 changes: 81 additions & 0 deletions cypress/integration/item/publish/publishedItem.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import {
buildPublishButtonId,
ITEM_PUBLISH_BUTTON_ID,
ITEM_UNPUBLISH_BUTTON_ID,
ITEM_VALIDATION_BUTTON_ID,
} from '../../../../src/config/selectors';
import { buildItemPath } from '../../../../src/config/paths';
import {
PUBLISHED_ITEM,
SAMPLE_ITEMS,
SAMPLE_PUBLIC_ITEMS,
} from '../../../fixtures/items';
import { DEFAULT_TAGS, ITEM_PUBLISHED_TAG } from '../../../fixtures/itemTags';
import { VALIDATED_ITEM } from '../../../fixtures/validations';

const openPublishItemTab = (id) => {
cy.get(`#${buildPublishButtonId(id)}`).click();
};

// eslint-disable-next-line import/prefer-default-export
export const publishItem = () => {
cy.get(`#${ITEM_PUBLISH_BUTTON_ID}`).click();
};

describe('Public Item', () => {
it('Validate item', () => {
cy.setUpApi({ ...SAMPLE_PUBLIC_ITEMS, tags: DEFAULT_TAGS });
const item = SAMPLE_ITEMS.items[0];
cy.visit(buildItemPath(item.id));
openPublishItemTab(item.id);

// click validate item button
cy.get(`#${ITEM_VALIDATION_BUTTON_ID}`).click();

cy.wait('@postItemValidation').then((data) => {
const {
request: { url },
} = data;
expect(url.split('/')).contains(item.id);
});
});
});

describe('Published Item', () => {
const item = PUBLISHED_ITEM;
beforeEach(() => {
cy.setUpApi({ items: [item], tags: DEFAULT_TAGS });
cy.visit(buildItemPath(item.id));
openPublishItemTab(item.id);
});
it('Show published state on button', () => {
// click validate item button
cy.get(`#${ITEM_PUBLISH_BUTTON_ID} > span`).children().children().should('exist');
});
it('Unpublish item', () => {
cy.get(`#${ITEM_UNPUBLISH_BUTTON_ID}`).click();
cy.wait('@deleteItemTag').then(({ request: { url } }) => {
// should contain published tag id
expect(url).to.contain(item.tags[1].id);
});
})
});

describe('Validated Item', () => {
it('Publish item', () => {
cy.setUpApi({ items: [VALIDATED_ITEM], tags: DEFAULT_TAGS });
const item = VALIDATED_ITEM;
cy.visit(buildItemPath(item.id));
openPublishItemTab(item.id);

// click validate item button
cy.get(`#${ITEM_PUBLISH_BUTTON_ID}`).click();

cy.wait('@postItemTag').then((data) => {
const {
request: { body },
} = data;
expect(body?.tagId).to.equal(ITEM_PUBLISHED_TAG.id);
});
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
buildCustomizedTagsSelector,
buildShareButtonId,
buildPublishButtonId,
ITEM_TAGS_EDIT_INPUT_ID,
ITEM_TAGS_EDIT_SUBMIT_BUTTON_ID,
} from '../../../../src/config/selectors';
Expand All @@ -14,14 +14,14 @@ import { DEFAULT_TAGS } from '../../../fixtures/itemTags';
import { MEMBERS, SIGNED_OUT_MEMBER } from '../../../fixtures/members';
import { EDIT_TAG_REQUEST_TIMEOUT } from '../../../support/constants';

const openShareItemTab = (id) => {
cy.get(`#${buildShareButtonId(id)}`).click();
const openPublishItemTab = (id) => {
cy.get(`#${buildPublishButtonId(id)}`).click();
};

const visitItemPage = (item) => {
cy.setUpApi({ items: [item], tags: DEFAULT_TAGS });
cy.visit(buildItemPath(item.id));
openShareItemTab(item.id);
openPublishItemTab(item.id);
};

describe('Customized Tags', () => {
Expand Down Expand Up @@ -68,9 +68,9 @@ describe('Tags permissions', () => {
tags: DEFAULT_TAGS,
});
cy.visit(buildItemPath(item.id));
openShareItemTab(item.id);
openPublishItemTab(item.id);
const tagsEdit = cy.get(`#${ITEM_TAGS_EDIT_INPUT_ID}`);
tagsEdit.should('be.disabled');
tagsEdit.should('not.exist');
});

it('Read-only user cannot edit tags', () => {
Expand All @@ -81,8 +81,8 @@ describe('Tags permissions', () => {
tags: DEFAULT_TAGS,
});
cy.visit(buildItemPath(item.id));
openShareItemTab(item.id);
openPublishItemTab(item.id);
const tagsEdit = cy.get(`#${ITEM_TAGS_EDIT_INPUT_ID}`);
tagsEdit.should('be.disabled');
tagsEdit.should('not.exist');
});
});
100 changes: 0 additions & 100 deletions cypress/integration/item/share/publishedItem.spec.js

This file was deleted.

Loading

0 comments on commit 316802a

Please sign in to comment.