Skip to content
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
199 changes: 199 additions & 0 deletions client/cypress/e2e/home.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
/**
* E2E tests for Home page management: searching and filtering tasks and notes.
*/

const mockUser = {
userId: 1,
name: 'Test User',
email: 'test@example.com',
admin: false,
createdAt: '2026-01-01T00:00:00.000Z',
gravatarImageUrl: '',
lang: 'en'
};

const mockTasks = [
{
id: 1,
description: 'Buy groceries',
done: false,
highPriority: true,
dueDate: '2026-06-01',
dueDateFmt: 'Jun 1, 2026',
lastUpdate: '2026-05-01',
tag: 'personal',
urls: []
},
{
id: 2,
description: 'Write report',
done: false,
highPriority: false,
dueDate: '',
dueDateFmt: '',
lastUpdate: '2026-05-02',
tag: 'work',
urls: []
}
];

const mockNotes = [
{
id: 1,
title: 'Meeting notes',
description: 'Discuss quarterly goals',
url: null,
tag: 'work',
lastUpdate: '2026-05-01',
shared: false,
shareToken: null
},
{
id: 2,
title: 'Recipe',
description: 'Pasta carbonara recipe',
url: null,
tag: 'personal',
lastUpdate: '2026-05-02',
shared: false,
shareToken: null
}
];

const mockTags = ['personal', 'work'];

describe('Home Management', () => {
beforeEach(() => {
cy.intercept('GET', /\/rest\/user-sessions\/refresh/, {
statusCode: 200,
body: { token: 'fake-jwt-token', ...mockUser }
}).as('refreshToken');

cy.intercept('GET', /\/rest\/home\/tasks\/tags/, {
statusCode: 200,
body: mockTags
}).as('getTags');

cy.intercept('GET', /\/rest\/tasks$/, {
statusCode: 200,
body: mockTasks
}).as('getTasks');

cy.intercept('GET', /\/rest\/notes$/, {
statusCode: 200,
body: mockNotes
}).as('getNotes');

cy.visit('/home', {
onBeforeLoad(win) {
win.localStorage.setItem('TASKNOTE-TOKEN', 'fake-jwt-token');
win.localStorage.setItem('TASKNOTE-USER', JSON.stringify(mockUser));
}
});
});

/**
* Home page display
*/
describe('Display', () => {
it('shows tasks and notes after loading', () => {
cy.wait('@getTasks');
cy.wait('@getNotes');

cy.contains('Buy groceries').should('be.visible');
cy.contains('Write report').should('be.visible');
cy.contains('Meeting notes').should('be.visible');
cy.contains('Recipe').should('be.visible');
});
});

/**
* Search / text filtering
*/
describe('Search', () => {
beforeEach(() => {
cy.wait('@getTasks');
cy.wait('@getNotes');
});

it('filters items by search text matching a task description', () => {
cy.get('input[placeholder="Filter tasks & notes"]').type('groceries');

cy.contains('Buy groceries').should('be.visible');
cy.contains('Write report').should('not.exist');
cy.contains('Meeting notes').should('not.exist');
cy.contains('Recipe').should('not.exist');
});

it('filters items by search text matching a note title', () => {
cy.get('input[placeholder="Filter tasks & notes"]').type('Meeting');

cy.contains('Meeting notes').should('be.visible');
cy.contains('Buy groceries').should('not.exist');
cy.contains('Recipe').should('not.exist');
});

it('restores all items after clearing the search', () => {
cy.get('input[placeholder="Filter tasks & notes"]').type('groceries');
cy.contains('Write report').should('not.exist');

cy.get('input[placeholder="Filter tasks & notes"]').clear();

cy.contains('Buy groceries').should('be.visible');
cy.contains('Meeting notes').should('be.visible');
});
});

/**
* Dropdown filter
*/
describe('Dropdown Filter', () => {
beforeEach(() => {
cy.wait('@getTasks');
cy.wait('@getNotes');
});

it('shows only tasks when Tasks filter is selected', () => {
cy.get('[data-testid="dropdown-tag-filter"]').click();
cy.contains('Tasks').click();

cy.contains('Buy groceries').should('be.visible');
cy.contains('Write report').should('be.visible');
cy.contains('Meeting notes').should('not.exist');
cy.contains('Recipe').should('not.exist');
});

it('shows only notes when Notes filter is selected', () => {
cy.get('[data-testid="dropdown-tag-filter"]').click();
cy.contains('Notes').click();

cy.contains('Meeting notes').should('be.visible');
cy.contains('Recipe').should('be.visible');
cy.contains('Buy groceries').should('not.exist');
cy.contains('Write report').should('not.exist');
});

it('shows everything when Everything filter is selected', () => {
cy.get('[data-testid="dropdown-tag-filter"]').click();
cy.contains('Tasks').click();

cy.get('[data-testid="dropdown-tag-filter"]').click();
cy.contains('Everything').click();

cy.contains('Buy groceries').should('be.visible');
cy.contains('Meeting notes').should('be.visible');
});

it('filters by tag when a tag is selected', () => {
cy.wait('@getTags');

cy.get('[data-testid="dropdown-tag-filter"]').click();
cy.contains('#personal').click();

cy.contains('Buy groceries').should('be.visible');
cy.contains('Recipe').should('be.visible');
cy.contains('Write report').should('not.exist');
cy.contains('Meeting notes').should('not.exist');
});
});
});
Loading