Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

add new testcases to e2e tests (#248)

Guilherme Oenning2cd86fc71462
diff --git a/.dockerignore b/.dockerignore
index 1337e9cc0..d22da8661 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -1,8 +1,8 @@
-node_modules/
-vendor/
-app/
-public/
-tests/
-data/
-output/
+node_modules
+vendor
+app
+public
+tests
+data
+output
gin-bin
\ No newline at end of file
diff --git a/Makefile b/Makefile
index 1bda2089b..f8677dafc 100644
--- a/Makefile
+++ b/Makefile
@@ -16,6 +16,15 @@ test:
coverage:
godotenv -f .test.env courtney -o cover.out $$(go list ./...)
+e2e-single:
+ ./scripts/e2e.sh single
+
+e2e-multi:
+ ./scripts/e2e.sh multi
+
+e2e-build:
+ ./scripts/e2e.sh build
+
e2e:
./scripts/e2e.sh
diff --git a/public/pages/site/ShowIdeaPage/ResponseForm.tsx b/public/pages/site/ShowIdeaPage/ResponseForm.tsx
index b0e7b4e2b..985ee38f8 100644
--- a/public/pages/site/ShowIdeaPage/ResponseForm.tsx
+++ b/public/pages/site/ShowIdeaPage/ResponseForm.tsx
@@ -53,7 +53,7 @@ export class ResponseForm extends React.Component<ResponseFormProps, ResponseFor
public render() {
const button = (
- <Button className="icon fluid text-left" onClick={async () => this.showModal()}>
+ <Button className="respond icon fluid text-left" onClick={async () => this.showModal()}>
<i className="announcement icon" /> Respond
</Button>
);
@@ -106,14 +106,14 @@ export class ResponseForm extends React.Component<ResponseFormProps, ResponseFor
Cancel
</Button>
</div>
- </div>
+ </div>
);
return (
- <div>
+ <>
{button}
{modal}
- </div>
+ </>
);
}
}
diff --git a/scripts/e2e.sh b/scripts/e2e.sh
index f84040251..328ace7d1 100755
--- a/scripts/e2e.sh
+++ b/scripts/e2e.sh
@@ -4,23 +4,21 @@ FIDER_CONTAINER="fider_e2e"
PG_CONTAINER="fider_pge2e"
PORT=3000
-if lsof -Pi :$PORT -sTCP:LISTEN -t >/dev/null ; then
- echo "Another process is already running on port $PORT."
- exit 1;
-fi
-
-echo "Clean up ..."
-rm -rf output
-docker rm -f $PG_CONTAINER || true
-docker run -d -e POSTGRES_USER=fider_e2e -e POSTGRES_PASSWORD=fider_e2e_pw --name $PG_CONTAINER postgres:9.6.2
+run_e2e () {
+ # Check is PORT is in use
+ if lsof -Pi :$PORT -sTCP:LISTEN -t >/dev/null ; then
+ echo "Another process is already running on port $PORT."
+ exit 1;
+ fi
-echo "Building ..."
-tsc
-CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make build
-docker build -t getfider/fider:e2e .
+ echo "Compiling tests..."
+ rm -rf output
+ ./node_modules/.bin/tsc
-run_e2e () {
echo "Starting Fider (HOST_MODE: $1)..."
+ docker rm -f $PG_CONTAINER || true
+ docker run -d -e POSTGRES_USER=fider_e2e -e POSTGRES_PASSWORD=fider_e2e_pw --name $PG_CONTAINER postgres:9.6.2
+ docker run --link $PG_CONTAINER:pg waisbrot/wait
docker run -d -p 3000:3000 --link $PG_CONTAINER -e HOST_MODE=$1 -e DATABASE_URL=postgres://fider_e2e:fider_e2e_pw@$PG_CONTAINER:5432/fider_e2e?sslmode=disable --env-file .env --name $FIDER_CONTAINER getfider/fider:e2e
{
@@ -36,8 +34,22 @@ run_e2e () {
}
}
-run_e2e single
-run_e2e multi
+if [[ $1 == 'build' ]] || [ -z $1 ]
+then
+ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make build
+ docker build -t getfider/fider:e2e .
+fi
+
+if [[ $1 == 'single' ]] || [ -z $1 ]
+then
+ run_e2e single
+fi
+
+if [[ $1 == 'multi' ]] || [ -z $1 ]
+then
+ run_e2e multi
+fi
+
echo "Stopping Postgres ..."
docker rm -f $PG_CONTAINER || true
\ No newline at end of file
diff --git a/tests/components/CommentList.ts b/tests/components/CommentList.ts
new file mode 100644
index 000000000..b43bf26a6
--- /dev/null
+++ b/tests/components/CommentList.ts
@@ -0,0 +1,14 @@
+import { WebElement, By } from 'selenium-webdriver';
+import { Browser, WebComponent } from '../lib';
+
+export class CommentList {
+ constructor(
+ private elements: Promise<WebElement[]>,
+ private selector: string,
+ private browser: Browser) {
+ }
+
+ public async count(): Promise<number> {
+ return (await this.elements).length;
+ }
+}
diff --git a/tests/components/IdeaList.ts b/tests/components/IdeaList.ts
index 080b035a5..7c0b372ce 100644
--- a/tests/components/IdeaList.ts
+++ b/tests/components/IdeaList.ts
@@ -1,14 +1,22 @@
import { WebElement, By } from 'selenium-webdriver';
-import { WebComponent } from '../lib';
+import { Browser, WebComponent, WaitCondition } from '../lib';
export class IdeaList {
- constructor(private elements: Promise<WebElement[]>, private selector: string) {
+ constructor(
+ private elements: Promise<WebElement[]>,
+ private selector: string,
+ private browser: Browser) {
}
public async want(index: number) {
await (await this.elements)[index].findElement(By.css('.support-counter .button')).click();
}
+ public async navigateAndWait(index: number, condition: WaitCondition) {
+ await (await this.elements)[index].findElement(By.css('a.title')).click();
+ await this.browser.wait(condition);
+ }
+
public async at(index: number): Promise<WebComponent> {
const selector = '.support-counter .button';
const counter = (await this.elements)[index].findElement(By.css(selector));
diff --git a/tests/lib/browser.ts b/tests/lib/browser.ts
index 194562a8f..c0f9f0d01 100644
--- a/tests/lib/browser.ts
+++ b/tests/lib/browser.ts
@@ -6,6 +6,7 @@ export class Browser {
private driver: ThenableWebDriver;
public constructor(private browserName: string) {
this.driver = new Builder().forBrowser('chrome').build();
+ this.driver.manage().timeouts().implicitlyWait(5 * 1000);
}
public async navigate(url: string): Promise<void> {
diff --git a/tests/lib/components.ts b/tests/lib/components.ts
index 1d3c49607..dfbcb04c6 100644
--- a/tests/lib/components.ts
+++ b/tests/lib/components.ts
@@ -1,4 +1,4 @@
-import { WebElementPromise, Key } from 'selenium-webdriver';
+import { WebElementPromise, Key, By } from 'selenium-webdriver';
export class WebComponent {
constructor(protected element: WebElementPromise, public selector: string) { }
@@ -45,6 +45,22 @@ export class Button extends WebComponent {
}
}
+export class DropDownList extends WebComponent {
+ constructor(element: WebElementPromise, selector: string) {
+ super(element, selector);
+ }
+
+ public async selectByText(text: string) {
+ const options = await this.element.findElements(By.tagName('option'));
+ for (const option of options) {
+ if (await option.getText() === text) {
+ return await option.click();
+ }
+ }
+ throw new Error(`No option found for text '${text}'.`);
+ }
+}
+
export class TextInput extends WebComponent {
constructor(element: WebElementPromise, selector: string) {
super(element, selector);
diff --git a/tests/lib/ensure.ts b/tests/lib/ensure.ts
index 437f736a8..b8f7237be 100644
--- a/tests/lib/ensure.ts
+++ b/tests/lib/ensure.ts
@@ -7,8 +7,7 @@ class WebComponentEnsurer {
let lastErr: Error;
do {
try {
- await fn();
- return;
+ return await fn();
} catch (err) {
lastErr = err;
await delay(500);
diff --git a/tests/lib/utils.ts b/tests/lib/utils.ts
index 957fd4284..cd520434c 100644
--- a/tests/lib/utils.ts
+++ b/tests/lib/utils.ts
@@ -1,5 +1,6 @@
import 'reflect-metadata';
import { ThenableWebDriver, WebElementPromise } from 'selenium-webdriver';
+import { Browser } from './';
export const delay = (ms: number) => {
return new Promise((resolve) => setTimeout(resolve, ms));
@@ -16,8 +17,9 @@ export function findBy(selector: string, t?: new(element: WebElementPromise, sel
configurable: true,
enumerable: true,
get() {
- const promise = ((this as any).browser as ThenableWebDriver).findElement(selector);
- return new type(promise, selector);
+ const browser = (this as any).browser;
+ const promise = (browser as Browser).findElement(selector);
+ return new type(promise, selector, browser);
},
});
};
@@ -30,8 +32,9 @@ export function findMultipleBy(selector: string, t?: new(element: WebElementProm
configurable: true,
enumerable: true,
get() {
- const promise = ((this as any).browser as ThenableWebDriver).findElements(selector);
- return new type(promise, selector);
+ const browser = (this as any).browser;
+ const promise = (browser as Browser).findElements(selector);
+ return new type(promise, selector, browser);
},
});
};
diff --git a/tests/pages/ShowIdeaPage.ts b/tests/pages/ShowIdeaPage.ts
index bc55742e1..6ce6889a7 100644
--- a/tests/pages/ShowIdeaPage.ts
+++ b/tests/pages/ShowIdeaPage.ts
@@ -1,4 +1,5 @@
-import { WebComponent, Browser, Page, findBy, elementIsVisible } from '../lib';
+import { WebComponent, TextInput, Button, DropDownList, Browser, Page, findBy, findMultipleBy, elementIsVisible } from '../lib';
+import { CommentList } from '../components/CommentList';
export class ShowIdeaPage extends Page {
constructor(browser: Browser) {
@@ -8,13 +9,50 @@ export class ShowIdeaPage extends Page {
@findBy('.idea-header .header')
public Title: WebComponent;
- @findBy('div.description')
+ @findBy('.description')
public Description: WebComponent;
+ @findBy('.fdr-response .ui.label')
+ public Status: WebComponent;
+
+ @findBy('.fdr-response .content')
+ public ResponseText: WebComponent;
+
@findBy('.support-counter .button')
public SupportCounter: WebComponent;
+ @findBy('.comment-input textarea')
+ public CommentInput: TextInput;
+
+ @findBy('.comment-input button')
+ public SubmitCommentButton: Button;
+
+ @findMultipleBy('.ui.comments > .comment')
+ public CommentList: CommentList;
+
+ @findBy('.action-col button.respond')
+ public RespondButton: Button;
+
+ @findBy('.ui.modal.active.fdr-response-form')
+ public ResponseModal: WebComponent;
+
+ @findBy('.ui.modal.active.fdr-response-form select')
+ private ResponseModalStatus: DropDownList;
+
+ @findBy('.ui.modal.active.fdr-response-form textarea')
+ private ResponseModalText: TextInput;
+
+ @findBy('.ui.modal.active.fdr-response-form .actions button.primary')
+ private ResponseModalSubmitButton: Button;
+
public loadCondition() {
return elementIsVisible(() => this.Title);
}
+
+ public async changeStatus(status: string, text: string): Promise<void> {
+ await this.ResponseModalStatus.selectByText(status);
+ await this.ResponseModalText.clear();
+ await this.ResponseModalText.type(text);
+ await this.ResponseModalSubmitButton.click();
+ }
}
diff --git a/tests/testcases/SubmitIdeas.ts b/tests/testcases/SubmitIdeas.ts
index 2c1edbd5c..e7b313464 100644
--- a/tests/testcases/SubmitIdeas.ts
+++ b/tests/testcases/SubmitIdeas.ts
@@ -1,6 +1,9 @@
import { ensure, elementIsVisible, elementIsNotVisible, mailgun, delay } from '../lib';
import { pages, tenant, browser } from '../context';
import { createTenant } from './setup';
+import {
+ equal as assertEqual
+} from 'assert';
describe('Submit ideas', () => {
@@ -51,7 +54,7 @@ describe('Submit ideas', () => {
await browser.wait(elementIsNotVisible(() => pages.home.IdeaDescription));
});
- it('Unauthenticated cannot submit ideas', async () => {
+ it('Unauthenticated users cannot submit ideas', async () => {
// Action
await pages.home.navigate();
await pages.home.signOut();
@@ -65,11 +68,11 @@ describe('Submit ideas', () => {
// Action
await pages.home.navigate();
await pages.home.signInWithFacebook();
- await pages.facebook.signInAsAryaStark();
+ await pages.facebook.signInAsJonSnow();
await pages.home.UserMenu.click();
// Assert
- await ensure(pages.home.UserName).textIs('ARYA STARK');
+ await ensure(pages.home.UserName).textIs('JON SNOW');
// Action
await pages.home.submitNewIdea('Add support to TypeScript', 'Because the language and community is awesome! :)');
@@ -80,16 +83,74 @@ describe('Submit ideas', () => {
await ensure(pages.showIdea.SupportCounter).textIs('1');
});
+ it('Admin can change status', async () => {
+ // Action & Assert
+ await pages.home.navigate();
+ await pages.home.IdeaList.navigateAndWait(0, pages.showIdea.loadCondition());
+ await pages.showIdea.RespondButton.click();
+ await browser.wait(elementIsVisible(() => pages.showIdea.ResponseModal));
+
+ // Action & Assert
+ await pages.showIdea.changeStatus('Planned', 'We will work on this soon...');
+ await browser.wait(elementIsVisible(() => pages.showIdea.Status));
+ await ensure(pages.showIdea.Status).textIs('PLANNED');
+ await ensure(pages.showIdea.ResponseText).textIs('We will work on this soon...');
+ });
+
+ it('Admin can change status to another one', async () => {
+ // Action & Assert
+ await pages.showIdea.RespondButton.click();
+ await browser.wait(elementIsVisible(() => pages.showIdea.ResponseModal));
+ await pages.showIdea.changeStatus('Planned', 'We will work on this soon...');
+ await browser.wait(elementIsVisible(() => pages.showIdea.Status));
+ await ensure(pages.showIdea.Status).textIs('PLANNED');
+ await ensure(pages.showIdea.ResponseText).textIs('We will work on this soon...');
+ });
+
+ it('Authenticated user can comment on an idea', async () => {
+ // Action & Assert
+ await pages.home.navigate();
+ await pages.home.IdeaList.navigateAndWait(0, pages.showIdea.loadCondition());
+ await ensure(pages.showIdea.SubmitCommentButton).isNotVisible();
+
+ // Action & Assert
+ await pages.showIdea.CommentInput.type('This is my first comment');
+ await ensure(pages.showIdea.SubmitCommentButton).isVisible();
+
+ // Action & Assert
+ await pages.showIdea.SubmitCommentButton.click();
+ await browser.wait(async () => await pages.showIdea.CommentList.count() === 1);
+ });
+
+ it('Unauthenticated user cannot comment on an idea', async () => {
+ // Action & Assert
+ await pages.home.navigate();
+ await pages.home.signOut();
+ await pages.home.IdeaList.navigateAndWait(0, pages.showIdea.loadCondition());
+ assertEqual(await pages.showIdea.CommentList.count(), 1);
+
+ // Action & Assert
+ await pages.showIdea.CommentInput.click();
+ await browser.wait(elementIsVisible(() => pages.home.SignInModal));
+ });
+
+ it('Unauthenticated user cannot see actions', async () => {
+ // Action & Assert
+ await pages.home.navigate();
+ await pages.home.signOut();
+ await pages.home.IdeaList.navigateAndWait(0, pages.showIdea.loadCondition());
+ await ensure(pages.showIdea.RespondButton).isNotVisible();
+ });
+
it('Can sign in with Google and support an idea', async () => {
- // Action
+ // Action & Assert
await pages.home.navigate();
await pages.home.signInWithGoogle();
await pages.google.signInAsDarthVader();
await pages.home.UserMenu.click();
-
- // Assert
await ensure(pages.home.UserName).textIs('DARTH VADER');
+ // Action & Assert
await pages.home.IdeaList.want(0);
await ensure(await pages.home.IdeaList.at(0)).textIs('2');
});
@@ -112,4 +173,8 @@ describe('Submit ideas', () => {
await pages.home.UserMenu.click();
await ensure(pages.home.UserName).textIs(`DARTH VADER ${now}`);
});
+
+ it.skip('Admin can change Title, Invitation and Welcom Message', async () => {
+ return true;
+ });
});