Skip to content

Commit

Permalink
Merge branch 'master' into 28337-binary-field-information-of-assets-n…
Browse files Browse the repository at this point in the history
…eeds-be-refreshed-after-any-change
  • Loading branch information
zJaaal authored Aug 13, 2024
2 parents 55755ef + 6616302 commit ab20661
Show file tree
Hide file tree
Showing 36 changed files with 677 additions and 258 deletions.
2 changes: 1 addition & 1 deletion .github/actions/cleanup-runner/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ runs:
- name: Cleanup Docker
shell: bash
run: |
if [[ "$RUNNER_OS" == "Linux" ]] || [[ "$RUNNER_OS" == "macOS" ]]; then
if [[ "$RUNNER_OS" == "Linux" ]]; then
echo 'Cleanup Docker'
docker system prune -f
docker volume prune -f
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/cli-build-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ jobs:
id: set-os
run: |
if [[ "${{ inputs.buildNativeImage }}" == "true" ]]; then
RUNNERS='[{ "os": "ubuntu-22.04", "label": "Linux" }, { "os": "macos-13", "label": "macOS-Intel" }, { "os": "macos-14", "label": "macOS-Silicon" }]'
RUNNERS='[{ "os": "ubuntu-22.04", "label": "Linux", "platform": "linux-x86_64" }, { "os": "macos-13", "label": "macOS-Intel", "platform": "osx-x86_64" }, { "os": "macos-14", "label": "macOS-Silicon", "platform": "osx-aarch_64" }]'
else
RUNNERS='[{ "os": "ubuntu-22.04", "label": "Linux" }]'
RUNNERS='[{ "os": "ubuntu-22.04", "label": "Linux", "platform": "linux-x86_64" }]'
fi
echo "runners=$RUNNERS" >> $GITHUB_OUTPUT
Expand All @@ -68,6 +68,7 @@ jobs:
ref: ${{ env.BRANCH }}
- uses: ./.github/actions/maven-job
with:
cleanup-runner: true
stage-name: "Build Native Image ${{ matrix.label }}"
maven-args: "package -Pnative -Pdist -DskipTests=$SKIP_TESTS -pl :dotcms-cli"
native: true
Expand All @@ -80,7 +81,7 @@ jobs:
id: upload-artifact
uses: actions/upload-artifact@v4
with:
name: cli-artifacts-${{ matrix.os }}
name: cli-artifacts-${{ matrix.platform }}
path: |
${{ github.workspace }}/tools/dotcms-cli/cli/target/distributions/*.zip
retention-days: 2
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/cli-release-process.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ jobs:
JRELEASER_ARTIFACTORY_PASSWORD: ${{ secrets.EE_REPO_PASSWORD }}
JRELEASER_DRY_RUN: ${{ github.event.inputs.dry-run || 'false' }}
with:
cleanup-runner: true
github-token: ${{ secrets.GITHUB_TOKEN }}
stage-name: "JReleaser"
maven-args: "-Prelease validate -DartifactsDir=artifacts -Dm2Dir=$HOME/.m2/repository -Djreleaser.git.root.search=true -pl :dotcms-cli-parent -Dmaven.plugin.validation=VERBOSE"
Expand Down
58 changes: 39 additions & 19 deletions .github/workflows/publish-starter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ on:
required: true
type: choice
options:
- 'Full Starter'
- 'full'
- 'empty'
changelog:
description: 'Changes description'
required: true
type: string
type: string
dry-run:
description: 'Enable dry-run mode'
required: true
Expand All @@ -23,47 +24,66 @@ defaults:

env:
STARTER_TYPE: ${{ github.event.inputs.type }}
EMPTY_STARTER_URL: ${{ vars.DOT_EMPTY_STARTER_URL }}
EMPTY_STARTER_TOKEN: ${{ secrets.DOT_EMPTY_STARTER_ACCESS_TOKEN }}
FULL_STARTER_URL: ${{ vars.DOT_STARTER_URL }}
FULL_STARTER_TOKEN: ${{ secrets.DOT_STARTER_ACCESS_TOKEN }}
DOWNLOAD_ENDPOINT: api/v1/maintenance/_downloadStarterWithAssets?oldAssets=true

jobs:
get-full-starter:
get-starter:
runs-on: macos-13
if: github.repository == 'dotcms/core'
environment: trunk
steps:
- name: Context
- name: 'Github context'
run: |
echo "Generating a Full Starter..."
echo "::group::Github context"
echo "${{ toJSON(github.event.inputs) }}"
echo "::endgroup::"
- name: 'Get zip file'
id: get-zip-file
env:
URL: ${{ vars.DOT_STARTER_URL }}
ACCESS_TOKEN: ${{ secrets.DOT_STARTER_ACCESS_TOKEN }}
run: |
echo "::group::Getting zip file"
echo "::notice::Starter type: $STARTER_TYPE"
function download_starter {
URL=$1/${{ env.DOWNLOAD_ENDPOINT }}
ACCESS_TOKEN=$2
OUTPUT_FILENAME=$3
curl -s -w "%{http_code}" --output ${OUTPUT_FILENAME} $URL \
-H "Content-Type: application/json" \
-H "Accept: application/octet-stream" \
-H "Authorization: Bearer $ACCESS_TOKEN"
}
mkdir -p starter && cd starter
RESP=$(curl -s -w "%{http_code}" --output $(date +'%Y%m%d').zip $URL \
-H "Content-Type: application/json" \
-H "Accept: application/octet-stream" \
-H "Authorization: Bearer $ACCESS_TOKEN")
if [[ "$RESP" != "200" ]]; then
echo "RESP: $RESP"
if [[ "$STARTER_TYPE" == "empty" ]]; then
echo "::debug::Empty Starter: downloading from [${{ env.EMPTY_STARTER_URL }}/${{ env.DOWNLOAD_ENDPOINT }}]"
RESPONSE=$(download_starter ${{ env.EMPTY_STARTER_URL }} ${{ env.EMPTY_STARTER_TOKEN }} empty_$(date +'%Y%m%d').zip)
else
echo "::debut::Full Starter: downloading from [${{ env.FULL_STARTER_URL }}/${{ env.DOWNLOAD_ENDPOINT }}]"
RESPONSE=$(download_starter ${{ env.FULL_STARTER_URL }} ${{ env.FULL_STARTER_TOKEN }} $(date +'%Y%m%d').zip)
fi
echo "::notice::Status Code: $RESPONSE"
if [[ "$RESPONSE" != "200" ]]; then
echo "::error::Failed with status code: $RESPONSE"
exit 1
fi
ls -ltrh
echo "::endgroup::"
# echo "::endgroup::"
- name: 'Upload artifacts'
id: upload-artifacts
uses: actions/upload-artifact@v4
with:
name: starter
name: ${{ env.STARTER_TYPE }}-starter
path: |
${{ github.workspace }}/starter/*.zip
retention-days: 2
if-no-files-found: ignore
if-no-files-found: ignore

deploy-artifacts:
needs: [ get-full-starter ]
needs: [ get-starter ]
runs-on: ubuntu-20.04
environment: trunk
outputs:
Expand All @@ -86,7 +106,7 @@ jobs:
uses: actions/download-artifact@v4
with:
github-token: ${{ github.token }}
name: starter
name: ${{ env.STARTER_TYPE }}-starter
path: ${{ github.workspace }}/starter

- name: 'Listing artifacts'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ export class DotTemplateCreateEditComponent implements OnInit, OnDestroy {
* @memberof DotTemplateBuilderComponent
*/
onCustomEvent($event: CustomEvent): void {
this.store.goToEditTemplate($event.detail.data.id, $event.detail.data.inode);
const { data } = $event.detail;
this.store.goToEditTemplate(data.id, data.inode);
}

private createTemplate(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('ContainerComponent', () => {
{
provide: PageContextService,
useValue: {
pageContextValue: {
context: {
pageAsset: {
containers: PageResponseMock.containers
},
Expand Down Expand Up @@ -116,7 +116,7 @@ describe('ContainerComponent', () => {
{
provide: PageContextService,
useValue: {
pageContextValue: {
context: {
pageAsset: {
containers: PageResponseMock.containers
},
Expand All @@ -139,7 +139,7 @@ describe('ContainerComponent', () => {
{
provide: PageContextService,
useValue: {
pageContextValue: {
context: {
pageAsset: {
containers: PageResponseMock.containers
},
Expand Down Expand Up @@ -168,7 +168,7 @@ describe('ContainerComponent', () => {
{
provide: PageContextService,
useValue: {
pageContextValue: {
context: {
pageAsset: {
containers: PageResponseMock.containers
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,9 @@ export class ContainerComponent implements OnChanges {
@HostBinding('attr.data-testid') testId = 'dot-container';

ngOnChanges() {
const {
pageAsset: { containers },
components,
isInsideEditor
} = this.pageContextService.pageContextValue;
const { pageAsset, components, isInsideEditor } = this.pageContextService.context;
const { acceptTypes, maxContentlets, variantId, path, contentlets } = getContainersData(
containers,
pageAsset.containers,
this.container
);
const { identifier, uuid } = this.container;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,25 @@ import { ActivatedRoute, Router } from '@angular/router';

import * as dotcmsClient from '@dotcms/client';

import { PageResponseMock } from './../../utils/testing.utils';
import { PageResponseMock, PageResponseOneRowMock } from './../../utils/testing.utils';
import { DotcmsLayoutComponent } from './dotcms-layout.component';

import { DotCMSContentlet, DotCMSPageAsset } from '../../models';
import { PageContextService } from '../../services/dotcms-context/page-context.service';
import { RowComponent } from '../row/row.component';

interface Callback {
[key: string]: (data: unknown) => void;
}

interface DotCmsClientMock extends dotcmsClient.DotCmsClient {
editor: {
on: (type: string, callbackFn: (data: unknown) => void) => void;
off: jest.Mock;
callbacks: Callback;
};
}

@Component({
selector: 'dotcms-mock-component',
standalone: true,
Expand All @@ -33,9 +45,11 @@ jest.mock('@dotcms/client', () => ({
DotCmsClient: {
instance: {
editor: {
on: jest.fn(),
on: function (type: string, callbackFn: (data: unknown) => void): void {
this.callbacks[type] = callbackFn;
},
off: jest.fn(),
callbacks: {}
callbacks: {} as Callback
}
}
},
Expand All @@ -48,19 +62,15 @@ const { DotCmsClient } = dotcmsClient as jest.Mocked<typeof dotcmsClient>;

describe('DotcmsLayoutComponent', () => {
let spectator: Spectator<DotcmsLayoutComponent>;
let pageContextService: PageContextService;

const createComponent = createRoutingFactory({
component: DotcmsLayoutComponent,
imports: [MockComponent(RowComponent)],
providers: [
PageContextService,
{ provide: ActivatedRoute, useValue: { url: of([]) } },
{ provide: Router, useValue: {} },
{
provide: PageContextService,
useValue: {
setContext: jest.fn()
}
}
{ provide: Router, useValue: {} }
]
});

Expand All @@ -74,6 +84,8 @@ describe('DotcmsLayoutComponent', () => {
},
detectChanges: false
});

pageContextService = spectator.inject(PageContextService, true);
});

afterEach(() => {
Expand All @@ -86,9 +98,9 @@ describe('DotcmsLayoutComponent', () => {
});

it('should save pageContext', () => {
const setContextSpy = jest.spyOn(pageContextService, 'setContext');
spectator.detectChanges();
jest.spyOn(spectator.inject(PageContextService), 'setContext');
expect(spectator.inject(PageContextService).setContext).toHaveBeenCalled();
expect(setContextSpy).toHaveBeenCalled();
});

describe('inside editor', () => {
Expand All @@ -101,26 +113,20 @@ describe('DotcmsLayoutComponent', () => {
expect(updateNavigationSpy).toHaveBeenCalled();
});

it('should listen to SET_PAGE_DATA message', () => {
spectator.detectChanges();
window.dispatchEvent(
new MessageEvent('message', { data: { name: 'SET_PAGE_DATA', payload: {} } })
);
expect(spectator.inject(PageContextService).setContext).toHaveBeenCalled();
});

describe('onReload', () => {
const client = DotCmsClient.instance;
let editorOnSpy: jest.SpyInstance;

beforeEach(() => {
editorOnSpy = jest.spyOn(client.editor, 'on');
spectator.setInput('onReload', () => {
/* do nothing */
});
spectator.detectChanges();
});

it('should subscribe to the `CHANGE` event', () => {
expect(client.editor.on).toHaveBeenCalled();
expect(editorOnSpy).toHaveBeenCalled();
});

it('should remove listener on unmount', () => {
Expand Down Expand Up @@ -153,8 +159,37 @@ describe('DotcmsLayoutComponent', () => {
beforeEach(() => spectator.detectChanges());

it('should update the page asset when changes are made in the editor', () => {
expect(client.editor.on).toHaveBeenCalledWith('changes', expect.any(Function));
const editorOnSpy = jest.spyOn(client.editor, 'on');
expect(editorOnSpy).toHaveBeenCalledWith('changes', expect.any(Function));
});
});
});

describe('template', () => {
beforeEach(() => spectator.detectChanges());

it('should render rows', () => {
expect(spectator.queryAll(RowComponent).length).toBe(3);
});

it('should pass the correct row to RowComponent', () => {
const rowComponents = spectator.queryAll(RowComponent);
const rows = PageResponseMock.layout.body.rows;
expect(rowComponents.length).toBe(rows.length);

rowComponents.forEach((component, index) => {
expect(component.row).toEqual(rows[index]);
});
});

it('should update the page asset when changes are made in the editor', () => {
const { editor } = DotCmsClient.instance as DotCmsClientMock;
editor.callbacks['changes'](PageResponseOneRowMock);
spectator.detectChanges();
const rowComponents = spectator.queryAll(RowComponent);
const rows = PageResponseMock.layout.body.rows;
expect(rowComponents.length).toBe(1);
expect(rowComponents[0].row).toEqual(rows[0]);
});
});
});
Loading

0 comments on commit ab20661

Please sign in to comment.