Skip to content

Commit

Permalink
Improve navigation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NoelDeMartin committed Mar 1, 2024
1 parent 6b015bb commit 76fc084
Show file tree
Hide file tree
Showing 11 changed files with 158 additions and 92 deletions.
6 changes: 2 additions & 4 deletions cypress/e2e/cloud.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,9 @@ describe('Cloud', () => {
cy.dontSee('Loading...');

// Assert
cy.see('Main');
cy.seeActiveWorkspace('Main');
cy.see('Onboarding task');
cy.see('Inbox', 'li').within(() => {
cy.see('(active)');
});
cy.seeActiveList('Inbox');

cy.get('@createContainer.all').should('have.length', 1);
cy.get('@createContainerMeta.all').should('have.length', 1);
Expand Down
97 changes: 50 additions & 47 deletions cypress/e2e/navigation.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,96 +2,99 @@ describe('Navigation', () => {

beforeEach(() => {
cy.visit('/');
cy.createStubs();
cy.clearLocalStorage();
});

// Create task
cy.ariaInput('Task name').type('...{enter}');

// Create list
cy.press('Add new');
cy.ariaInput('List name').type('Groceries{enter}');
it('Navigates across workspaces and lists', () => {
cy.press('Groceries');
cy.seeActiveWorkspace('Household');
cy.seeActiveList('Groceries');
cy.see('Nuts');
cy.see('Chickpeas');
cy.see('Tomatoes');

// Create first workspace
cy.ariaLabel('Select workspace').within(() => {
cy.get('button').click();
});
cy.press('Add new', 'li');
cy.ariaInput('Workspace name').type('Study{enter}');
cy.see('Study');
cy.press('Recipes');
cy.seeActiveWorkspace('Household');
cy.seeActiveList('Recipes');
cy.see('Ramen');

cy.clearLocalStorage();
cy.press('Inbox');
cy.seeActiveWorkspace('Household');
cy.seeActiveList('Inbox');
cy.see('Clean room');

cy.switchWorkspace('Japanese');
cy.seeActiveWorkspace('Japanese');
cy.seeActiveList('Inbox');
cy.see('Learn Heisig Kanji');

cy.press('Manga');
cy.seeActiveWorkspace('Japanese');
cy.seeActiveList('Manga');
cy.see('Read One Piece');

cy.switchWorkspace('Main');
cy.seeActiveWorkspace('Main');
cy.seeActiveList('Inbox');
cy.see('Learn Aerogel');
});

it('Opens the default workspace', () => {
// Act
cy.visit('/');

// Assert
cy.url().should('equal', `${Cypress.config('baseUrl')}/main`);
cy.see('Main');
cy.see('Inbox', 'li').within(() => {
cy.see('(active)');
});
cy.url().should('equal', `${Cypress.config('baseUrl')}/household`);
cy.seeActiveWorkspace('Household');
cy.seeActiveList('Inbox');
});

it('Opens the last visited workspace', () => {
// Arrange
cy.visit('/main/groceries');
cy.see('Groceries');
cy.visit('/household/groceries');
cy.seeActiveWorkspace('Groceries');

// Act
cy.visit('/');

// Assert
cy.url().should('equal', `${Cypress.config('baseUrl')}/main/groceries`);
cy.see('Main');
cy.see('Groceries', 'li').within(() => {
cy.see('(active)');
});
cy.url().should('equal', `${Cypress.config('baseUrl')}/household/groceries`);
cy.seeActiveWorkspace('Household');
cy.seeActiveList('Groceries');
});

it('Opens lists', () => {
// Act
cy.visit('/main/groceries');
cy.visit('/household/groceries');

// Assert
cy.see('Groceries', 'li').within(() => {
cy.see('(active)');
});
cy.seeActiveList('Groceries');
});

it('Changes workspaces', () => {
// Act
cy.ariaLabel('Select workspace').within(() => {
cy.get('button').click();
});
cy.press('Study', 'li');
cy.switchWorkspace('Japanese');

// Assert
cy.url().should('equal', `${Cypress.config('baseUrl')}/study`);
cy.see('Study');
cy.url().should('equal', `${Cypress.config('baseUrl')}/japanese`);
cy.seeActiveWorkspace('Japanese');
});

it('Changes lists', () => {
// Arrange
cy.visit('/');

// Open Groceries - Act
cy.press('Groceries');

// Open Groceries - Assert
cy.url().should('equal', `${Cypress.config('baseUrl')}/main/groceries`);
cy.see('Groceries', 'li').within(() => {
cy.see('(active)');
});
cy.url().should('equal', `${Cypress.config('baseUrl')}/household/groceries`);
cy.seeActiveList('Groceries');

// Open Inbox - Act
cy.press('Inbox');

// Open Inbox - Assert
cy.url().should('equal', `${Cypress.config('baseUrl')}/main`);
cy.see('Inbox', 'li').within(() => {
cy.see('(active)');
});
cy.url().should('equal', `${Cypress.config('baseUrl')}/household`);
cy.seeActiveList('Inbox');
});

it('Shows missing workspaces notice', () => {
Expand Down
24 changes: 8 additions & 16 deletions cypress/e2e/onboarding.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ describe('Onboarding', () => {
// Assert
cy.url().should('equal', `${Cypress.config('baseUrl')}/main`);
cy.see('Start being more focused');
cy.see('Main');
cy.see('Inbox', 'li').within(() => {
cy.see('(active)');
});
cy.seeActiveWorkspace('Main');
cy.seeActiveList('Inbox');
});

it('Signs up', () => {
Expand All @@ -38,18 +36,14 @@ describe('Onboarding', () => {

// Assert
cy.url().should('equal', `${Cypress.config('baseUrl')}/main`);
cy.see('Main');
cy.seeActiveWorkspace('Main');
cy.see('Cook Ramen');
cy.see('Inbox', 'li').within(() => {
cy.see('(active)');
});
cy.seeActiveList('Inbox');

cy.reload();
cy.see('Main');
cy.seeActiveWorkspace('Main');
cy.see('Cook Ramen');
cy.see('Inbox', 'li').within(() => {
cy.see('(active)');
});
cy.seeActiveList('Inbox');

cy.get('@createContainer.all').should('have.length', 1);
cy.get('@createContainerMeta.all').should('have.length', 1);
Expand Down Expand Up @@ -93,12 +87,10 @@ describe('Onboarding', () => {
cy.see('Syncing');

cy.url().should('equal', `${Cypress.config('baseUrl')}/household`);
cy.see('Household');
cy.seeActiveWorkspace('Household');
cy.seeActiveList('Inbox');
cy.see('Tomatoes');
cy.see('Groceries');
cy.see('Inbox', 'li').within(() => {
cy.see('(active)');
});

cy.press('Household');
cy.see('Work');
Expand Down
10 changes: 3 additions & 7 deletions cypress/e2e/workspaces.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ describe('Workspaces', () => {

// Assert
cy.url().should('equal', `${Cypress.config('baseUrl')}/study`);
cy.see('Study');
cy.see('Inbox', 'li').within(() => {
cy.see('(active)');
});
cy.seeActiveWorkspace('Study');
cy.seeActiveList('Inbox');
});

it('Creates lists', () => {
Expand All @@ -30,9 +28,7 @@ describe('Workspaces', () => {

// Assert
cy.url().should('equal', `${Cypress.config('baseUrl')}/main/groceries`);
cy.see('Groceries', 'li').within(() => {
cy.see('(active)');
});
cy.seeActiveList('Groceries');
});

});
8 changes: 7 additions & 1 deletion cypress/support/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { defineCommands } from '@aerogel/cypress';

import * as cloudCommands from './cloud';
import * as navigationCommands from './navigation';
import * as stubsCommands from './stubs';

const commands = { ...cloudCommands };
const commands = {
...cloudCommands,
...navigationCommands,
...stubsCommands,
};

type Commands = typeof commands;

Expand Down
16 changes: 16 additions & 0 deletions cypress/support/commands/navigation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export function seeActiveList(name: string): void {
cy.see(name, 'li').within(() => {
cy.see('(active)');
});
}

export function seeActiveWorkspace(name: string): void {
cy.see(name);
}

export function switchWorkspace(name: string): void {
cy.ariaLabel('Select workspace').within(() => {
cy.get('button').click();
});
cy.press(name, 'li');
}
43 changes: 43 additions & 0 deletions cypress/support/commands/stubs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
export function createStubs(open: boolean = true): void {
cy.model('Workspace').then(async (Workspace) => {
const main = await Workspace.create({ name: 'Main' });

await main.relatedTasks.create({ name: 'Learn Typescript' }).then((task) => task.toggle());
await main.relatedTasks.create({ name: 'Learn Vue' }).then((task) => task.toggle());
await main.relatedTasks.create({ name: 'Learn TailwindCSS' }).then((task) => task.toggle());
await main.relatedTasks.create({ name: 'Learn Aerogel' });
});

cy.model('Workspace').then(async (Workspace) => {
const household = await Workspace.create({ name: 'Household' });
const groceries = await household.relatedLists.create({ name: 'Groceries' });
const recipes = await household.relatedLists.create({ name: 'Recipes' });

await household.relatedTasks.create({ name: 'Clean room' });
await household.relatedTasks.create({ name: 'Clean Neko\'s litter box' }).then((task) => task.toggle());

await groceries.relatedTasks.create({ name: 'Chickpeas' });
await groceries.relatedTasks.create({ name: 'Tomatoes' });
await groceries.relatedTasks.create({ name: 'Nuts' });

await recipes.relatedTasks.create({ name: 'Ramen' });
await recipes.relatedTasks.create({ name: 'Pizza' }).then((task) => task.toggle());
await recipes.relatedTasks.create({ name: 'Baba Ganoush' }).then((task) => task.toggle());
});

cy.model('Workspace').then(async (Workspace) => {
const japanese = await Workspace.create({ name: 'Japanese' });
const manga = await japanese.relatedLists.create({ name: 'Manga' });

await japanese.relatedTasks.create({ name: 'Learn Hiragana' }).then((task) => task.toggle());
await japanese.relatedTasks.create({ name: 'Learn Katakana' }).then((task) => task.toggle());
await japanese.relatedTasks.create({ name: 'Learn Heisig Kanji' });

await manga.relatedTasks.create({ name: 'Read One Piece' });
await manga.relatedTasks.create({ name: 'Read Yotsubato' }).then((task) => task.toggle());
});

if (open) {
cy.model('Workspace').then((Workspace) => Workspace.all().then((workspaces) => workspaces[0].open()));
}
}
3 changes: 2 additions & 1 deletion cypress/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
"types": ["cypress", "node"],
"baseUrl": ".",
"paths": {
"@/*": ["../src/*"],
"@cy/*": ["./*"]
}
},
"include": ["**/*.ts"]
"include": ["**/*.ts", "../src/**/*.ts"]
}
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 76fc084

Please sign in to comment.