-
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.
Add tests + Update src to enhance testability
- Loading branch information
1 parent
eb4f812
commit f1b19a7
Showing
24 changed files
with
2,967 additions
and
3,188 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,101 @@ | ||
// server needs to start before running this test | ||
// % node index.js | ||
|
||
// Needs to be higher than the default Playwright timeout | ||
jest.setTimeout(40 * 1000) | ||
|
||
const { chromium, firefox, webkit, devices } = require("playwright"); | ||
|
||
const deviceList = [ | ||
'Galaxy S8', | ||
// 'iPad Pro 11', | ||
'iPad Mini landscape', | ||
// 'iPhone 8', | ||
'iPhone 12', | ||
'Pixel 2 XL', | ||
// 'Pixel 5 landscape', | ||
'Desktop Safari', | ||
'Desktop Chrome', | ||
'Dekstop Edge', | ||
'Desktop Firefox', | ||
]; | ||
|
||
describe.each([ | ||
[chromium.name(), chromium], | ||
[firefox.name(), firefox], | ||
[webkit.name(), webkit], | ||
])('test on %p', (_browserName, browserType) => { | ||
|
||
let newBrowser; | ||
|
||
beforeAll(async () => { | ||
newBrowser = await browserType.launch(); | ||
// // For debugging | ||
// newBrowser = await browserType.launch({ | ||
// // slowMo: 250, | ||
// headless: false | ||
// }); | ||
}); | ||
|
||
afterAll(async () => { | ||
await newBrowser.close(); | ||
}); | ||
|
||
it.each(deviceList)('(#%s) should render the built app', async (curDeviceName) => { | ||
|
||
let context | ||
try { | ||
context = await newBrowser.newContext({ | ||
...devices[curDeviceName], | ||
|
||
// Required when clicking Submit | ||
geolocation: { longitude: 48.858455, latitude: 2.294474 }, | ||
permissions: ['geolocation'] | ||
}); | ||
} catch (e) { | ||
console.log(`Skip test in "${_browserName}" `); | ||
return | ||
} | ||
|
||
const page = await context.newPage(); | ||
await page.goto('http://localhost:8080'); | ||
|
||
await expect(page).toHaveSelector('[data-testid="nav-item-brand"]'); | ||
|
||
const selector = '[data-testid="nav-item-askbuddy"]'; | ||
await page.click(selector); | ||
await expect(page).toHaveSelector('[data-testid="qna-container"]'); | ||
|
||
|
||
const selectorResContainer = '[data-testid="response-container"]'; | ||
const elResContainerBefore = await page.$(selectorResContainer); | ||
const elResContainerContentBefore = await elResContainerBefore.textContent(); | ||
expect(elResContainerContentBefore).toBeFalsy(); | ||
|
||
// await page.pause() | ||
|
||
// Click [placeholder="Select or type question or category..."] | ||
await page.click('[placeholder="Select or type question or category..."]'); | ||
|
||
// Click text=What can we do so that other diseases like COVID-19 do not affect us in future?C | ||
// await page.click('text=What can we do so that other diseases like COVID-19 do not affect us in future?C'); | ||
await page.click('#faq-typeahead-item-0'); | ||
const element = await page.$('input[placeholder="Select or type question or category..."]'); | ||
|
||
const elemValue = await element.inputValue(); | ||
expect(elemValue).toBeTruthy(); | ||
|
||
// Click text=Submit | ||
await page.click('text=Submit'); | ||
|
||
// Poll until the response shows up | ||
await page.waitForSelector('[data-testid="response-item"]'); | ||
|
||
const elResContainerAfter = await page.$(selectorResContainer); | ||
const elResContainerContentAfter = await elResContainerAfter.textContent(); | ||
expect(elResContainerContentAfter).toBeTruthy(); | ||
|
||
await page.close(); | ||
}); | ||
|
||
}); |
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,41 @@ | ||
const { zipWith } = require('../../server/Utils'); | ||
|
||
describe('tUtils', () => { | ||
|
||
it('zipWith should return an appropriate output', () => { | ||
|
||
const myFcn = (a, b) => [a, b]; | ||
|
||
// --- When xs and ys has the same number of elements | ||
let xs = [1, 2, 3]; | ||
let ys = [4, 5, 6]; | ||
|
||
const actSameElems = zipWith(myFcn, xs, ys); | ||
expect(actSameElems).toEqual([ | ||
[1, 4], | ||
[2, 5], | ||
[3, 6] | ||
]); | ||
|
||
// --- When a number of Elements in xs of LESS than a number of element of ys | ||
xs = [1, 2]; | ||
ys = [4, 5, 6]; | ||
|
||
const actXsLessThanYs = zipWith(myFcn, xs, ys); | ||
expect(actXsLessThanYs).toEqual([ | ||
[1, 4], | ||
[2, 5] | ||
]); | ||
|
||
// --- When a number of Elements in xs of GREATER than a number of element of ys | ||
xs = [1, 2, 3]; | ||
ys = [4]; | ||
|
||
const actXsGtYs = zipWith(myFcn, xs, ys); | ||
expect(actXsGtYs).toEqual([ | ||
[1, 4] | ||
]); | ||
|
||
}); | ||
|
||
}); |
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 @@ | ||
|
||
## Sequence diagram | ||
|
||
### FAQ Workflow | ||
 | ||
|
||
The sequence diagram above was created from https://sequencediagram.org/ using the syntaxes below: | ||
|
||
``` | ||
title FAQ Workflow | ||
User->Client-FAQ:Select a FAQ | ||
Client-FAQ->Client-QnAService:getFAQResponseById(id) | ||
Client-QnAService->Server: axios.get(`/getfaqresponse?id=${id}`) | ||
Server->Server-QnAService: getFAQResponseById(id) | ||
Server-QnAService->Server: [Object] faqresponse | ||
Server->Client-QnAService: {data: faqresponse} | ||
Client-QnAService->Client-FAQ: faqresponse | ||
Client-FAQ->Client-FAQ: Render FAQ result | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.