Skip to content

Commit

Permalink
✅ Add project creation & edition test scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
Lysoun committed Nov 14, 2023
1 parent 65ba3d9 commit 7235375
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 5 deletions.
70 changes: 70 additions & 0 deletions modules/ui/cypress/e2e/project-creation-and-edition.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
Cypress.Commands.add('getBySelectorId', (selectorId) => {
cy.get('[data-cy="' + selectorId + '"]');
});

function generateId(): string {
return Math.random().toString(16).slice(2);
}

function buildProjectName(id): string {
return 'project ' + id;
}

function buildProjectSmallName(id): string {
return id;
}

const projectId = generateId();
const projectName = buildProjectName(projectId);
const projectSmallName = buildProjectSmallName(projectId);

const newProjectId = generateId();
const projectNewName = buildProjectName(newProjectId)
const projectNewSmallName = buildProjectSmallName(newProjectId);

describe('project creation and edition afterwards', () => {
it('create project', () => {
cy.visit('/projects')
cy.getBySelectorId('name')
.type(projectName)
.should('have.value', projectName)
cy.getBySelectorId('smallName')
.type(projectSmallName)
.should('have.value', projectSmallName)
cy.get('button[type=submit]').click()
})

it('new project should appear in project hierarchies', () => {
cy.visit('/')
cy.contains(projectName);
cy.contains(projectSmallName);
})

it('edit newly created project', () => {
cy.visit('/')
cy.contains(projectName).click();
cy.getBySelectorId('editProject').click();

cy.getBySelectorId('name')
.clear()
.type(projectNewName)
.should('have.value', projectNewName)
cy.getBySelectorId('smallName')
.clear()
.type(projectNewSmallName)
.should('have.value', projectNewSmallName)
cy.get('button[type=submit]').click()
})

it('new name should appear in project hierarchies', () => {
cy.visit('/')
cy.contains(projectNewName);
cy.contains(projectNewSmallName);
})

it('old name should not appear anywhere',() => {
cy.visit('/')
cy.contains(projectName).should('not.exist');
cy.contains(projectSmallName).should('not.exist');
})
})
3 changes: 2 additions & 1 deletion modules/ui/src/lib/components/atoms/form/A_inputText.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
export let value;
export let placeholder;
export let required;
export let testId;
</script>

<input type="text" bind:value={value} {required} placeholder="{placeholder}" class="aInputText">
<input type="text" bind:value={value} {required} placeholder="{placeholder}" class="aInputText" data-cy="{testId}">

<style lang="scss">
@import "src/app";
Expand Down
3 changes: 2 additions & 1 deletion modules/ui/src/lib/components/molecules/M_inputText.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
export let value;
export let required;
export let placeholder;
export let testId;
</script>

<A_label {label}>
<A_inputText bind:value={value} {required} {placeholder}></A_inputText>
<A_inputText bind:value={value} {required} {placeholder} {testId}></A_inputText>
</A_label>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import type {Project} from "$lib/domain/Project";
import {t} from "$lib/services/I18nService";
export const prerender = false;
export let project: Project = {} as Project;
function save() {
Expand All @@ -17,8 +18,8 @@
</script>

<form on:submit|preventDefault={save}>
<M_inputText label="{$t('project.name')}" bind:value={project.name} required="true" placeholder="{$t('project.name')}"/>
<M_inputText label="{$t('project.smallName')}" bind:value={project.smallName} required="true" placeholder="{$t('project.smallName')}"/>
<M_inputText label="{$t('project.name')}" bind:value={project.name} required="true" placeholder="{$t('project.name')}" testId="name"/>
<M_inputText label="{$t('project.smallName')}" bind:value={project.smallName} required="true" placeholder="{$t('project.smallName')}" testId="smallName"/>

<A_button label="{$t('common.actions.save')}" type="submit"/>
</form>
Expand Down
2 changes: 1 addition & 1 deletion modules/ui/src/routes/projects/[project]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<a href="{project.id}/envs">Créer un nouvel environnement</a>

<br>
<a href="{project.id}/edit">Editer</a>
<a href="{project.id}/edit" data-cy="editProject">Editer</a>

{#if moduleEnvMatrix}
<O_matrixModuleEnv projectRef="{project.id}" matrix="{moduleEnvMatrix}"></O_matrixModuleEnv>
Expand Down

0 comments on commit 7235375

Please sign in to comment.