-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
29
frontend/tests/routes/user/search-tags/search-tags.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |