Skip to content

Commit

Permalink
fix: fix or remove tests that were failing (#690)
Browse files Browse the repository at this point in the history
* fix: fix or remove tests that were failing

* chore: fix issues with build test

---------

Co-authored-by: spaenleh <[email protected]>
  • Loading branch information
juancarlosfarah and spaenleh authored May 8, 2024
1 parent 1c9b538 commit f84ceea
Show file tree
Hide file tree
Showing 3 changed files with 283 additions and 85 deletions.
182 changes: 174 additions & 8 deletions cypress/e2e/shuffle.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import {
ANOTHER_FOLDER_WITH_FIVE_ORDERED_SUBFOLDER_ITEMS,
FOLDER_WITH_FIVE_ORDERED_SUBFOLDER_ITEMS,
YET_ANOTHER_FOLDER_WITH_FIVE_ORDERED_SUBFOLDER_ITEMS,
} from '../fixtures/items.ts';
import { MEMBERS } from '../fixtures/members.ts';
import { expectFolderLayout } from '../support/integrationUtils.ts';
Expand Down Expand Up @@ -64,7 +65,12 @@ describe('Shuffle', () => {
});

// shuffled order is always the same for a given member + item id
const shuffledOrder = [2, 4, 5, 3, 1];
const shuffledOrder = [2, 4, 1, 3, 5];

// last should always be last
expect(shuffledOrder[shuffledOrder.length - 1]).to.equal(
shuffledOrder.length,
);

cy.get(`.${buildTreeItemClass(root.id)}`)
.siblings(`ul.${TREE_NODE_GROUP_CLASS}:first`)
Expand Down Expand Up @@ -97,7 +103,12 @@ describe('Shuffle', () => {
});

// shuffled order is always the same for a given member + item id
const shuffledOrder = [2, 4, 5, 3, 1];
const shuffledOrder = [2, 4, 1, 3, 5];

// last should always be last
expect(shuffledOrder[shuffledOrder.length - 1]).to.equal(
shuffledOrder.length,
);

cy.get(`.${buildTreeItemClass(root.id)}`)
.siblings(`ul.${TREE_NODE_GROUP_CLASS}:first`)
Expand Down Expand Up @@ -130,7 +141,12 @@ describe('Shuffle', () => {
});

// shuffled order is always the same for a given member + item id
const shuffledOrder = [2, 4, 5, 3, 1];
const shuffledOrder = [2, 4, 1, 3, 5];

// last should always be last
expect(shuffledOrder[shuffledOrder.length - 1]).to.equal(
shuffledOrder.length,
);

cy.get(`.${buildTreeItemClass(root.id)}`)
.siblings(`ul.${TREE_NODE_GROUP_CLASS}:first`)
Expand Down Expand Up @@ -163,9 +179,14 @@ describe('Shuffle', () => {
});

// shuffled order is always the same for a given member + item id
// this is the value for the other item: [ 2, 4, 5, 3, 1 ]
// this is the value for the other item: [2, 4, 1, 3, 5]
const shuffledOrder = [1, 4, 3, 2, 5];

// last should always be last
expect(shuffledOrder[shuffledOrder.length - 1]).to.equal(
shuffledOrder.length,
);

cy.get(`.${buildTreeItemClass(root.id)}`)
.siblings(`ul.${TREE_NODE_GROUP_CLASS}:first`)
.children('li')
Expand Down Expand Up @@ -210,8 +231,13 @@ describe('Shuffle', () => {
});

// shuffled order is always the same for a given member + item id
// this is the value for Anna: [2, 4, 5, 3, 1]
const shuffledOrder = [1, 5, 3, 4, 2];
// this is the value for Anna: [2, 4, 1, 3, 5]
const shuffledOrder = [1, 2, 3, 4, 5];

// last should always be last
expect(shuffledOrder[shuffledOrder.length - 1]).to.equal(
shuffledOrder.length,
);

cy.get(`.${buildTreeItemClass(root.id)}`)
.siblings(`ul.${TREE_NODE_GROUP_CLASS}:first`)
Expand Down Expand Up @@ -244,10 +270,108 @@ describe('Shuffle', () => {
});

// shuffled order is always the same for a given member + item id
// this is the value for the other item: [1, 5, 3, 4, 2]
// and this is the value for Anna for this item: [ 1, 4, 3, 2, 5 ]
// this is the value for the other item: [1, 2, 3, 4, 5]
// and this is the value for Anna for this item: [1, 4, 3, 2, 5]
const shuffledOrder = [3, 4, 2, 1, 5];

// last should always be last
expect(shuffledOrder[shuffledOrder.length - 1]).to.equal(
shuffledOrder.length,
);

cy.get(`.${buildTreeItemClass(root.id)}`)
.siblings(`ul.${TREE_NODE_GROUP_CLASS}:first`)
.children('li')
.each(($li, index) => {
// assert the text of each li matches the expected order
cy.wrap($li).should(
'have.text',
ANOTHER_FOLDER_WITH_FIVE_ORDERED_SUBFOLDER_ITEMS.items[
shuffledOrder[index]
].name,
);
});
});
});

describe('Cedric', () => {
beforeEach(() => {
cy.setUpApi({
currentMember: MEMBERS.CEDRIC,
items: [
...YET_ANOTHER_FOLDER_WITH_FIVE_ORDERED_SUBFOLDER_ITEMS.items,
...ANOTHER_FOLDER_WITH_FIVE_ORDERED_SUBFOLDER_ITEMS.items,
...FOLDER_WITH_FIVE_ORDERED_SUBFOLDER_ITEMS.items,
],
});
});

it('displays item with children shuffled differently for a different user', () => {
const root = FOLDER_WITH_FIVE_ORDERED_SUBFOLDER_ITEMS.items[0];
cy.visit(
buildContentPagePath({
rootId: root.id,
itemId: root.id,
searchParams: 'shuffle=true',
}),
);

cy.get(`.${FOLDER_NAME_TITLE_CLASS}`).should('contain', root.name);

expectFolderLayout({
rootId: root.id,
items: FOLDER_WITH_FIVE_ORDERED_SUBFOLDER_ITEMS.items,
});

// shuffled order is always the same for a given member + item id
// this is the value for Anna: [2, 4, 1, 3, 5]
// and this is the value for Bob: [1, 2, 3, 4, 5]
const shuffledOrder = [3, 2, 1, 4, 5];

// last should always be last
expect(shuffledOrder[shuffledOrder.length - 1]).to.equal(
shuffledOrder.length,
);

cy.get(`.${buildTreeItemClass(root.id)}`)
.siblings(`ul.${TREE_NODE_GROUP_CLASS}:first`)
.children('li')
.each(($li, index) => {
// assert the text of each li matches the expected order
cy.wrap($li).should(
'have.text',
FOLDER_WITH_FIVE_ORDERED_SUBFOLDER_ITEMS.items[shuffledOrder[index]]
.name,
);
});
});

it('displays item with children shuffled differently for a different user and different item', () => {
const root = ANOTHER_FOLDER_WITH_FIVE_ORDERED_SUBFOLDER_ITEMS.items[0];
cy.visit(
buildContentPagePath({
rootId: root.id,
itemId: root.id,
searchParams: 'shuffle=true',
}),
);

cy.get(`.${FOLDER_NAME_TITLE_CLASS}`).should('contain', root.name);

expectFolderLayout({
rootId: root.id,
items: ANOTHER_FOLDER_WITH_FIVE_ORDERED_SUBFOLDER_ITEMS.items,
});

// shuffled order is always the same for a given member + item id
// this is the value for the other item: [3, 4, 2, 1, 5]
const shuffledOrder = [3, 2, 1, 4, 5];

// last should always be last
expect(shuffledOrder[shuffledOrder.length - 1]).to.equal(
shuffledOrder.length,
);

cy.get(`.${buildTreeItemClass(root.id)}`)
.siblings(`ul.${TREE_NODE_GROUP_CLASS}:first`)
.children('li')
Expand All @@ -261,5 +385,47 @@ describe('Shuffle', () => {
);
});
});

it('displays item with children shuffled differently for a different user and another different item', () => {
const root =
YET_ANOTHER_FOLDER_WITH_FIVE_ORDERED_SUBFOLDER_ITEMS.items[0];
cy.visit(
buildContentPagePath({
rootId: root.id,
itemId: root.id,
searchParams: 'shuffle=true',
}),
);

cy.get(`.${FOLDER_NAME_TITLE_CLASS}`).should('contain', root.name);

expectFolderLayout({
rootId: root.id,
items: YET_ANOTHER_FOLDER_WITH_FIVE_ORDERED_SUBFOLDER_ITEMS.items,
});

// shuffled order is always the same for a given member + item id
// this is the value for the first other item: [3, 4, 2, 1, 5]
// and this is the value for the second other item: [3, 2, 1, 4, 5]
const shuffledOrder = [3, 4, 1, 2, 5];

// last should always be last
expect(shuffledOrder[shuffledOrder.length - 1]).to.equal(
shuffledOrder.length,
);

cy.get(`.${buildTreeItemClass(root.id)}`)
.siblings(`ul.${TREE_NODE_GROUP_CLASS}:first`)
.children('li')
.each(($li, index) => {
// assert the text of each li matches the expected order
cy.wrap($li).should(
'have.text',
YET_ANOTHER_FOLDER_WITH_FIVE_ORDERED_SUBFOLDER_ITEMS.items[
shuffledOrder[index]
].name,
);
});
});
});
});
100 changes: 66 additions & 34 deletions cypress/fixtures/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,30 +623,6 @@ export const FOLDER_WITH_FIVE_ORDERED_SUBFOLDER_ITEMS: { items: MockItem[] } = {
showChatbox: false,
},
},

// descendants
{
...DEFAULT_FOLDER_ITEM,
id: 'fdf09f5a-5688-11eb-ae93-0242ac130005',
name: 'child of child folder 2',
path: 'ecafbd2a_5688_11eb_ae93_0242ac130002.fdf09f5a_5688_11eb_ae93_0242ac130003.fdf09f5a_5688_11eb_ae93_0242ac130005',
settings: {
isPinned: true,
showChatbox: false,
},
},
{
...DEFAULT_FOLDER_ITEM,
id: 'fdf09f5a-5688-11eb-ae93-0242ac130006',
name: 'document inside of child folder',
type: 'document',
extra: { document: { content: 'hello I am a document' } },
path: 'ecafbd2a_5688_11eb_ae93_0242ac130002.fdf09f5a_5688_11eb_ae93_0242ac130003.fdf09f5a_5688_11eb_ae93_0242ac130005.fdf09f5a_5688_11eb_ae93_0242ac130006',
settings: {
isPinned: true,
showChatbox: false,
},
},
],
};

Expand Down Expand Up @@ -727,29 +703,85 @@ export const ANOTHER_FOLDER_WITH_FIVE_ORDERED_SUBFOLDER_ITEMS: {
showChatbox: false,
},
},
],
};

// descendants
export const YET_ANOTHER_FOLDER_WITH_FIVE_ORDERED_SUBFOLDER_ITEMS: {
items: MockItem[];
} = {
items: [
// root
{
...DEFAULT_FOLDER_ITEM,
id: 'fdf09f5a-5688-11eb-ae93-0242ac130005',
name: 'child of child folder 2',
path: 'acafbd2a_5688_11eb_ae93_0242ac130002.fdf09f5a_5688_11eb_ae93_0242ac130003.fdf09f5a_5688_11eb_ae93_0242ac130005',
id: 'acafbd2a-5688-11eb-ae93-0242ac130012',
name: 'parent folder',
path: 'acafbd2a_5688_11eb_ae93_0242ac130012',
extra: {
[ItemType.FOLDER]: {
childrenOrder: [
'fdf09f5a-5688-11eb-ae93-0242ac130013',
'fdf09f5a-5688-11eb-ae93-0242ac130014',
'fdf09f5a-5688-11eb-ae93-0242ac130017',
'fdf09f5a-5688-11eb-ae93-0242ac130018',
'fdf09f5a-5688-11eb-ae93-0242ac130019',
],
},
},
settings: {
isPinned: true,
isPinned: false,
showChatbox: false,
},
},
// children (need to be in order to respect test)
{
...DEFAULT_FOLDER_ITEM,
id: 'fdf09f5a-5688-11eb-ae93-0242ac130006',
name: 'document inside of child folder',
type: 'document',
extra: { document: { content: 'hello I am a document' } },
path: 'acafbd2a_5688_11eb_ae93_0242ac130002.fdf09f5a_5688_11eb_ae93_0242ac130003.fdf09f5a_5688_11eb_ae93_0242ac130005.fdf09f5a_5688_11eb_ae93_0242ac130006',
id: 'fdf09f5a-5688-11eb-ae93-0242ac130013',
name: 'child folder 1',
path: 'acafbd2a_5688_11eb_ae93_0242ac130012.fdf09f5a_5688_11eb_ae93_0242ac130013',
settings: {
isPinned: true,
showChatbox: false,
},
},
{
...DEFAULT_FOLDER_ITEM,
id: 'fdf09f5a-5688-11eb-ae93-0242ac130014',
name: 'child folder 2',
path: 'acafbd2a_5688_11eb_ae93_0242ac130012.fdf09f5a_5688_11eb_ae93_0242ac130014',
settings: {
isPinned: false,
showChatbox: false,
},
},
{
...DEFAULT_FOLDER_ITEM,
id: 'fdf09f5a-5688-11eb-ae93-0242ac130017',
name: 'child folder 3',
path: 'acafbd2a_5688_11eb_ae93_0242ac130012.fdf09f5a-5688-11eb-ae93-0242ac130017',
settings: {
isPinned: false,
showChatbox: false,
},
},
{
...DEFAULT_FOLDER_ITEM,
id: 'fdf09f5a-5688-11eb-ae93-0242ac130018',
name: 'child folder 4',
path: 'acafbd2a_5688_11eb_ae93_0242ac130012.fdf09f5a-5688-11eb-ae93-0242ac130018',
settings: {
isPinned: false,
showChatbox: false,
},
},
{
...DEFAULT_FOLDER_ITEM,
id: 'fdf09f5a-5688-11eb-ae93-0242ac130019',
name: 'child folder 5',
path: 'acafbd2a_5688_11eb_ae93_0242ac130012.fdf09f5a-5688-11eb-ae93-0242ac130019',
settings: {
isPinned: false,
showChatbox: false,
},
},
],
};
Loading

0 comments on commit f84ceea

Please sign in to comment.