Skip to content

Commit

Permalink
tests: added search tags tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FoHoOV committed Mar 6, 2024
1 parent f350e8a commit a2ee301
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
5 changes: 4 additions & 1 deletion frontend/src/routes/user/search-tags/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@
{/snippet}
</EnhancedForm>

<div class="grid grid-cols-1 gap-2 md:grid-cols-2 xl:grid-cols-3">
<div
class="grid grid-cols-1 gap-2 md:grid-cols-2 xl:grid-cols-3"
data-testid="search-tags-results-wrapper"
>
{#each todoCategoriesStore.current as category (category.id)}
{#each category.items as todo (todo.id)}
<TodoItem {todo} showCategoryInfo={true} showProjectsInfo={true} draggable={false}></TodoItem>
Expand Down
52 changes: 52 additions & 0 deletions frontend/tests/fixtures/search-tags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import type { IPage } from './IPage';
import type { EnhancedPage } from './test';
import { test as todoItemTest } from './/todo-item/todo-item';
export type SearchTagsUtils = {
page: SearchTagsPage;
};

export class SearchTagsPage implements IPage {
#enhancedPage: EnhancedPage;

constructor(enhancedPage: EnhancedPage) {
this.#enhancedPage = enhancedPage;
}
async goto() {
await this.#enhancedPage.goto('/user/search-tags');
}

async search({ tagName, projectId }: { tagName: string; projectId?: number }) {
await this.#enhancedPage.getByPlaceholder('tag name').click();
await this.#enhancedPage.getByPlaceholder('tag name').fill(tagName);
await this.#enhancedPage.getByPlaceholder('tag name').press('Tab');
projectId && (await this.#enhancedPage.getByPlaceholder('project id (Optional)').fill('1'));
await this.#enhancedPage.getByRole('button', { name: 'Search' }).click();
}

getResultsWrapperLocator() {
return this.#enhancedPage.getByTestId('search-tags-results-wrapper');
}

async expectNotFoundError() {
await this.#enhancedPage
.getByRole('alert')
.filter({
hasText:
"tag not found or doesn't belong to user or you don't have the permission to perform the requested action"
})
.waitFor({ state: 'visible' });
}
}

export const test = todoItemTest.extend<{
searchTagsUtils: SearchTagsUtils;
}>({
// eslint-disable-next-line @typescript-eslint/no-unused-vars
searchTagsUtils: async ({ enhancedPage, auth }, use) => {
// I have to include auth because we need to be authenticated to use this page
const searchTags = new SearchTagsPage(enhancedPage);
await use({
page: searchTags
});
}
});
29 changes: 29 additions & 0 deletions frontend/tests/routes/user/search-tags/search-tags.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { expect } from '@playwright/test';
import { test } from '../../../fixtures/search-tags';

test('search for tags that exist', async ({ todoItemUtils, searchTagsUtils }) => {
const t1 = await todoItemUtils.helpers.createTodoItem();

await todoItemUtils.page.tags.create({
tag: 'test',
todoId: t1.todoId
});

await searchTagsUtils.page.goto();

await searchTagsUtils.page.search({
tagName: 'test'
});

await expect(searchTagsUtils.page.getResultsWrapperLocator()).toContainText(`${t1.todoId}`);
});

test("search for tags that don't exist", async ({ searchTagsUtils }) => {
await searchTagsUtils.page.goto();

await searchTagsUtils.page.search({
tagName: 'test'
});

await searchTagsUtils.page.expectNotFoundError();
});

0 comments on commit a2ee301

Please sign in to comment.