-
-
Notifications
You must be signed in to change notification settings - Fork 550
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #306 from QAComet/qacomet/search-tests
Added tests for search
- Loading branch information
Showing
10 changed files
with
270 additions
and
9 deletions.
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 |
---|---|---|
@@ -0,0 +1,117 @@ | ||
const dotenv = require("dotenv"); | ||
|
||
let ENV_FILE_NAME = ""; | ||
switch (process.env.NODE_ENV) { | ||
case "production": | ||
ENV_FILE_NAME = ".env.production"; | ||
break; | ||
case "staging": | ||
ENV_FILE_NAME = ".env.staging"; | ||
break; | ||
case "test": | ||
ENV_FILE_NAME = ".env.test"; | ||
break; | ||
case "development": | ||
default: | ||
ENV_FILE_NAME = ".env"; | ||
break; | ||
} | ||
|
||
try { | ||
dotenv.config({ path: process.cwd() + "/" + ENV_FILE_NAME }); | ||
} catch (e) {} | ||
|
||
// CORS when consuming Medusa from admin | ||
const ADMIN_CORS = | ||
process.env.ADMIN_CORS || "http://localhost:7000,http://localhost:7001"; | ||
|
||
// CORS to avoid issues when consuming Medusa from a client | ||
const STORE_CORS = process.env.STORE_CORS || "http://localhost:8000"; | ||
|
||
const DATABASE_URL = | ||
process.env.DATABASE_URL || "postgres://medusa:password@localhost/medusa"; | ||
|
||
const REDIS_URL = process.env.REDIS_URL || "redis://localhost:6379"; | ||
|
||
const plugins = [ | ||
`medusa-fulfillment-manual`, | ||
`medusa-payment-manual`, | ||
{ | ||
resolve: `@medusajs/file-local`, | ||
options: { | ||
upload_dir: "uploads", | ||
}, | ||
}, | ||
{ | ||
resolve: "@medusajs/admin", | ||
/** @type {import('@medusajs/admin').PluginOptions} */ | ||
options: { | ||
autoRebuild: true, | ||
develop: { | ||
open: process.env.OPEN_BROWSER !== "false", | ||
}, | ||
}, | ||
}, | ||
{ | ||
resolve: `medusa-plugin-meilisearch`, | ||
options: { | ||
config: { | ||
host: process.env.MEILISEARCH_HOST, | ||
apiKey: process.env.MEILISEARCH_API_KEY, | ||
}, | ||
settings: { | ||
products: { | ||
indexSettings: { | ||
searchableAttributes: [ | ||
"title", | ||
"description", | ||
"variant_sku", | ||
], | ||
displayedAttributes: [ | ||
"id", | ||
"title", | ||
"description", | ||
"variant_sku", | ||
"thumbnail", | ||
"handle", | ||
], | ||
}, | ||
primaryKey: "id", | ||
}, | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
const modules = { | ||
/*eventBus: { | ||
resolve: "@medusajs/event-bus-redis", | ||
options: { | ||
redisUrl: REDIS_URL | ||
} | ||
}, | ||
cacheService: { | ||
resolve: "@medusajs/cache-redis", | ||
options: { | ||
redisUrl: REDIS_URL | ||
} | ||
},*/ | ||
}; | ||
|
||
/** @type {import('@medusajs/medusa').ConfigModule["projectConfig"]} */ | ||
const projectConfig = { | ||
jwtSecret: process.env.JWT_SECRET, | ||
cookieSecret: process.env.COOKIE_SECRET, | ||
store_cors: STORE_CORS, | ||
database_url: DATABASE_URL, | ||
admin_cors: ADMIN_CORS, | ||
// Uncomment the following lines to enable REDIS | ||
redis_url: REDIS_URL | ||
}; | ||
|
||
/** @type {import('@medusajs/medusa').ConfigModule} */ | ||
module.exports = { | ||
projectConfig, | ||
plugins, | ||
modules, | ||
}; |
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
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,36 @@ | ||
import { Page, Locator } from "@playwright/test" | ||
import { BaseModal } from "./base-modal" | ||
import { NavMenu } from "./nav-menu" | ||
|
||
export class SearchModal extends BaseModal { | ||
searchInput: Locator | ||
searchResults: Locator | ||
noSearchResultsContainer: Locator | ||
searchResult: Locator | ||
searchResultTitle: Locator | ||
|
||
constructor(page: Page) { | ||
super(page, page.getByTestId("search-modal-container")) | ||
this.searchInput = this.container.getByTestId("search-input") | ||
this.searchResults = this.container.getByTestId("search-results") | ||
this.noSearchResultsContainer = this.container.getByTestId( | ||
"no-search-results-container" | ||
) | ||
this.searchResult = this.container.getByTestId("search-result") | ||
this.searchResultTitle = this.container.getByTestId("search-result-title") | ||
} | ||
|
||
async open() { | ||
const menu = new NavMenu(this.page) | ||
await menu.open() | ||
await menu.searchLink.click() | ||
await this.container.waitFor({ state: "visible" }) | ||
} | ||
|
||
async close() { | ||
const viewport = this.page.viewportSize() | ||
const y = viewport ? viewport.height / 2 : 100 | ||
await this.page.mouse.click(1, y, { clickCount: 2, delay: 100 }) | ||
await this.container.waitFor({ state: "hidden" }) | ||
} | ||
} |
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,71 @@ | ||
import { test, expect } from "../../index" | ||
|
||
test.describe("Search tests", async () => { | ||
test("Searching for a specific product returns the correct product page", async ({ | ||
productPage, | ||
}) => { | ||
const searchModal = productPage.searchModal | ||
await searchModal.open() | ||
await searchModal.searchInput.fill("Sweatshirt") | ||
await searchModal.searchResult | ||
.filter({ hasText: "Sweatshirt" }) | ||
.first() | ||
.click() | ||
await productPage.container.waitFor({ state: "visible" }) | ||
await expect(productPage.productTitle).toContainText("Sweatshirt") | ||
}) | ||
|
||
test("An erroneous search returns an empty result", async ({ | ||
productPage, | ||
}) => { | ||
const searchModal = productPage.searchModal | ||
await searchModal.open() | ||
await searchModal.searchInput.fill("Does Not Sweatshirt") | ||
await expect(searchModal.noSearchResultsContainer).toBeVisible() | ||
}) | ||
|
||
test("User can search after an empty search result", async ({ | ||
productPage, | ||
}) => { | ||
const searchModal = productPage.searchModal | ||
|
||
await searchModal.open() | ||
await searchModal.searchInput.fill("Does Not Sweatshirt") | ||
await expect(searchModal.noSearchResultsContainer).toBeVisible() | ||
|
||
await searchModal.searchInput.fill("Sweat") | ||
await expect(searchModal.searchResults).toBeVisible() | ||
await expect(searchModal.searchResult.first()).toBeVisible() | ||
}) | ||
|
||
test("Closing the search page returns user back to their current page", async ({ | ||
storePage, | ||
productPage, | ||
loginPage, | ||
}) => { | ||
const searchModal = storePage.searchModal | ||
await test.step("Navigate to the store page and open and close search modal", async () => { | ||
await storePage.goto() | ||
await searchModal.open() | ||
await searchModal.close() | ||
await expect(storePage.container).toBeVisible() | ||
}) | ||
|
||
await test.step("Navigate to the product page and open and close search modal", async () => { | ||
await storePage.goto() | ||
const product = await storePage.getProduct("Sweatshirt") | ||
await product.locator.click() | ||
await productPage.container.waitFor({ state: "visible" }) | ||
await searchModal.open() | ||
await searchModal.close() | ||
await expect(productPage.container).toBeVisible() | ||
}) | ||
|
||
await test.step("Navigate to the login page and open and close search modal", async () => { | ||
await loginPage.goto() | ||
await searchModal.open() | ||
await searchModal.close() | ||
await expect(loginPage.container).toBeVisible() | ||
}) | ||
}) | ||
}) |
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
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
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