Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: analytics test #556

Merged
merged 9 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cypress/e2e/analytics/appAnalytics.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import MOCK_ITEMS, {
APP_ITEM_WITH_PARENT,
CALC_APP_ITEM,
CALC_APP_ITEM_WITH_PARENT,
} from '../../../src/modules/analytics/cypress/fixtures/items';
} from '../../fixtures/analytics/items';
import { buildItemPath } from './utils';

const visitItemPage = (item: { id: string }) => {
Expand Down
95 changes: 91 additions & 4 deletions cypress/e2e/analytics/chartsHeader.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Context } from '@graasp/sdk';
import { Context, HttpMethod } from '@graasp/sdk';

import {
SELECT_ACTION_ID,
Expand All @@ -12,9 +12,18 @@ import {
buildSelectedUserChipId,
buildSidebarListItemId,
} from '../../../src/modules/analytics/config/selectors';
import MOCK_ACTION_DATA from '../../../src/modules/analytics/cypress/fixtures/actions';
import MOCK_ITEMS from '../../../src/modules/analytics/cypress/fixtures/items';
import MOCK_MEMBERS from '../../../src/modules/analytics/cypress/fixtures/members';
import MOCK_ACTION_DATA from '../../fixtures/analytics/actions';
import {
MOCK_AGGREGATE_ACTIONS_ACTIVE_USERS,
MOCK_AGGREGATE_ACTIONS_BY_DAY,
MOCK_AGGREGATE_ACTIONS_BY_TIME,
MOCK_AGGREGATE_ACTIONS_BY_WEEKDAY,
MOCK_AGGREGATE_ACTIONS_TOTAL_ACTIONS,
MOCK_AGGREGATE_ACTIONS_TOTAL_USERS,
MOCK_AGGREGATE_ACTIONS_TYPE,
} from '../../fixtures/analytics/aggregateActions';
import MOCK_ITEMS from '../../fixtures/analytics/items';
import MOCK_MEMBERS from '../../fixtures/analytics/members';
import { buildItemPath } from './utils';

const visitItemPage = (item: { id: string }) => {
Expand All @@ -24,9 +33,84 @@ const visitItemPage = (item: { id: string }) => {
const checkContainViewText = (view: Context) =>
cy.get(`#${buildSelectViewId(view)}`).should('contain', view);

const setupIntercepts = () => {
cy.intercept(
{ method: HttpMethod.Get, pathname: /\/items\/(.*?)\/actions$/ },
MOCK_ACTION_DATA,
).as('getItemActions');
cy.intercept(
{
method: HttpMethod.Get,
pathname: /\/items\/(.*?)\/actions\/aggregation$/,
},
(request) => {
const { countGroupBy, aggregateBy, aggregateMetric, aggregateFunction } =
request.query;

if (
countGroupBy === 'user' &&
aggregateMetric === 'user' &&
aggregateFunction === 'count'
) {
return MOCK_AGGREGATE_ACTIONS_TOTAL_USERS;
}
if (
countGroupBy === 'createdDay' &&
aggregateBy === 'createdDay' &&
aggregateMetric === 'actionCount' &&
aggregateFunction === 'count'
) {
return MOCK_AGGREGATE_ACTIONS_ACTIVE_USERS;
}
if (
countGroupBy === 'createdDay' &&
aggregateBy === 'createdDay' &&
aggregateMetric === 'actionCount' &&
aggregateFunction === 'avg'
) {
return MOCK_AGGREGATE_ACTIONS_BY_DAY;
}
if (
countGroupBy === 'createdDay' &&
aggregateBy === 'createdDay' &&
aggregateMetric === 'actionCount' &&
aggregateFunction === 'sum'
) {
return MOCK_AGGREGATE_ACTIONS_TOTAL_ACTIONS;
}
if (
countGroupBy === 'createdTimeOfDay' &&
aggregateBy === 'createdTimeOfDay' &&
aggregateMetric === 'actionCount' &&
aggregateFunction === 'avg'
) {
return MOCK_AGGREGATE_ACTIONS_BY_TIME;
}
if (
countGroupBy === 'createdDayOfWeek' &&
aggregateBy === 'createdDayOfWeek' &&
aggregateMetric === 'actionCount' &&
aggregateFunction === 'avg'
) {
return MOCK_AGGREGATE_ACTIONS_BY_WEEKDAY;
}
if (
countGroupBy === 'actionType' &&
aggregateBy === 'actionType' &&
aggregateMetric === 'actionCount' &&
aggregateFunction === 'sum'
) {
return MOCK_AGGREGATE_ACTIONS_TYPE;
}
return [];
},
).as('getAggregateActions');
};

describe('Select platform view ', () => {
beforeEach(() => {
cy.setUpApi({});
setupIntercepts();
});

it('select platform view should be library, or player, or builder', () => {
Expand Down Expand Up @@ -64,6 +148,7 @@ describe('Select platform view ', () => {
describe('Select users', () => {
beforeEach(() => {
cy.setUpApi({});
setupIntercepts();
});
it('values of user select should be maintained when navigating within different routes', () => {
visitItemPage(MOCK_ITEMS[0]);
Expand All @@ -90,9 +175,11 @@ describe('Select users', () => {
);
});
});

describe('Select actions', () => {
beforeEach(() => {
cy.setUpApi({});
setupIntercepts();
});
it('values of action select should be maintained when navigating within different routes', () => {
visitItemPage(MOCK_ITEMS[0]);
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/analytics/exportAnalytics.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
EXPORT_ACTIONS_BUTTON_ID,
buildSelectExportFormatID,
} from '../../../src/modules/analytics/config/selectors';
import { ITEM_TO_EXPORT } from '../../../src/modules/analytics/cypress/fixtures/items';
import MOCK_MEMBERS from '../../../src/modules/analytics/cypress/fixtures/members';
import { ITEM_TO_EXPORT } from '../../fixtures/analytics/items';
import MOCK_MEMBERS from '../../fixtures/analytics/members';

describe('Check exporting analytics for allowed formats', () => {
beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/analytics/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const buildItemPath = ({
itemId = `:itemId`,
searchParams = '',
} = {}): string => {
let url = `/analytics/${itemId}`;
let url = `/analytics/items/${itemId}`;
// append search parameters if present
if (searchParams) {
url = `${url}?${searchParams}`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import {
AppItemFactory,
DiscriminatedItem,
DocumentItemFactory,
FolderItemFactory,
ItemType,
PackedAppItemFactory,
PackedFolderItemFactory,
PermissionLevel,
} from '@graasp/sdk';

import MOCK_MEMBERS from './members';
import { CURRENT_MEMBER, MEMBERS } from '../members';

const MOCK_ITEMS: DiscriminatedItem[] = [
FolderItemFactory({
id: '2162f6ec-60f3-4339-be17-765a49d638c3',
name: 'folder1',
path: '2162f6ec_60f3_4339_be17_765a49d638c3',
creator: MOCK_MEMBERS[0],
creator: CURRENT_MEMBER,
}),
FolderItemFactory({
id: '81950088-ec8b-4afc-a8d2-4c6ddffdc497',
name: 'folder2',
path: '2162f6ec_60f3_4339_be17_765a49d638c3.81950088_ec8b_4afc_a8d2_4c6ddffdc497',
creator: MOCK_MEMBERS[0],
creator: CURRENT_MEMBER,
}),
DocumentItemFactory({
id: '865fad9a-a6e8-4c5f-899d-7f845bf37a1d',
Expand All @@ -31,7 +32,7 @@ const MOCK_ITEMS: DiscriminatedItem[] = [
content: '',
},
},
creator: MOCK_MEMBERS[0],
creator: CURRENT_MEMBER,
}),
DocumentItemFactory({
id: '02ae7c43-aaf8-45b7-a665-829fcf160550',
Expand All @@ -42,19 +43,19 @@ const MOCK_ITEMS: DiscriminatedItem[] = [
content: '',
},
},
creator: MOCK_MEMBERS[0],
creator: CURRENT_MEMBER,
}),
FolderItemFactory({
id: 'c884c33a-f8db-4a20-9935-d10b8ca758a4',
name: 'folder3',
path: 'c884c33a_f8db_4a20_9935_d10b8ca758a4',
creator: MOCK_MEMBERS[1],
creator: MEMBERS.BOB,
}),
FolderItemFactory({
id: '5dd7ed57-59b2-4058-9e70-b171a5c50be9',
name: 'sharedFolder1',
path: 'c884c33a_f8db_4a20_9935_d10b8ca758a4.5dd7ed57_59b2_4058_9e70_b171a5c50be9',
creator: MOCK_MEMBERS[1],
creator: MEMBERS.BOB,
}),
DocumentItemFactory({
id: '676d82b9-5a4c-4127-9807-2ad19b073526',
Expand All @@ -65,33 +66,42 @@ const MOCK_ITEMS: DiscriminatedItem[] = [
content: '',
},
},
creator: MOCK_MEMBERS[1],
creator: MEMBERS.BOB,
}),
];

export const CALC_APP_ITEM = AppItemFactory({
id: '820fb440-66dc-44d9-b6b4-bd767ac6085f',
name: 'Calculator',
path: '820fb440_66dc_44d9_b6b4_bd767ac6085f',
creator: MOCK_MEMBERS[0],
});
export const CALC_APP_ITEM = PackedAppItemFactory(
{
id: '820fb440-66dc-44d9-b6b4-bd767ac6085f',
name: 'Calculator',
path: '820fb440_66dc_44d9_b6b4_bd767ac6085f',
creator: CURRENT_MEMBER,
},
{ permission: PermissionLevel.Admin },
);

export const APP_ITEM_WITH_PARENT = AppItemFactory({
id: 'd70ec385-e6b7-4665-b4ea-fd06badeccbc',
name: 'App with parent',
creator: MOCK_MEMBERS[0],
parentItem: MOCK_ITEMS[0],
});
export const APP_ITEM_WITH_PARENT = PackedAppItemFactory(
{
id: 'd70ec385-e6b7-4665-b4ea-fd06badeccbc',
name: 'App with parent',
creator: CURRENT_MEMBER,
parentItem: MOCK_ITEMS[0],
},
{ permission: PermissionLevel.Admin },
);

export const CALC_APP_ITEM_WITH_PARENT = AppItemFactory({
id: 'd70ec385-e6b7-4665-b4ea-fd06badeccdd',
name: 'Calculator with parent',
creator: MOCK_MEMBERS[0],
parentItem: MOCK_ITEMS[0],
});
export const CALC_APP_ITEM_WITH_PARENT = PackedAppItemFactory(
{
id: 'd70ec385-e6b7-4665-b4ea-fd06badeccdd',
name: 'Calculator with parent',
creator: CURRENT_MEMBER,
parentItem: MOCK_ITEMS[0],
},
{ permission: PermissionLevel.Admin },
);

export const ITEM_TO_EXPORT = PackedFolderItemFactory({
creator: MOCK_MEMBERS[0],
creator: CURRENT_MEMBER,
});

export default MOCK_ITEMS;
Loading
Loading