Skip to content

Commit

Permalink
feat: 🚸 rework project selection
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudTA committed Oct 9, 2024
1 parent 48f574f commit 752afee
Show file tree
Hide file tree
Showing 61 changed files with 1,762 additions and 1,280 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:

jobs:
cleanup-cache:
name: Delete gituhb cache
name: Delete github cache
runs-on: ubuntu-latest
steps:
- name: Check out code
Expand Down
25 changes: 20 additions & 5 deletions apps/client/cypress/components/specs/repo-form.ct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ describe('RepoForm.vue', () => {

const randomDbSetup = createRandomDbSetup({})
const projectStore = useProjectStore()
projectStore.selectedProject = randomDbSetup.project
projectStore.myProjectsById = {
[randomDbSetup.project.id]: randomDbSetup.project.id,
}
projectStore.setSelectedProject(randomDbSetup.project.id)

cy.mount(RepoForm, { props })

Expand Down Expand Up @@ -95,7 +98,10 @@ describe('RepoForm.vue', () => {

const randomDbSetup = createRandomDbSetup({})
const projectStore = useProjectStore()
projectStore.selectedProject = randomDbSetup.project
projectStore.myProjectsById = {
[randomDbSetup.project.id]: randomDbSetup.project.id,
}
projectStore.setSelectedProject(randomDbSetup.project.id)

cy.mount(RepoForm, { props })

Expand Down Expand Up @@ -185,7 +191,10 @@ describe('RepoForm.vue', () => {

const randomDbSetup = createRandomDbSetup({})
const projectStore = useProjectStore()
projectStore.selectedProject = randomDbSetup.project
projectStore.myProjectsById = {
[randomDbSetup.project.id]: randomDbSetup.project.id,
}
projectStore.setSelectedProject(randomDbSetup.project.id)

cy.mount(RepoForm, { props })

Expand Down Expand Up @@ -230,7 +239,10 @@ describe('RepoForm.vue', () => {

const randomDbSetup = createRandomDbSetup({})
const projectStore = useProjectStore()
projectStore.selectedProject = randomDbSetup.project
projectStore.myProjectsById = {
[randomDbSetup.project.id]: randomDbSetup.project.id,
}
projectStore.setSelectedProject(randomDbSetup.project.id)

cy.mount(RepoForm, { props })

Expand Down Expand Up @@ -269,7 +281,10 @@ describe('RepoForm.vue', () => {

const randomDbSetup = createRandomDbSetup({})
const projectStore = useProjectStore()
projectStore.selectedProject = randomDbSetup.project
projectStore.myProjectsById = {
[randomDbSetup.project.id]: randomDbSetup.project.id,
}
projectStore.setSelectedProject(randomDbSetup.project.id)

cy.mount(RepoForm, { props })

Expand Down
36 changes: 19 additions & 17 deletions apps/client/cypress/components/specs/services-config.ct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ import ServicesConfig from '@/components/ServicesConfig.vue'

const argoto = { to: 'https://argocd.domain.com/applications?showFavorites=false&proj=&sync=&health=&namespace=&cluster=&labels=&search=org-project', name: '' }
const gitlabto = { to: 'https://gitlab.domain.com/forge-mi/projects/org/project', name: '' }
const services = [{ imgSrc: '/img/argocd.svg', title: 'ArgoCD', name: 'argocd', urls: [argoto, argoto, argoto], manifest: {} }, { imgSrc: '/img/gitlab.svg', title: 'Gitlab', name: 'gitlab', urls: [gitlabto, gitlabto], manifest: {} }, { imgSrc: '/img/harbor.svg', title: 'Harbor', name: 'registry', urls: [{ to: 'https://harbor.domain.com/harbor/projects/254', name: '' }], manifest: { global: [{ permissions: { admin: { read: true, write: true }, user: { read: true, write: false } }, key: 'publish-ro-robot-by-default', kind: 'switch', title: 'Publier le robot RO par défaut', value: 'default', initialValue: 'disabled' }], project: [{ permissions: { admin: { read: true, write: true }, user: { read: true, write: false } }, key: 'view-robot', kind: 'switch', title: 'Publier le robot', initialValue: 'disabled', value: 'default', description: 'Autoriser un robot de lecture sur le projet' }] } }, { imgSrc: '/img/sonarqube.svg', title: 'SonarQube', name: 'sonarqube', urls: [], manifest: {} }]
const services = [
{ imgSrc: '/img/argocd.svg', title: 'ArgoCD', name: 'argocd', urls: [argoto, argoto, argoto], manifest: {} },
{ imgSrc: '/img/gitlab.svg', title: 'Gitlab', name: 'gitlab', urls: [gitlabto, gitlabto], manifest: {} },
{ imgSrc: '/img/harbor.svg', title: 'Harbor', name: 'registry', urls: [{ to: 'https://harbor.domain.com/harbor/projects/254', name: '' }], manifest: { global: [{ permissions: { admin: { read: true, write: true }, user: { read: true, write: false } }, key: 'publish-ro-robot-by-default', kind: 'switch', title: 'Publier le robot RO par défaut', value: 'default', initialValue: 'disabled' }], project: [{ permissions: { admin: { read: true, write: true }, user: { read: true, write: false } }, key: 'view-robot', kind: 'switch', title: 'Publier le robot', initialValue: 'disabled', value: 'default', description: 'Autoriser un robot de lecture sur le projet' }] } },
{ imgSrc: '/img/sonarqube.svg', title: 'SonarQube', name: 'sonarqube', urls: [], manifest: {} },
]

const urlsLength = services.reduce((length, service) => length + service.urls.length, 0)

describe('Service Configuration Component', () => {
it('Affiche correctement les services et leurs configurations', () => {
Expand All @@ -18,18 +25,14 @@ describe('Service Configuration Component', () => {
displayGlobal: true,
},
})
// Vérifie que les services sont correctement affichés
cy.getByDataTestid('service-argocd').should('exist')

// Vérifie que les boutons de lien sont présents et fonctionnent
cy.getByDataTestid('service-argocd').find('a').should('have.length', 5)
cy.getByDataTestid('service-argocd').find('button').first().click() // Simule un clic sur le premier lien
// Vérifie que les services sont correctement affichés
cy.getByDataTestid('services-urls').find('a').should('have.length', urlsLength)

// Verifies qu'il n'y ait que 2 bouton "lien" si 2 to
cy.getByDataTestid('service-gitlab').find('a').should('have.length', 2)
cy.getByDataTestid('service-config-registry').should('exist')

// Verifies qu'il n'y ait pas de boutons "lien"
cy.getByDataTestid('service-sonarqube').find('a').should('not.exist')
// Vérifie que les boutons de lien sont présents et fonctionnent
cy.getByDataTestid('service-config-registry').click() // Simule un clic sur le premier lien

// Vérifie que les boutons de rechargement sont présents
cy.getByDataTestid('reloadBtn').should('exist')
Expand All @@ -44,12 +47,11 @@ describe('Service Configuration Component', () => {
},
})
// Simule un clic sur le bouton d'extension
cy.getByDataTestid('service-registry').within(() => {
cy.getByDataTestid('additional-config').should('not.be.visible')
cy.getByDataTestid('dropdown-button').click()
cy.getByDataTestid('additional-config').should('be.visible')
cy.getByDataTestid('dropdown-button').click()
cy.getByDataTestid('additional-config').should('not.be.visible')
})
cy.getByDataTestid('service-config-registry')
.click()
cy.getByDataTestid('service-project-config-registry')
.should('exist')
cy.getByDataTestid('service-project-config-registry')
.should('exist')
})
})
13 changes: 8 additions & 5 deletions apps/client/cypress/components/specs/team-ct.ct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import '@gouvfr/dsfr/dist/dsfr.min.css'
import '@gouvfr/dsfr/dist/utility/icons/icons.min.css'
import '@gouvfr/dsfr/dist/utility/utility.main.min.css'
import '@/main.css'
import { createRandomDbSetup, getRandomUser } from '@cpn-console/test-utils'
import type { ProjectV2 } from '@cpn-console/shared'
import { faker } from '@faker-js/faker'
import TeamCt from '@/components/TeamCt.vue'
import { useProjectStore } from '@/stores/project.js'
import { useUsersStore } from '@/stores/users.js'
import { useUserStore } from '@/stores/user.js'

const ownerId = faker.string.uuid()
const props: {
Expand Down Expand Up @@ -87,10 +87,11 @@ describe('TeamCt.vue', () => {
})
it('Should mount a TeamCt for user', () => {
useProjectStore()
const { project } = createRandomDbSetup({ nbUsers: 4 })
const newUser = getRandomUser()
const userStore = useUserStore()
// devrait tester que l'on peut toujours quitter un projet
userStore.userProfile = { id: props.project.members[0].id }

cy.intercept('GET', `api/v1/projects/${project.id}/users/match?letters=*`, { body: [newUser] })
// cy.intercept('GET', `api/v1/projects/${project.id}/users/match?letters=*`, { body: [newUser] })

cy.mount(TeamCt, { props: { ...props, canTransfer: false, canManage: false } })

Expand All @@ -101,7 +102,9 @@ describe('TeamCt.vue', () => {
cy.get('tbody > tr')
.should('have.length', props.project.members.length + 1) // +1 cause owner is not a member
cy.get('thead > tr > th')
.should('have.length', 3)
.should('have.length', 4)
// devrait tester que l'on peut toujours quitter un projet
// cy.get('.fr-fi-close-line').should('have.length', 1)
})
cy.getByDataTestid('showTransferProjectBtn')
.should('not.exist')
Expand Down
27 changes: 18 additions & 9 deletions apps/client/cypress/e2e/specs/01-logs.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getModel } from '../support/func.js'
const projects = getModel('project')
const betaapp = projects.find(({ name }) => name === 'betaapp') as ProjectV2

describe('Create Project', () => {
describe('Project Logs', () => {
beforeEach(() => {
})

Expand All @@ -26,6 +26,7 @@ describe('Create Project', () => {
})
cy.getByDataTestid('replayHooksBtn')
.click()
cy.wait('@listLogs')
cy.getByDataTestid('displayLogsPanel')
.should('be.visible')
.within(() => {
Expand All @@ -35,7 +36,7 @@ describe('Create Project', () => {
cy.getByDataTestid('menuMyProjects').click()
.url().should('contain', '/projects')
cy.getByDataTestid('displayLogsPanel')
.should('not.be.visible')
.should('not.exist')
})

it('Should handle display project logs as manager or memebr of project', () => {
Expand All @@ -45,6 +46,7 @@ describe('Create Project', () => {
// as owner
cy.goToProjects()
cy.getByDataTestid(`projectTile-${betaapp.name}`).click()
cy.wait('@listLogs')
cy.getByDataTestid('displayLogsPanel')
.should('not.be.visible')
cy.getByDataTestid('displayLogsBtn')
Expand All @@ -63,17 +65,24 @@ describe('Create Project', () => {
})

// as member
cy.getByDataTestid('menuMyProjects').click()
.url().should('contain', '/projects')

cy.goToProjects()
cy.getByDataTestid(`projectTile-candilib`).click()
cy.wait('@listLogs')
cy.getByDataTestid('displayLogsPanel')
.should('not.exist')
.should('not.be.visible')
cy.getByDataTestid('displayLogsBtn')
.should('not.exist')
.should('be.visible')
.click()
cy.getByDataTestid('displayLogsPanel')
.should('be.visible')
.within(() => {
cy.get('span').should('contain', '0 - 0 sur 0')
})
cy.getByDataTestid('menuRepos').click()
cy.getByDataTestid('displayLogsBtn')
.should('not.exist')
cy.getByDataTestid('displayLogsPanel')
.should('be.visible')
.within(() => {
cy.get('span').should('contain', '0 - 0 sur 0')
})
})
})
1 change: 1 addition & 0 deletions apps/client/cypress/e2e/specs/admin/organizations.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ describe('Administration organizations', () => {

cy.visit('/projects/create-project')
cy.wait('@getAllOrganizations').its('response').then((response) => {
cy.log(organizations)
cy.get('select#organizationId-select')
.select((response.body.find(org => org.name === newOrg.name)).id)
.should('have.value', (response.body.find(org => org.label === newOrg.label)).id)
Expand Down
33 changes: 14 additions & 19 deletions apps/client/cypress/e2e/specs/admin/projects.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { Organization, Project, ProjectV2 } from '@cpn-console/shared'
import { formatDate, sortArrByObjKeyAsc, statusDict } from '@cpn-console/shared'
import { getModel, getModelById } from '../../support/func.js'
import { truncateDescription } from '@/utils/func.js'

function checkTableRowsLength(length: number) {
if (!length) cy.get('tr:last-child>td:first-child').should('have.text', 'Aucun projet trouvé')
Expand Down Expand Up @@ -40,15 +39,11 @@ describe('Administration projects', () => {
cy.get(`tbody tr:nth-of-type(${index + 1})`).within(() => {
cy.getSettled('td:nth-of-type(1)').should('contain', project.organization)
cy.getSettled('td:nth-of-type(2)').should('contain', project.name)
cy.getByDataTestid('description').invoke('text').then((text) => {
cy.log(text)
expect(text).to.equal(truncateDescription(text).innerHTML)
})
cy.getSettled('td:nth-of-type(4)').should('contain', project.owner.email)
cy.getSettled('td:nth-of-type(5) svg title').should('contain', `Le projet ${project.name} est ${statusDict.status[project.status].wording}`)
cy.getSettled('td:nth-of-type(6) svg title').should('contain', `Le projet ${project.name} est ${statusDict.locked[String(!!project.locked)].wording}`)
cy.getSettled('td:nth-of-type(7)').should('contain', formatDate(project.createdAt))
cy.getSettled('td:nth-of-type(8)').should('contain', formatDate(project.updatedAt))
cy.getSettled('td:nth-of-type(3)').should('contain', project.owner.email)
cy.getSettled('td:nth-of-type(4) svg title').should('contain', `Le projet ${project.name} est ${statusDict.status[project.status].wording}`)
cy.getSettled('td:nth-of-type(5) svg title').should('contain', `Le projet ${project.name} est ${statusDict.locked[String(!!project.locked)].wording}`)
cy.getSettled('td:nth-of-type(6)').should('contain', formatDate(project.createdAt))
cy.getSettled('td:nth-of-type(7)').should('contain', formatDate(project.updatedAt))
})
})
})
Expand Down Expand Up @@ -321,12 +316,12 @@ describe('Administration projects', () => {
})
cy.get('.fr-callout__title')
.should('contain', project.name)
cy.get(`td[title="retirer ${member.email} du projet"]`)
cy.get(`td[title="Retirer ${member.email} du projet"]`)
.click()
cy.wait('@removeUser')
.its('response.statusCode')
.should('match', /^20\d$/)
cy.get(`td[title="retirer ${member.email} du projet"]`)
cy.get(`td[title="Retirer ${member.email} du projet"]`)
.should('not.exist')
cy.getByDataTestid('addUserSuggestionInput')
.find('input')
Expand All @@ -337,7 +332,7 @@ describe('Administration projects', () => {
cy.wait('@addUser')
.its('response.statusCode')
.should('match', /^20\d$/)
cy.get(`td[title="retirer ${member.email} du projet"]`)
cy.get(`td[title="Retirer ${member.email} du projet"]`)
.should('exist')
})

Expand Down Expand Up @@ -418,12 +413,12 @@ describe('Administration projects', () => {
cy.get('.fr-callout__title')
.should('contain', project.name)
cy.get('#servicesTable').should('exist')
cy.getByDataTestid('service-argocd').within(() => {
cy.get('a:first')
.should('have.attr', 'href', 'https://theuselessweb.com/')
cy.get('img:first')
.should('have.attr', 'src', '/img/argocd.svg')
})
cy.getByDataTestid('service-config-argocd')
.click()
.within(() => {
cy.get('input')
.should('have.length', 1)
})
})

it('Should download projects informations, loggedIn as admin', () => {
Expand Down
2 changes: 2 additions & 0 deletions apps/client/cypress/e2e/specs/create-project.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ describe('Create Project', () => {
cy.getByDataTestid('createProjectBtn').should('be.enabled').click()

cy.wait('@postProject').its('response.statusCode').should('match', /^20\d$/)
cy.url().should('match', /projects\/.*\/dashboard/)

cy.wait('@listProjects').its('response.statusCode').should('match', /^20\d$/)

cy.assertCreateProjects([project.name])
Expand Down
4 changes: 2 additions & 2 deletions apps/client/cypress/e2e/specs/environments.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ describe('Manage project environments', () => {
cy.get('#zone-select')
.select(publicZone?.id)
cy.get('#cluster-select')
.should('not.exist')
cy.getByDataTestid('noClusterOptionAlert')
.should('exist')
cy.getByDataTestid('noClusterOptionAlert')
.should('not.exist')

cy.get('#stage-select')
.select(devStage?.id)
Expand Down
5 changes: 0 additions & 5 deletions apps/client/cypress/e2e/specs/redirection.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const organization = getModelById('organization', project.organizationId)

describe('Redirection', () => {
it('Should redirect to original page on reload', () => {
cy.intercept('GET', '/api/v1/stages').as('listStages')
cy.intercept('GET', '/api/v1/projects?filter=member&statusNotIn=archived').as('listProjects')
cy.intercept('POST', '/realms/cloud-pi-native/protocol/openid-connect/token').as('postToken')

Expand All @@ -22,20 +21,17 @@ describe('Redirection', () => {
cy.should('have.length', `${response?.body.length}`)
cy.getByDataTestid(`projectTile-${project.name}`).click()
cy.url().should('contain', `/projects/${project.id}/dashboard`)
cy.wait('@listStages')
})
cy.reload()
cy.wait('@postToken')
cy.url().should('contain', `/projects/${project.id}/dashboard`)
cy.wait('@listStages')
cy.wait('@listProjects').its('response').then((_response) => {
cy.getByDataTestid('currentProjectInfo')
cy.should('contain', `Le projet courant est : ${project.name} (${organization.label})`)
})
})

it('Should redirect to login page if not logged in', () => {
cy.intercept('GET', '/api/v1/stages').as('listStages')
cy.intercept('GET', '/api/v1/projects?filter=member&statusNotIn=archived').as('listProjects')
cy.intercept('POST', '/realms/cloud-pi-native/protocol/openid-connect/token').as('postToken')
cy.intercept('GET', '/realms/cloud-pi-native/account').as('getAccount')
Expand All @@ -47,7 +43,6 @@ describe('Redirection', () => {
cy.get('input#kc-login').click()
cy.wait('@postToken')
cy.url().should('contain', `/projects/${project.id}/dashboard`)
cy.wait('@listStages')
cy.wait('@listProjects', { timeout: 5_000 }).its('response').then((_response) => {
cy.getByDataTestid('currentProjectInfo')
cy.should('contain', `Le projet courant est : ${project.name} (${organization.label})`)
Expand Down
4 changes: 2 additions & 2 deletions apps/client/cypress/e2e/specs/roles.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('Project roles', () => {

cy.getByDataTestid('menuTeam').should('be.visible').click()
cy.url().should('contain', `/projects/${project.id}/team`)
cy.getByDataTestid('teamTable').get('th').contains('Retirer du projet').should('not.exist')
cy.getByDataTestid('teamTable').get('th').contains('Retirer du projet').should('be.visible')
cy.getByDataTestid('addUserSuggestionInput').should('not.exist')
cy.getByDataTestid('showTransferProjectBtn').should('not.exist')

Expand Down Expand Up @@ -118,7 +118,7 @@ describe('Project roles', () => {

cy.getByDataTestid('menuTeam').should('be.visible').click()
cy.url().should('contain', `/projects/${project.id}/team`)
cy.getByDataTestid('teamTable').get('th').contains('Retirer du projet').should('not.exist')
cy.getByDataTestid('teamTable').get('th').contains('Retirer du projet').should('be.visible')
cy.getByDataTestid('addUserSuggestionInput').should('not.exist')
cy.getByDataTestid('showTransferProjectBtn').should('not.exist')

Expand Down
Loading

0 comments on commit 752afee

Please sign in to comment.