From ebaf3c366019c383f1dfa50d7d409419b558c31c Mon Sep 17 00:00:00 2001 From: Andrew Wylde Date: Fri, 29 Nov 2024 13:49:43 -0600 Subject: [PATCH] feat(catalog): add support for displaying public labels --- cypress/e2e/specs/catalog.spec.ts | 103 +++++++++++++++++++++++++++- package.json | 2 +- src/components/CatalogItem.vue | 43 ++++++++++-- src/components/CatalogTableList.vue | 22 ++++++ src/constants/feature-flags.ts | 1 + src/locales/ca_ES.ts | 3 +- src/locales/de.ts | 3 +- src/locales/en.ts | 1 + src/locales/es_ES.ts | 3 +- src/locales/fr.ts | 3 +- src/locales/i18n-type.d.ts | 1 + src/stores/product.ts | 1 + src/views/ProductCatalogWrapper.vue | 13 +++- yarn.lock | 39 ++--------- 14 files changed, 192 insertions(+), 46 deletions(-) diff --git a/cypress/e2e/specs/catalog.spec.ts b/cypress/e2e/specs/catalog.spec.ts index bc01ac39..6db04930 100644 --- a/cypress/e2e/specs/catalog.spec.ts +++ b/cypress/e2e/specs/catalog.spec.ts @@ -1,5 +1,6 @@ import { ProductCatalogIndexSourceLatestVersion, SearchResults, SearchResultsDataInner } from '@kong/sdk-portal-js' import { generateProducts } from '../support/utils/generateProducts' +import { FeatureFlags } from '@/constants/feature-flags' const mockProductSearchQuery = (searchQuery: string) => { const searchResults: SearchResultsDataInner[] = ([ @@ -25,7 +26,8 @@ const mockProductSearchQuery = (searchQuery: string) => { latest_version: { name: versions[0], id: crypto.randomUUID() - } + }, + public_labels: {} } })) @@ -197,6 +199,105 @@ describe('Catalog', () => { cy.get('.k-table tbody td:nth-of-type(4) a').should('exist').should('contain', 'Documentation') }) }) + + describe('Catalog Item Public Labels (feature flag enabled)', () => { + beforeEach(() => { + cy.mockPublicPortal() + cy.mockLaunchDarklyFlags([ + { name: FeatureFlags.publicLabelsUI, value: true } + ]) + cy.visit('/') + // click view toggle to table mode + cy.get('[data-testid="view-switcher"]:not(:disabled)').click() + }) + + it('renders public labels correctly', () => { + const productWithLabels = { + id: 'test-product', + title: 'Test Product', + description: 'A test product with public labels', + public_labels: { + category: 'test', + version: '1.0' + }, + showSpecLink: true, + documentCount: 1, + latestVersion: { name: 'v1' } + } + + cy.mockProductsCatalog(1, [productWithLabels]) + + cy.visit('/') + + cy.get('.catalog-item').eq(0).within(() => { + // Check if the public labels section exists + cy.contains('Labels:').should('exist') + + // Check if all public labels are rendered + cy.get('.product-public-label').should('have.length', 2) + + // Check the content of each label + cy.get('.product-public-label').eq(0).should('contain', 'category: test') + cy.get('.product-public-label').eq(1).should('contain', 'version: 1.0') + }) + }) + + it('does not render public labels section when product has no labels', () => { + const productWithoutLabels = { + id: 'test-product-no-labels', + title: 'Test Product Without Labels', + description: 'A test product without public labels', + public_labels: {}, + showSpecLink: true, + documentCount: 1, + latestVersion: { name: 'v1' } + } + + cy.mockProductsCatalog(1, [productWithoutLabels]) + + cy.visit('/') + + cy.get('.catalog-item').eq(0).within(() => { + // Check that the public labels section does not exist + cy.contains('Labels:').should('not.exist') + cy.get('.product-public-label').should('not.exist') + }) + }) + }) + describe('Catalog Item Public Labels (feature flag disabled)', () => { + beforeEach(() => { + cy.mockPublicPortal() + cy.mockLaunchDarklyFlags([ + { name: FeatureFlags.publicLabelsUI, value: false } + ]) + cy.visit('/') + }) + + it('renders no labels ', () => { + const productWithLabels = { + id: 'test-product', + title: 'Test Product', + description: 'A test product with public labels', + public_labels: { + category: 'test', + version: '1.0' + }, + showSpecLink: true, + documentCount: 1, + latestVersion: { name: 'v1' } + } + + cy.mockProductsCatalog(1, [productWithLabels]) + + cy.visit('/') + + cy.get('.catalog-item').within(() => { + // Check if the public labels section exists + cy.contains('Labels:').should('not.exist') + cy.get('.product-public-label').should('not.exist') + }) + }) + }) }) describe('Catalog versions', () => { diff --git a/package.json b/package.json index 825b567d..011478c1 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "@kong/kong-auth-elements": "2.12.6", "@kong/kongponents": "8.127.0", "@kong/markdown": "1.7.8", - "@kong/sdk-portal-js": "2.15.4", + "@kong/sdk-portal-js": "2.16.0", "@unhead/vue": "1.11.6", "@xstate/vue": "2.0.0", "axios": "1.6.7", diff --git a/src/components/CatalogItem.vue b/src/components/CatalogItem.vue index c668b5a6..c89d485b 100644 --- a/src/components/CatalogItem.vue +++ b/src/components/CatalogItem.vue @@ -18,9 +18,7 @@