Skip to content

Commit

Permalink
feat(Templates): extend the tutorial table
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
  • Loading branch information
blizzz committed Jan 13, 2025
1 parent add3b2b commit 760f018
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 103 deletions.
8 changes: 4 additions & 4 deletions cypress/e2e/tables-archive.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ describe('Archive tables/views', () => {
it('can archive tables', () => {
cy.get('[data-cy="navigationTableItem"]').first().as('tutorialTable')

cy.get('@tutorialTable').should('contain.text', 'Tutorial')
cy.get('@tutorialTable').find('[aria-haspopup="menu"]').click({ force: true })
cy.get('@tutorialTable').should('contain.text', 'Welcome to Nextcloud Tables!')
cy.get('@tutorialTable').find('[aria-haspopup="menu"]').first().click({ force: true })

cy.intercept({ method: 'PUT', url: '**/apps/tables/api/2/tables/*'}).as('archiveTableReq')
cy.contains('Archive table').click({ force: true })
Expand All @@ -38,8 +38,8 @@ describe('Archive tables/views', () => {
it('can unarchive tables', () => {
cy.get('[data-cy="navigationTableItem"]').first().as('tutorialTable')

cy.get('@tutorialTable').should('contain.text', 'Tutorial')
cy.get('@tutorialTable').find('[aria-haspopup="menu"]').click({ force: true })
cy.get('@tutorialTable').should('contain.text', 'Welcome to Nextcloud Tables!')
cy.get('@tutorialTable').find('[aria-haspopup="menu"]').first().click({ force: true })

cy.intercept({ method: 'PUT', url: '**/apps/tables/api/2/tables/*' }).as('unarchiveTableReq')
cy.contains('Unarchive table').click({ force: true })
Expand Down
14 changes: 9 additions & 5 deletions cypress/e2e/tables-export-csv.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@ describe('Import csv', () => {
})

it('Export csv', () => {
cy.loadTable('Tutorial')
console.log('before table load')
cy.loadTutorialTable()
console.log('before click')
cy.clickOnTableThreeDotMenu('Export as CSV')
const hour = new Date().getHours().toString().length < 2 ? '0' + new Date().getHours() : new Date().getHours().toString()
const minutes = new Date().getMinutes().toString().length < 2 ? '0' + new Date().getMinutes() : new Date().getMinutes().toString()
const date = new Date().toISOString().slice(2, 10)
const fileName = date + '_' + hour + '-' + minutes + '_' + 'Tutorial.csv'
cy.log('filename: ' + fileName)
cy.readFile('cypress/downloads/' + fileName).should('contain', 'What,How to do,Ease of use,Done')
cy.readFile('cypress/downloads/' + fileName).should('contain', 'Open the tables app,Click on tables icon in the menu bar.,5,true')
cy.getTutorialTableName().then(tutorialName => {
const fileName = date + '_' + hour + '-' + minutes + '_' + tutorialName + '.csv'
cy.log('filename: ' + fileName)
cy.readFile('cypress/downloads/' + fileName).should('contain', 'What,How to do,Ease of use,Done')
cy.readFile('cypress/downloads/' + fileName).should('contain', 'Open the tables app,Reachable via the Tables icon in the apps list.,5,true')
})
})

})
19 changes: 9 additions & 10 deletions cypress/e2e/tables-favorite.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ describe('Favorite tables/views', () => {
it('can favorite tables', () => {
cy.get('[data-cy="navigationTableItem"]').first().as('tutorialTable')

cy.get('@tutorialTable').should('contain.text', 'Tutorial')
cy.get('@tutorialTable').find('[aria-haspopup="menu"]').click({ force: true })
cy.get('@tutorialTable').should('contain.text', 'Welcome to ')
cy.get('@tutorialTable').find('[aria-haspopup="menu"]').first().click({ force: true })

cy.intercept({ method: 'POST', url: '**/ocs/v2.php/apps/tables/api/2/favorites/*/*'}).as('favoriteTableReq')
cy.contains('Add to favorites').click({ force: true })
Expand All @@ -34,8 +34,8 @@ describe('Favorite tables/views', () => {
it('can remove favorite table', () => {
cy.get('[data-cy="navigationTableItem"]').first().as('tutorialTable')

cy.get('@tutorialTable').should('contain.text', 'Tutorial')
cy.get('@tutorialTable').find('[aria-haspopup="menu"]').click({ force: true })
cy.get('@tutorialTable').should('contain.text', 'Welcome to ')
cy.get('@tutorialTable').find('[aria-haspopup="menu"]').first().click({ force: true })

cy.intercept({ method: 'DELETE', url: '**/ocs/v2.php/apps/tables/api/2/favorites/*/*' }).as('unfavoriteTableReq')
cy.contains('Remove from favorites').click({ force: true })
Expand All @@ -45,12 +45,11 @@ describe('Favorite tables/views', () => {
})

it('can favorite views', () => {
cy.loadTable('Tutorial')
cy.createView('test')
cy.loadTutorialTable

cy.get('[data-cy="navigationViewItem"]').first().as('testView')

cy.get('@testView').parent().parent().parent().should('contain.text', 'Tutorial')
cy.get('@testView').parent().parent().parent().should('contain.text', 'Welcome to ')
cy.get('@testView').find('[aria-haspopup="menu"]').click({ force: true })

cy.intercept({ method: 'POST', url: '**/ocs/v2.php/apps/tables/api/2/favorites/*/*' }).as('favoriteViewReq')
Expand All @@ -70,20 +69,20 @@ describe('Favorite tables/views', () => {
cy.contains('Remove from favorites').click({ force: true })
cy.wait('@unfavoriteViewReq').its('response.statusCode').should('equal', 200)

cy.get('@testView').parent().parent().parent().should('contain.text', 'Tutorial')
cy.get('@testView').parent().parent().parent().should('contain.text', 'Welcome to ')
})

it('can (un)favorite views with favorited parent tables', () => {
cy.get('[data-cy="navigationViewItem"]').first().as('testView')
cy.get('[data-cy="navigationTableItem"]').first().as('tutorialTable')

cy.get('@testView').parent().parent().parent().should('contain.text', 'Tutorial')
cy.get('@testView').parent().parent().parent().should('contain.text', 'Welcome to ')
cy.get('@testView').find('[aria-haspopup="menu"]').click({ force: true })
cy.contains('Add to favorites').click({ force: true })

cy.get('@testView').parent().should('contain.text', 'Favorites')

cy.get('@tutorialTable').should('contain.text', 'Tutorial')
cy.get('@tutorialTable').should('contain.text', 'Welcome to ')
cy.get('@tutorialTable').find('[aria-haspopup="menu"]').first().click({ force: true })
cy.contains('Add to favorites').click({ force: true })

Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/tables-fe-filters.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('FE sorting and filtering', () => {
})

it('FE Search in table', () => {
cy.get('.app-navigation-entry-link').contains('Tutorial').click({ force: true })
cy.get('.app-navigation-entry-link').contains('Welcome to Nextcloud Tables!').click({ force: true })

// test case-sensitive
cy.contains('Edit a row').should('exist')
Expand Down
6 changes: 3 additions & 3 deletions cypress/e2e/tables-import.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Import csv', () => {
})

it('Import csv from Files', () => {
cy.loadTable('Tutorial')
cy.loadTable('Welcome to Nextcloud Tables!')
cy.clickOnTableThreeDotMenu('Import')
cy.get('.modal__content button').contains('Select from Files').click()
cy.get('.file-picker__files').contains('test-import').click()
Expand All @@ -42,7 +42,7 @@ describe('Import csv', () => {
})

it('Import csv from device', () => {
cy.loadTable('Tutorial')
cy.loadTable('Welcome to Nextcloud Tables!')
cy.clickOnTableThreeDotMenu('Import')
cy.get('.modal__content button').contains('Upload from device').click()
cy.get('input[type="file"]').selectFile('cypress/fixtures/test-import.csv', { force: true })
Expand Down Expand Up @@ -102,7 +102,7 @@ describe('Import csv from Files file action', () => {
cy.get('[data-cy-files-list-row-action="import-to-tables"]').click()

cy.get('[data-cy="importAsNewTableSwitch"]').click()
cy.get('[data-cy="selectExistingTableDropdown"]').type('tutorial')
cy.get('[data-cy="selectExistingTableDropdown"]').type('Welcome to Nextcloud Tables!')
cy.get('.name-parts').click()

cy.intercept({
Expand Down
6 changes: 3 additions & 3 deletions cypress/e2e/tables-rows.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('Rows for a table', () => {
})

it('Create', () => {
cy.get('.app-navigation-entry-link').contains('Tutorial').click({ force: true })
cy.get('.app-navigation-entry-link').contains('Welcome to Nextcloud Tables!').click({ force: true })
cy.get('.NcTable').contains('Create row').click({ force: true })
cy.get('.modal__content .slot input').first().type('My first task')
cy.get('.modal__content .ProseMirror').first().click()
Expand All @@ -32,7 +32,7 @@ describe('Rows for a table', () => {
})

it('Edit', () => {
cy.get('.app-navigation-entry-link').contains('Tutorial').click({ force: true })
cy.get('.app-navigation-entry-link').contains('Welcome to Nextcloud Tables!').click({ force: true })
cy.get('.custom-table table').contains('My first task').parent().parent().find('[aria-label="Edit row"]').click()
cy.get('.modal__content .slot input').first().clear().type('Changed column value')
cy.get('.modal__content [aria-label="Increase stars"]').click().click()
Expand All @@ -43,7 +43,7 @@ describe('Rows for a table', () => {
})

it('Delete', () => {
cy.get('.app-navigation-entry-link').contains('Tutorial').click({ force: true })
cy.get('.app-navigation-entry-link').contains('Welcome to Nextcloud Tables!').click({ force: true })
cy.get('.custom-table table').contains('Changed column value').parent().parent().find('[aria-label="Edit row"]').click()
cy.get('.modal-container button').contains('Delete').click()
cy.get('.modal-container button').contains('I really want to delete this row!').click()
Expand Down
11 changes: 11 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@ Cypress.Commands.add('loadTable', (name) => {
cy.get('[data-cy="navigationTableItem"] a[title="' + name + '"]').click({ force: true })
})

// The name depends on the instance name, Nextcloud might be overwritten
Cypress.Commands.add('loadTutorialTable', () => {
cy.get('[data-cy="navigationTableItem"] a[title^="Welcome to"]').click({ force: true })
})

Cypress.Commands.add('getTutorialTableName', () => {
return cy.get('[data-cy="navigationTableItem"] a[title^="Welcome to"]').invoke('attr', 'title').then((title) => {
return cy.wrap(title)
})
})

Cypress.Commands.add('loadView', (name) => {
cy.get('[data-cy="navigationViewItem"] a[title="' + name + '"]').click({ force: true })
})
Expand Down
69 changes: 19 additions & 50 deletions lib/Service/TableService.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\DB\Exception as OcpDbException;
use OCP\Defaults;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IL10N;
use Psr\Log\LoggerInterface;
Expand All @@ -33,59 +34,26 @@
* @psalm-import-type TablesTable from ResponseDefinitions
*/
class TableService extends SuperService {
private TableMapper $mapper;

private TableTemplateService $tableTemplateService;

private ColumnService $columnService;

private RowService $rowService;

private ViewService $viewService;

private ShareService $shareService;

protected UserHelper $userHelper;

protected FavoritesService $favoritesService;

protected IAppManager $appManager;

protected IL10N $l;
private ContextService $contextService;

protected IEventDispatcher $eventDispatcher;

public function __construct(
PermissionsService $permissionsService,
LoggerInterface $logger,
?string $userId,
TableMapper $mapper,
TableTemplateService $tableTemplateService,
ColumnService $columnService,
RowService $rowService,
ViewService $viewService,
ShareService $shareService,
UserHelper $userHelper,
FavoritesService $favoritesService,
IEventDispatcher $eventDispatcher,
ContextService $contextService,
IAppManager $appManager,
IL10N $l,
PermissionsService $permissionsService,
LoggerInterface $logger,
?string $userId,
private TableMapper $mapper,
private TableTemplateService $tableTemplateService,
private ColumnService $columnService,
private RowService $rowService,
private ViewService $viewService,
private ShareService $shareService,
protected UserHelper $userHelper,
protected FavoritesService $favoritesService,
protected IEventDispatcher $eventDispatcher,
private ContextService $contextService,
protected IAppManager $appManager,
protected IL10N $l,
protected Defaults $themingDefaults,
) {
parent::__construct($logger, $userId, $permissionsService);
$this->appManager = $appManager;
$this->mapper = $mapper;
$this->tableTemplateService = $tableTemplateService;
$this->columnService = $columnService;
$this->rowService = $rowService;
$this->viewService = $viewService;
$this->shareService = $shareService;
$this->userHelper = $userHelper;
$this->favoritesService = $favoritesService;
$this->l = $l;
$this->eventDispatcher = $eventDispatcher;
$this->contextService = $contextService;
}

/**
Expand Down Expand Up @@ -119,7 +87,8 @@ public function findAll(?string $userId = null, bool $skipTableEnhancement = fal
// if there are no own tables found, create the tutorial table
if (count($allTables) === 0 && $createTutorial) {
try {
$tutorialTable = $this->create($this->l->t('Tutorial'), 'tutorial', '🚀');
$productName = $this->themingDefaults->getName();
$tutorialTable = $this->create($this->l->t('Welcome to %s Tables!', [$productName]), 'tutorial', '🚀');
$allTables[$tutorialTable->getId()] = $tutorialTable;
} catch (InternalError|PermissionError|DoesNotExistException|MultipleObjectsReturnedException|OcpDbException $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
Expand Down
Loading

0 comments on commit 760f018

Please sign in to comment.