Skip to content

Commit 3ef4a45

Browse files
committed
[e2e] add user registration tests
1 parent 64ce51b commit 3ef4a45

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// vue-skuilder/cypress/e2e/user-registration.cy.js
2+
describe('User Registration', () => {
3+
it('should allow a new user to register', () => {
4+
// Generate a unique username using timestamp to avoid conflicts
5+
cy.registerUser().then((username) => {
6+
// Wait for the registration process to complete
7+
// You may need to adjust the assertion based on what indicates successful registration in your app
8+
cy.url().should('include', `/u/${username}/new`);
9+
10+
// Additional assertions to verify that the user is logged in
11+
// For example, check if a profile element or welcome message is visible
12+
cy.contains(`Welcome, ${username}`).should('be.visible');
13+
14+
// Navigate to the home page and verify that the user's username is displayed
15+
cy.visit('/');
16+
cy.reload();
17+
cy.contains('.v-chip', username);
18+
});
19+
});
20+
21+
it('should prevent registration with an existing username', () => {
22+
cy.visit('/');
23+
cy.contains('Sign Up').click();
24+
25+
// Use a username that you know already exists
26+
const existingUsername = 'Colin'; // Replace with a username that exists in your system
27+
const password = 'password123';
28+
29+
// Fill out the registration form with an existing username
30+
cy.get('input[name="username"]').type(existingUsername);
31+
cy.get('input[name="password"]').type(password);
32+
cy.get('input[name="retypedPassword"]').type(password);
33+
34+
// Submit the form
35+
cy.contains('button', 'Create Account').click();
36+
37+
// Assert that an error message is displayed
38+
cy.contains('The name ' + existingUsername + ' is taken!').should('be.visible');
39+
40+
// Assert that we're still on the registration page
41+
cy.url().should('not.include', `/u/${existingUsername}`);
42+
});
43+
44+
it('should validate that passwords match', () => {
45+
cy.visit('/');
46+
cy.contains('Sign Up').click();
47+
48+
const username = `testuser${Date.now()}`;
49+
const password = 'password123';
50+
const differentPassword = 'different123';
51+
52+
// Fill out the form with non-matching passwords
53+
cy.get('input[name="username"]').type(username);
54+
cy.get('input[name="password"]').type(password);
55+
cy.get('input[name="retypedPassword"]').type(differentPassword);
56+
57+
// Submit the form
58+
cy.contains('button', 'Create Account').click();
59+
60+
// Assert that we're still on the registration page
61+
cy.url().should('not.include', `/u/${username}`);
62+
63+
// Assert that an error message about password mismatch is displayed
64+
cy.contains('Passwords do not match').should('be.visible');
65+
});
66+
67+
it('should not render Signup form if logged in', () => {
68+
cy.registerUser().then(() => {
69+
cy.visit('/signup');
70+
cy.url().should('include', '/signup');
71+
72+
// Check that the signup form is not displayed
73+
cy.get('input[name="username"]').should('not.exist');
74+
cy.get('input[name="password"]').should('not.exist');
75+
cy.get('input[name="retypedPassword"]').should('not.exist');
76+
77+
// Alternative approach - check for any input field
78+
cy.get('form input').should('not.exist');
79+
80+
// Check that some logged-in state indicator is present instead
81+
cy.contains('Already logged in').should('be.visible');
82+
});
83+
});
84+
});

0 commit comments

Comments
 (0)