-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Answer:17 #1412
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
Open
lukasss88
wants to merge
1
commit into
tomalaforge:main
Choose a base branch
from
lukasss88:router-test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Answer:17 #1412
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,33 +1,73 @@ | ||
| import { provideRouter } from '@angular/router'; | ||
| import { AppComponent } from './app.component'; | ||
| import { appRoutes } from './app.routes'; | ||
|
|
||
| describe(AppComponent.name, () => { | ||
| beforeEach(() => { | ||
| cy.mount(AppComponent, { | ||
| providers: [provideRouter(appRoutes)], | ||
| }); | ||
| cy.get('nav a:first').click(); | ||
| }); | ||
|
|
||
| describe('Given no search criteria', () => { | ||
| it('Then shows error message and disabled button', () => { | ||
| //todo | ||
| cy.get('input[name=bookName]').as('bookControl').clear(); | ||
| cy.contains('Search criteria is required!'); | ||
|
|
||
| cy.get('@bookControl').type('kill'); | ||
| cy.contains('Search criteria is required!').should('not.exist'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Given a search criteria with no book match', () => { | ||
| it('Then shows No book found', () => { | ||
| //todo | ||
| cy.get('input[name=bookName]').as('bookControl').type('NonExistingBook'); | ||
| cy.get('button').contains('Borrow').click(); | ||
|
|
||
| cy.get('[data-testid="no-book-found-msg"]').should('be.visible'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Given a search criteria with one book match', () => { | ||
| it('Then shows One book and no error', () => { | ||
| //todo | ||
| cy.get('input[name=bookName]').as('bookControl').type('1984'); | ||
| cy.get('button').contains('Borrow').click(); | ||
|
|
||
| cy.get('[data-testid="search-error-msg"]').should('not.exist'); | ||
| cy.contains('1984 by George Orwell').should('be.visible'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Given a search criteria in Uppercase with one book match', () => { | ||
| it('Then shows One book and no error', () => { | ||
| //todo | ||
| cy.get('input[name=bookName]').as('bookControl').type('HOBBIT'); | ||
| cy.get('button').contains('Borrow').click(); | ||
|
|
||
| cy.get('[data-testid="search-error-msg"]').should('not.exist'); | ||
| cy.contains('The Hobbit by J.R.R. Tolkien').should('be.visible'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Given a search criteria with multple books matches', () => { | ||
| it('Then shows a list of books', () => { | ||
| //todo | ||
| cy.get('input[name=bookName]').as('bookControl').type('the'); | ||
| cy.get('button').contains('Borrow').click(); | ||
|
|
||
| cy.get('ul li').should('have.length.greaterThan', 1); | ||
|
|
||
| cy.contains('The Hobbit by J.R.R. Tolkien').should('be.visible'); | ||
| cy.contains('The Great Gats by F. Scott Fitzgerald').should('be.visible'); | ||
| cy.contains('The Lord of the Rings by J.R.R. Tolkien').should( | ||
| 'be.visible', | ||
| ); | ||
| cy.contains('The Catcher in the Rye by J.D. Salinger').should( | ||
| 'be.visible', | ||
| ); | ||
| cy.contains('The Hunger Games').should('be.visible'); | ||
| cy.contains( | ||
| "Harry Potter and the Philosopher's Stone by J.K. Rowling", | ||
| ).should('be.visible'); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,31 +1,86 @@ | ||
| describe('AppComponent', () => { | ||
| import { render, screen } from '@testing-library/angular'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import { AppComponent } from './app.component'; | ||
| import { appRoutes } from './app.routes'; | ||
| import exp = require('constants'); | ||
|
|
||
| describe.only('AppComponent', () => { | ||
| const search = async (text: string) => { | ||
| await render(AppComponent, { routes: appRoutes }); | ||
|
|
||
| const searchControl = screen.getByRole('textbox', { | ||
| name: /search book by author or title/i, | ||
| }); | ||
| const borrowBtn = screen.getByRole('button', { name: /borrow/i }); | ||
|
|
||
| await userEvent.type(searchControl, text); | ||
| await userEvent.click(borrowBtn); | ||
| }; | ||
|
|
||
| describe('Given no search criteria', () => { | ||
| it('Then shows error message and disabled button', async () => { | ||
| //todo | ||
| await render(AppComponent, { routes: appRoutes }); | ||
|
|
||
| const searchControl = screen.getByRole('textbox', { | ||
| name: /search book by author or title/i, | ||
| }); | ||
| userEvent.clear(searchControl); | ||
|
|
||
| expect(screen.getByTestId('search-error-msg')).toBeInTheDocument(); | ||
| expect(screen.getByRole('button', { name: /borrow/i })).toBeDisabled(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Given a search criteria with no book match', () => { | ||
| it('Then shows No book found', async () => { | ||
| //todo | ||
| await search('NonExistingBook'); | ||
|
|
||
| expect(screen.getByTestId('no-book-found-msg')).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Given a search criteria with one book match', () => { | ||
| it('Then shows One book and no error', async () => { | ||
| //todo | ||
| await search('1984'); | ||
|
|
||
| expect(screen.queryByTestId('search-error-msg')).not.toBeInTheDocument(); | ||
| expect(screen.getByText(/1984 by George Orwell/i)).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Given a search criteria in Uppercase with one book match', () => { | ||
| it('Then shows One book and no error', async () => { | ||
| //todo | ||
| await search('HOBBIT'); | ||
|
|
||
| expect(screen.queryByTestId('search-error-msg')).not.toBeInTheDocument(); | ||
| expect( | ||
| screen.getByText(/The Hobbit by J.R.R. Tolkien/i), | ||
| ).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Given a search criteria with multple books matches', () => { | ||
| it('Then shows a list of books', async () => { | ||
| //todo | ||
| await search('the'); | ||
|
|
||
| expect( | ||
| screen.getByText(/The Hobbit by J.R.R. Tolkien/i), | ||
| ).toBeInTheDocument(); | ||
| expect( | ||
| screen.getByText(/The Catcher in the Rye by J.D. Salinger/i), | ||
| ).toBeInTheDocument(); | ||
| expect( | ||
| screen.getByText(/The Lord of the Rings by J.R.R. Tolkien/i), | ||
| ).toBeInTheDocument(); | ||
| expect( | ||
| screen.getByText(/The Great Gats by F. Scott Fitzgerald/i), | ||
| ).toBeInTheDocument(); | ||
| expect( | ||
| screen.getByText( | ||
| /Harry Potter and the Philosopher's Stone by J.K. Rowling/i, | ||
| ), | ||
| ).toBeInTheDocument(); | ||
| expect(screen.getByText(/The Hunger Games/i)).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The real fix is to exclude cypress test from this file,
but i don't know why this tsconfig was created in the first place, so i will just remove them
thanks 🙏