Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
NEXT_PUBLIC_CLIENT_BASE_URL=https://uat.a-comosus.link
NEXT_PUBLIC_GRAPHQL_ENDPOINT=https://api.uat.a-comosus.link/graphql/
NEXT_PUBLIC_RECAPTCHA_SITE_KEY=6LcYqNcgAAAAAEVUbCZb4cvf919b48U9Ux-Mz_cv

NEXT_PUBLIC_RECAPTCHA_SITE_KEY=6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI
2 changes: 2 additions & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NEXT_PUBLIC_GRAPHQL_ENDPOINT=http://localhost:3100/graphql/
GRAPHQL_ENDPOINT=http://localhost:3100/graphql/
1 change: 1 addition & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defineConfig } from 'cypress';

export default defineConfig({
projectId: '21s6cy',
chromeWebSecurity: false,
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
Expand Down
17 changes: 14 additions & 3 deletions cypress/e2e/auth/login.cy.js → cypress/e2e/auth/auth.cy.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/// <reference types='cypress' />

describe('Login Feature', function () {
describe('Auth Feature', function () {
beforeEach(() => {
cy.visit('http://localhost:3000/login');
cy.fixture('auth').then((data) => {
this.authData = data;
});
});

it('displays two input field by default', () => {
cy.visit('http://localhost:3000/login');
cy.get('form').within(() => {
cy.get('input').should('have.length', 2);
});
Expand All @@ -17,12 +17,23 @@ describe('Login Feature', function () {
it('navigate user to admin panel when logged in', () => {
const { username, password } = this.authData;
cy.login(username.valid, password.valid);
cy.url().should('contains', '/admin');
});

it('display error message when entered incorrect credential', () => {
const { username, password } = this.authData;
cy.login(username.invalid, password.invalid);
cy.get('[data-test-id="login.error"]').should('be.visible');
});

it('Signup Feature', () => {
const { username, email, password } = this.authData;
cy.signup(username.valid, email.valid, password.valid);
cy.get('[data-testid="checkbox"]').click();
cy.get('[data-testid="register"]').click();
cy.get('[data-testid="display-name"]').type('KevinLu');
cy.get('[data-testid="continue-btn"]').click();
cy.get(':nth-child(2) > .css-13qzv8t').click();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to test this with data-test-id

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The category(cy.get(':nth-child(2) > .css-13qzv8t').click(), ) seems like not a button, how can I click it? I changed the display-name already.

cy.recaptcha();
cy.get('[data-testid="recaptcha-continue-btn"]').click();
});
});
6 changes: 5 additions & 1 deletion cypress/fixtures/auth.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"username": {
"valid": "norris-wu",
"valid": "tester",
"invalid": "invalid"
},
"email": {
"valid": "tester@gmail.com",
"invalid": "invalid"
},
"password": {
Expand Down
25 changes: 25 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,31 @@ Cypress.Commands.add('login', (username: string, password: string) => {
});
});

Cypress.Commands.add(
'signup',
(username: string, email: string, password: string) => {
cy.visit('http://localhost:3000/sign-up');
cy.get('form').within(() => {
const randomStr = (Math.random() + 1).toString(36).substring(7);
cy.get('[id="username"]').type(`KevinLu${randomStr}`);
cy.get('[id="email"]').type(`turnkevin${randomStr}@gmail.com`);
cy.get('[id="password"]').type('admin123');
});
},
);

Cypress.Commands.add('recaptcha', () => {
cy.get('iframe')
.first()
.its('0.contentDocument.body')
.should('not.be.undefined')
.and('not.be.empty')
.then(cy.wrap)
.find('#recaptcha-anchor')
.should('be.visible')
.click();
});

// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
Expand Down
2 changes: 1 addition & 1 deletion src/modules/auth/SignUpForm/Policy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function Policy({ name, control }: PolicyProps) {
render={({ field, fieldState: { invalid, error } }) => (
<FormControl id={name} isInvalid={invalid}>
<HStack alignItems="flex-start">
<Checkbox mt="4px" {...field} />
<Checkbox mt="4px" {...field} data-testid="checkbox" />
<Text>{t('sign-up.policy.description')}</Text>
</HStack>
{error && (
Expand Down
7 changes: 6 additions & 1 deletion src/modules/auth/SignUpForm/SignUpForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ export default function SignUpForm({
testId="sign-up.error"
error={t('sign-up.error.user-exist')}
/>
<Button variantType="accent" type="submit" isLoading={isLoading}>
<Button
variantType="accent"
type="submit"
isLoading={isLoading}
data-testid="register"
>
{t('sign-up.button')}
</Button>
</VStack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default function DisplayName({ name, control }: DisplayNameProps) {
control={control}
placeholder={t('display-name.placeholder')}
borderRadius={15}
data-testid="display-name"
/>
</VStack>
);
Expand Down
2 changes: 2 additions & 0 deletions src/modules/onboarding/OnboardingForm/OnboardingForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default function OnboardingForm({
_.isNil(getFieldState('displayName').error) &&
toggleIsDisplayNameFilled();
}}
data-testid="continue-btn"
>
{t('continue')}
</Button>
Expand All @@ -92,6 +93,7 @@ export default function OnboardingForm({
isDisabled={!isValid}
isLoading={isOnboarding}
type="submit"
data-testid="recaptcha-continue-btn"
>
{t('continue')}
</Button>
Expand Down