Skip to content

Commit

Permalink
feat: improve cc selection (#596)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Alexandre Chau <[email protected]>
Co-authored-by: Clément <[email protected]>
  • Loading branch information
3 people authored May 9, 2023
1 parent 60d539b commit 64659bc
Show file tree
Hide file tree
Showing 6 changed files with 320 additions and 57 deletions.
61 changes: 61 additions & 0 deletions cypress/e2e/item/publish/ccLicense.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { buildItemPath } from "../../../../src/config/paths";
import {
buildPublishButtonId,
CC_ALLOW_COMMERCIAL_CONTROL_ID,
CC_CC0_CONTROL_ID,
CC_DERIVATIVE_CONTROL_ID,
CC_DISALLOW_COMMERCIAL_CONTROL_ID,
CC_NO_DERIVATIVE_CONTROL_ID,
CC_REQUIRE_ATTRIBUTION_CONTROL_ID,
CC_SHARE_ALIKE_CONTROL_ID,
} from "../../../../src/config/selectors";
import { PUBLISHED_ITEMS } from "../../../fixtures/items";
import { DEFAULT_TAGS } from "../../../fixtures/itemTags";

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

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

const ensureRadioCheckedState = (parentId, shouldBeChecked) =>
cy.get(`#${parentId}`)
// MUI doesn't update the `checked` attribute of checkboxes.
.find('svg[data-testid=RadioButtonCheckedIcon]')
.should('have.css', 'transform', `matrix(${shouldBeChecked ? '1, 0, 0, 1, 0, 0' : '0, 0, 0, 0, 0, 0'})`);

describe('Creative Commons License', () => {
it('Current license is selected', () => {
for (const publishedItem of PUBLISHED_ITEMS) {
visitItemPage(publishedItem);

const requireAttribution = publishedItem.settings.ccLicenseAdaption.includes('BY');
const noncommercial = publishedItem.settings.ccLicenseAdaption.includes('NC');
const shareAlike = publishedItem.settings.ccLicenseAdaption.includes('SA');
const noDerivative = publishedItem.settings.ccLicenseAdaption.includes('ND');

ensureRadioCheckedState(CC_REQUIRE_ATTRIBUTION_CONTROL_ID, requireAttribution);
ensureRadioCheckedState(CC_CC0_CONTROL_ID, !requireAttribution);

if (requireAttribution) {
ensureRadioCheckedState(CC_ALLOW_COMMERCIAL_CONTROL_ID, !noncommercial);
ensureRadioCheckedState(CC_DISALLOW_COMMERCIAL_CONTROL_ID, noncommercial);

ensureRadioCheckedState(CC_NO_DERIVATIVE_CONTROL_ID, noDerivative);
ensureRadioCheckedState(CC_SHARE_ALIKE_CONTROL_ID, shareAlike);
ensureRadioCheckedState(CC_DERIVATIVE_CONTROL_ID, !shareAlike && !noDerivative);
}
else {
cy.get(`#${CC_ALLOW_COMMERCIAL_CONTROL_ID}`).should('not.exist');
cy.get(`#${CC_DISALLOW_COMMERCIAL_CONTROL_ID}`).should('not.exist');
cy.get(`#${CC_NO_DERIVATIVE_CONTROL_ID}`).should('not.exist');
cy.get(`#${CC_SHARE_ALIKE_CONTROL_ID}`).should('not.exist');
cy.get(`#${CC_DERIVATIVE_CONTROL_ID}`).should('not.exist');
}
}
});
});
32 changes: 32 additions & 0 deletions cypress/fixtures/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export const DEFAULT_FOLDER_ITEM = {
type: ITEM_TYPES.FOLDER,
createdAt: new Date('2020-01-01T01:01:01Z'),
updatedAt: new Date('2020-01-02T01:01:01Z'),
settings: {
ccLicenseAdaption: 'CC BY',
}
};

export const CREATED_ITEM = {
Expand Down Expand Up @@ -73,6 +76,9 @@ export const SAMPLE_ITEMS = {
memberId: MEMBERS.BOB.id,
},
],
settings: {
ccLicenseAdaption: 'CC BY-NC',
}
},
{
...DEFAULT_FOLDER_ITEM,
Expand All @@ -81,6 +87,7 @@ export const SAMPLE_ITEMS = {
path: 'ecafbd2a_5688_11eb_ae93_0242ac130002.fdf09f5a_5688_11eb_ae93_0242ac130003',
extra: {
image: 'someimageurl',
ccLicenseAdaption: 'CC BY-NC',
},
createdAt: '2022-12-16T16:00:50.968Z',
updatedAt: '2022-12-18T16:00:52.655Z',
Expand All @@ -107,6 +114,9 @@ export const SAMPLE_ITEMS = {
memberId: MEMBERS.ANNA.id,
},
],
settings: {
ccLicenseAdaption: 'CC0',
}
},
{
...DEFAULT_FOLDER_ITEM,
Expand All @@ -123,6 +133,9 @@ export const SAMPLE_ITEMS = {
memberId: MEMBERS.ANNA.id,
},
],
settings: {
ccLicenseAdaption: 'CC BY-NC-SA',
}
},
{
...DEFAULT_FOLDER_ITEM,
Expand All @@ -141,6 +154,9 @@ export const SAMPLE_ITEMS = {
memberId: MEMBERS.ANNA.id,
},
],
settings: {
ccLicenseAdaption: 'CC BY-NC-ND',
}
},
],
memberships: [],
Expand Down Expand Up @@ -597,6 +613,22 @@ export const PUBLISHED_ITEM = {
],
};

export const PUBLISHED_ITEMS = [
PUBLISHED_ITEM,
{
...PUBLISHED_ITEM,
settings: {
ccLicenseAdaption: 'CC0',
}
},
{
...PUBLISHED_ITEM,
settings: {
ccLicenseAdaption: 'CC BY-NC-ND',
}
}
]

export const HIDDEN_ITEM = {
...DEFAULT_FOLDER_ITEM,
id: 'ecafbd2a-5688-11eb-ae93-0242ac130001',
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"@graasp/chatbox": "1.2.1",
"@graasp/query-client": "0.4.1",
"@graasp/sdk": "0.12.0",
"@graasp/translations": "1.11.0",
"@graasp/ui": "2.4.3",
"@graasp/translations": "1.12.0",
"@graasp/ui": "2.5.0",
"@mui/icons-material": "5.11.16",
"@mui/lab": "5.0.0-alpha.117",
"@mui/material": "5.12.0",
Expand Down
Loading

0 comments on commit 64659bc

Please sign in to comment.