-
Notifications
You must be signed in to change notification settings - Fork 0
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
361 fix home specs #373
Merged
Merged
361 fix home specs #373
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7c7ea59
correct the customApiIntercept `loading` case
alishaevn f9d4eae
fix the first home spec
alishaevn 940b731
refactor the home page specs
alishaevn 4111930
correctly testing for a search with no query
alishaevn 733458a
all search bar tests from the home e2e spec pass
alishaevn 531182c
formatting
alishaevn 9c7f21f
Merge branch 'main' into 361-fix-home-specs
alishaevn 6113560
properly throw errors from fetcher
alishaevn fd52f07
correctly accounting for errors on the home page spec
alishaevn 808b838
all 7 home specs are passing
alishaevn 11f0bc9
remove now irrelevant code
alishaevn 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 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 |
---|---|---|
|
@@ -23,12 +23,18 @@ module.exports = defineConfig({ | |
env: { | ||
TEST_SCIENTIST_USER: '[email protected]', | ||
TEST_SCIENTIST_PW: '!test1234', | ||
NEXT_PUBLIC_PROVIDER_NAME: 'acme', | ||
NEXT_PUBLIC_PROVIDER_ID: '572' | ||
NEXT_PUBLIC_PROVIDER_NAME: process.env.NEXT_PUBLIC_PROVIDER_NAME, | ||
NEXT_PUBLIC_PROVIDER_ID: process.env.NEXT_PUBLIC_PROVIDER_ID, | ||
NEXT_PUBLIC_TOKEN: process.env.NEXT_PUBLIC_TOKEN, | ||
CYPRESS_SEARCH_QUERY: 'test', | ||
// importing the `API_PER_PAGE` variable from the constants file throws | ||
// errors since this file doesn't follow ES6 syntax. if the value is | ||
// changed in constants, it needs to be updated here too | ||
API_PER_PAGE: 2000, | ||
}, | ||
reporter: 'junit', | ||
reporterOptions: { | ||
mochaFile: 'cypress/results/results-[hash].xml', | ||
toConsole: true, | ||
}, | ||
}); | ||
}) |
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 |
---|---|---|
@@ -1,67 +1,120 @@ | ||
describe('Viewing Home page', () => { | ||
describe('Navigating to the home page', () => { | ||
// declare variables that can be used to change how the response is intercepted. | ||
let loading | ||
let data = 'services/wares.json' | ||
let error | ||
let featuredServices | ||
|
||
beforeEach(() => { | ||
// Intercept the response from the endpoint to view all requests | ||
cy.customApiIntercept({ | ||
action: 'GET', | ||
alias: 'useAllWares', | ||
requestURL: `/providers/${Cypress.env('NEXT_PUBLIC_PROVIDER_ID')}/wares.json`, | ||
data: featuredServices, | ||
defaultFixture: 'services/wares.json', | ||
emptyFixture: 'services/no-wares.json', | ||
loading, | ||
error | ||
data, | ||
error, | ||
requestURL: '/wares.json?per_page=2000', | ||
}) | ||
|
||
cy.visit('/') | ||
}) | ||
|
||
|
||
context('featured services list is loading', () => { | ||
before(() => { | ||
loading = true | ||
describe('renders a search bar', () => { | ||
it('with no query', () => { | ||
cy.get("form[data-cy='search-bar']").should('exist').then(() => { | ||
cy.log('Search bar renders successfully.') | ||
}) | ||
}) | ||
it('should show 3 placeholder cards loading', () => { | ||
cy.get('p.placeholder-glow').should('be.visible').then(() => { | ||
cy.log('Loading text displays correctly.') | ||
|
||
context('able to navigate to "/browse"', () => { | ||
const testSetup = ({ data, defaultFixture, requestURL }) => { | ||
cy.customApiIntercept({ | ||
alias: 'useFilteredWares', | ||
data, | ||
error, | ||
requestURL, | ||
}) | ||
} | ||
|
||
it('with a blank query', () => { | ||
testSetup({ | ||
data: 'services/wares.json', | ||
requestURL: '/wares.json?per_page=2000&q=', | ||
}) | ||
|
||
cy.get('button.search-button').click() | ||
cy.url().should('include', '/browse') | ||
cy.url().should('not.include', '?') | ||
cy.get('input.search-bar').should('have.value', '') | ||
cy.get(".card[data-cy='item-card']").should('be.visible') | ||
}) | ||
|
||
it('with a valid query term', () => { | ||
testSetup({ | ||
data: 'services/filtered-wares.json', | ||
requestURL: `/wares.json?per_page=2000&q=${Cypress.env('CYPRESS_SEARCH_QUERY')}`, | ||
}) | ||
|
||
cy.get('input.search-bar').type(Cypress.env('CYPRESS_SEARCH_QUERY')) | ||
cy.get('button.search-button').click() | ||
cy.url().should('include', `/browse?q=${Cypress.env('CYPRESS_SEARCH_QUERY')}`) | ||
cy.get('input.search-bar').should('have.value', Cypress.env('CYPRESS_SEARCH_QUERY')) | ||
cy.get(".card[data-cy='item-card']").should('be.visible') | ||
}) | ||
|
||
it('with an invalid query term', () => { | ||
const invalidQuery = 'asdfghjk' | ||
testSetup({ | ||
data: 'services/no-wares.json', | ||
requestURL: `/wares.json?per_page=2000&q=${invalidQuery}`, | ||
}) | ||
|
||
cy.get('input.search-bar').type(invalidQuery) | ||
cy.get('button.search-button').click() | ||
cy.url().should('include', `/browse?q=${invalidQuery}`) | ||
cy.get('input.search-bar').should('have.value', invalidQuery) | ||
cy.get("p[data-cy='no-results']").should('contain', `Your search for ${invalidQuery} returned no results`) | ||
}) | ||
}) | ||
}) | ||
|
||
context('error while making a request to the api', () => { | ||
before(() => { | ||
loading = false | ||
error = true | ||
}) | ||
it('should show an error message.', () => { | ||
cy.get("div[role='alert']").should('be.visible').then(() => { | ||
cy.log('Successfully hits an error.') | ||
describe('renders a text box', () => { | ||
it('showing the about text.', () => { | ||
cy.get("section[data-cy='about-us-section']").should('exist').then(() => { | ||
cy.log('Abouttext renders successfully.') | ||
}) | ||
}) | ||
}) | ||
|
||
context('home page components are loading successfully, &', () => { | ||
before(() => { | ||
featuredServices = true | ||
error = false | ||
}) | ||
it('should show the search bar.', () => { | ||
cy.get("form[data-cy='search-bar']").should('exist').then(() => { | ||
cy.log('Search bar renders successfully.') | ||
describe('makes a call to the api', () => { | ||
context('which when given an invalid access token', () => { | ||
before(() => { | ||
data = undefined | ||
error = { | ||
body: { | ||
message: 'No access token provided.', | ||
}, | ||
statusCode: 403, | ||
} | ||
}) | ||
|
||
it('shows an error message', () => { | ||
cy.get("div[role='alert']").should('be.visible').then(() => { | ||
cy.log('Successfully hits an error.') | ||
}) | ||
cy.get("div[role='alert']").contains('No access token provided.') | ||
}) | ||
}) | ||
it('should show the about text.', () => { | ||
cy.get("section[data-cy='about-us-section']").should('exist').then(() => { | ||
cy.log('Abouttext renders successfully.') | ||
|
||
context('which when returns no error or data', () => { | ||
it('shows 3 placeholder cards loading', () => { | ||
cy.get('p.placeholder-glow').should('have.length', 3).then(() => { | ||
cy.log('Loading text displays correctly.') | ||
}) | ||
}) | ||
}) | ||
it('should show the featured services cards.', () => { | ||
cy.get("div[data-cy='item-group']").should('exist').then(() => { | ||
cy.log('Status bar renders successfully.') | ||
|
||
context('which when returns data', () => { | ||
it('shows the featured services cards', () => { | ||
cy.get("div[data-cy='item-group']").should('exist').then(() => { | ||
cy.log('Status bar renders successfully.') | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
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,22 @@ | ||
{ | ||
"ware_refs": [ | ||
{ | ||
"id": 3456, | ||
"slug": "test-ware", | ||
"name": "Test Ware", | ||
"snippet": "Here is a test ware snippet.", | ||
"urls": { | ||
"promo_image": "https://y.yarn.co/193fa4ae-a245-4f7a-ac9d-64bbebb18c8d_screenshot.jpg" | ||
} | ||
}, | ||
{ | ||
"id": 4567, | ||
"slug": "another-test-ware", | ||
"name": "Another Test Ware", | ||
"snippet": "Another test snippet.", | ||
"urls": { | ||
"promo_image": "https://cdn.drawception.com/images/panels/2017/7-2/jtqKRKSpyj-6.png" | ||
} | ||
} | ||
] | ||
} |
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
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.
without this, we are only getting the placeholder cards on the homepage, instead of the error notice.
if we use
return
instead ofthrow
, then the useSWR hook would incorrectly get the error as the data property: